@@ 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},
@@ 113,6 116,31 @@ pub(crate) fn message_events(
&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::<DataRequestChannel, DataRequestResponse>(
+ &user_key,
+ &DataRequestResponse::new(request.r#type, Some(vec![user_details]), None),
+ );
+
+ // update cookie
+ global
+ .user_to_session_map
+ .insert(user_key, wrapped.cookie.clone());
+ server.send_message::<CookieRefreshChannel, CookieRefresh>(
+ &user_key,
+ &CookieRefresh::new(&wrapped.cookie),
+ );
+ }
}
}
}
@@ 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<String>,
}
impl DataRequest {
- pub fn new(r#type: u8) -> Self {
- Self { r#type }
+ pub fn new(r#type: u8, data: Option<String>) -> 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,