From 379efefbdbbaf116cbc9eac6f4c56b8eed44928a Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 23 Mar 2023 13:07:13 +0200 Subject: [PATCH] feat(server, shared): PubUserDetails datarequest --- server/src/systems/event/message/mod.rs | 32 +++++++++++++++++++++-- shared/src/server/messages/datarequest.rs | 11 ++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/server/src/systems/event/message/mod.rs b/server/src/systems/event/message/mod.rs index 51a9a6d..7963146 100644 --- a/server/src/systems/event/message/mod.rs +++ b/server/src/systems/event/message/mod.rs @@ -13,8 +13,11 @@ use bevy_ecs::{ system::{Res, ResMut}, }; use laurelin_shared::{ - api::game::{ - all_forming, create, my_games, ResponseAllForming, ResponseCreateGame, ResponseMyGames, + api::{ + game::{ + all_forming, create, my_games, ResponseAllForming, ResponseCreateGame, ResponseMyGames, + }, + user::{self, ResponseInfo}, }, server::{ channels::{CookieRefreshChannel, DataRequestChannel}, @@ -104,6 +107,31 @@ pub(crate) fn message_events( &DataRequestResponse::new(request.r#type, None, Some(games_pub)), ); + // update cookie + global + .user_to_session_map + .insert(user_key, wrapped.cookie.clone()); + server.send_message::( + &user_key, + &CookieRefresh::new(&wrapped.cookie), + ); + } + DataRequestType::PubUserDetails => { + // TODO: handle + let cookie = global.user_to_session_map.get(&user_key).unwrap(); + let wrapped = + user::info(&config.api_address, &request.data.unwrap_or("".to_string())); + let user_details = match wrapped.response { + ResponseInfo::Error(_err) => { + panic!("I can't be bothered to handle this right now.") + } + ResponseInfo::Ok(result) => result, + }; + server.send_message::( + &user_key, + &DataRequestResponse::new(request.r#type, Some(vec![user_details]), None), + ); + // update cookie global .user_to_session_map diff --git a/shared/src/server/messages/datarequest.rs b/shared/src/server/messages/datarequest.rs index 388ca8b..79ef83c 100644 --- a/shared/src/server/messages/datarequest.rs +++ b/shared/src/server/messages/datarequest.rs @@ -13,11 +13,16 @@ use crate::types::{game::GamePub, user::UserPub}; #[derive(Message)] pub struct DataRequest { pub r#type: u8, + /// Optional data to give with a request, + /// should be a maximum of 508 bytes. + /// + /// Mostly used for handing in an ID for something. + pub data: Option, } impl DataRequest { - pub fn new(r#type: u8) -> Self { - Self { r#type } + pub fn new(r#type: u8, data: Option) -> Self { + Self { r#type, data } } } @@ -43,6 +48,7 @@ pub enum DataRequestType { GameAllForming = 100, GameMyGames = 101, GameCreate = 102, + PubUserDetails = 150, } impl DataRequestType { @@ -52,6 +58,7 @@ impl DataRequestType { 100 => Self::GameAllForming, 101 => Self::GameMyGames, 102 => Self::GameCreate, + 150 => Self::PubUserDetails, _ => { // NOTE/TODO/FIXME: bad, veeeery bad. // just... I'm not sure how to handle this best, -- 2.44.1