Emote broadcasting
This commit is contained in:
+40
@@ -180,6 +180,19 @@ async fn main() -> session_rs::Result<()> {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
session
|
||||||
|
.on_request::<methods::Emote, _>({
|
||||||
|
let sessions = Arc::clone(&sessions);
|
||||||
|
|
||||||
|
move |_, emote| {
|
||||||
|
let sessions = Arc::clone(&sessions);
|
||||||
|
let uuid = Arc::clone(&uuid);
|
||||||
|
|
||||||
|
send_emote(sessions, uuid, emote)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
Ok::<(), session_rs::Error>(())
|
Ok::<(), session_rs::Error>(())
|
||||||
}) as Pin<Box<dyn Future<Output = _> + Send>>
|
}) as Pin<Box<dyn Future<Output = _> + Send>>
|
||||||
}
|
}
|
||||||
@@ -187,6 +200,31 @@ async fn main() -> session_rs::Result<()> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn send_emote(
|
||||||
|
sessions: SessionMap,
|
||||||
|
uuid: Arc<Mutex<String>>,
|
||||||
|
emote: methods::ClientEmote,
|
||||||
|
) -> Result<String, String> {
|
||||||
|
let emote_event = methods::EventEmote {
|
||||||
|
from: uuid.lock().await.clone(),
|
||||||
|
emote: emote.emote,
|
||||||
|
};
|
||||||
|
|
||||||
|
for i in emote.targets {
|
||||||
|
if let Some(sessions) = sessions.lock().await.get_mut(&i) {
|
||||||
|
let emote_event = emote_event.clone();
|
||||||
|
sessions.retain(|s| {
|
||||||
|
let notify_result = tokio::runtime::Handle::current()
|
||||||
|
.block_on(s.notify::<methods::EmoteEvent>(emote_event.clone()));
|
||||||
|
|
||||||
|
notify_result.is_ok()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(format!("Cool"))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
struct MinecraftAuthResponse {
|
struct MinecraftAuthResponse {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@@ -234,5 +272,7 @@ async fn authenticate(
|
|||||||
.or_default()
|
.or_default()
|
||||||
.insert(session);
|
.insert(session);
|
||||||
|
|
||||||
|
println!("Authenticated as {:?}", auth);
|
||||||
|
|
||||||
user::get_put(&auth.id, &pool).await
|
user::get_put(&auth.id, &pool).await
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-2
@@ -53,12 +53,24 @@ impl Method for BuyHat {
|
|||||||
type Error = String;
|
type Error = String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct ClientEmote {
|
||||||
|
pub emote: String,
|
||||||
|
pub targets: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct EventEmote {
|
||||||
|
pub emote: String,
|
||||||
|
pub from: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Emote;
|
pub struct Emote;
|
||||||
|
|
||||||
impl Method for Emote {
|
impl Method for Emote {
|
||||||
const NAME: &'static str = "emote";
|
const NAME: &'static str = "emote";
|
||||||
type Request = String;
|
type Request = ClientEmote;
|
||||||
type Response = String;
|
type Response = String;
|
||||||
type Error = String;
|
type Error = String;
|
||||||
}
|
}
|
||||||
@@ -68,7 +80,7 @@ pub struct EmoteEvent;
|
|||||||
|
|
||||||
impl Method for EmoteEvent {
|
impl Method for EmoteEvent {
|
||||||
const NAME: &'static str = "emote_event";
|
const NAME: &'static str = "emote_event";
|
||||||
type Request = String;
|
type Request = EventEmote;
|
||||||
type Response = String;
|
type Response = String;
|
||||||
type Error = String;
|
type Error = String;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user