This commit is contained in:
2026-02-23 16:30:02 +01:00
parent ffb88c86c3
commit e250895386
2 changed files with 34 additions and 0 deletions
+24
View File
@@ -180,6 +180,7 @@ async fn main() -> session_rs::Result<()> {
session session
.on_request::<methods::Emote, _>({ .on_request::<methods::Emote, _>({
let sessions = Arc::clone(&sessions); let sessions = Arc::clone(&sessions);
let uuid = Arc::clone(&uuid);
move |_, emote| { move |_, emote| {
let sessions = Arc::clone(&sessions); let sessions = Arc::clone(&sessions);
@@ -190,6 +191,17 @@ async fn main() -> session_rs::Result<()> {
}) })
.await; .await;
session
.on_request::<methods::Player, _>({
let sessions = Arc::clone(&sessions);
let pool = Arc::clone(&pool);
move |_, uuid: String| {
get_user(sessions.clone(), uuid.clone(), pool.clone())
}
})
.await;
Ok::<(), session_rs::Error>(()) Ok::<(), session_rs::Error>(())
}) as Pin<Box<dyn Future<Output = _> + Send>> }) as Pin<Box<dyn Future<Output = _> + Send>>
} }
@@ -197,6 +209,18 @@ async fn main() -> session_rs::Result<()> {
.await .await
} }
async fn get_user(
sessions: SessionMap,
uuid: String,
pool: Arc<SqlitePool>,
) -> Result<Option<User>, String> {
if !sessions.lock().await.contains_key(&uuid) {
return Ok(None);
}
Ok(Some(user::get(&uuid, pool.as_ref()).await?))
}
async fn send_emote( async fn send_emote(
sessions: SessionMap, sessions: SessionMap,
uuid: UUID, uuid: UUID,
+10
View File
@@ -75,3 +75,13 @@ impl Method for EmoteEvent {
type Response = String; type Response = String;
type Error = String; type Error = String;
} }
#[derive(Debug, Serialize, Deserialize)]
pub struct Player;
impl Method for Player {
const NAME: &'static str = "player";
type Request = String;
type Response = Option<User>;
type Error = String;
}