From f2de86d05f6458f905521a221c7470b86207f285 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 20 Mar 2023 12:39:35 +0200 Subject: [PATCH] feat: add id to CfgUser and AfterAuth --- client/src/cfg/mod.rs | 3 +++ client/src/plugins/menu/ui/play/ui.rs | 22 +++++++++---------- .../networking/systems/events/receive/mod.rs | 1 + server/src/main.rs | 4 ++-- server/src/systems/event/mod.rs | 7 +++--- shared/src/server/messages/auth.rs | 4 +++- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/client/src/cfg/mod.rs b/client/src/cfg/mod.rs index a9569c6..5188708 100644 --- a/client/src/cfg/mod.rs +++ b/client/src/cfg/mod.rs @@ -47,6 +47,8 @@ impl Default for CfgSettings { pub struct CfgUser { /// User logged in status pub logged_in: bool, + /// User ID + pub id: String, /// Username pub username: String, /// User Session Cookie @@ -57,6 +59,7 @@ impl Default for CfgUser { fn default() -> Self { CfgUser { logged_in: false, + id: "".to_string(), username: "".to_string(), cookie: "".to_string(), } diff --git a/client/src/plugins/menu/ui/play/ui.rs b/client/src/plugins/menu/ui/play/ui.rs index ed0a418..f974f06 100644 --- a/client/src/plugins/menu/ui/play/ui.rs +++ b/client/src/plugins/menu/ui/play/ui.rs @@ -167,28 +167,28 @@ fn browse_forming(ui: &mut egui::Ui, data: &mut PlayScreenData, cfg_user: &CfgUs .inner_margin(4.) .show(ui, |ui| { ui.horizontal(|ui| { - ui.label(format!("Host: {}", game.host.username)); + //ui.label(format!("Host: {}", game.host.username)); + ui.label("Host: host-username-here"); ui.with_layout( egui::Layout::right_to_left(egui::Align::Center), |ui| { - if game.guest_id == cfg_user.id { + if game.guest_id.unwrap_or_default().to_string() == cfg_user.id + { ui.add_enabled(false, egui::Button::new("Joined")); if ui.button("Inspect").clicked() { - rtdmenu.cur_game = Some(game.clone()); - rtdmenu.play_menu_ui_state = - PlayMenuUIState::InLobbyGuest; + data.cur_game = Some(game.clone()); + data.state = PlayScreenState::InLobbyGuest; } - } else if game.host_id == cfg_user.id { + } else if game.host_id.to_string() == cfg_user.id { ui.add_enabled(false, egui::Button::new("Host")); if ui.button("Inspect").clicked() { - rtdmenu.cur_game = Some(game.clone()); - rtdmenu.play_menu_ui_state = - PlayMenuUIState::InLobbyHost; + data.cur_game = Some(game.clone()); + data.state = PlayScreenState::InLobbyHost; } } else { if ui.button("Join").clicked() { - rtdmenu.cur_game = Some(game.clone()); - joingame_ev_w.send(JoinGameEvent); + //data.cur_game = Some(game.clone()); + //joingame_ev_w.send(JoinGameEvent); } } }, diff --git a/client/src/plugins/networking/systems/events/receive/mod.rs b/client/src/plugins/networking/systems/events/receive/mod.rs index d5f2710..e8f88a7 100644 --- a/client/src/plugins/networking/systems/events/receive/mod.rs +++ b/client/src/plugins/networking/systems/events/receive/mod.rs @@ -66,6 +66,7 @@ pub fn message_events( // TODO: move handling to a separate function? // save details from AfterAuth + cfg_user.id = aa_message.id; cfg_user.username = aa_message.username; cfg_user.cookie = aa_message.cookie; diff --git a/server/src/main.rs b/server/src/main.rs index 9834d62..32f5ce2 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -15,7 +15,7 @@ use bevy_log::{info, LogPlugin}; use naia_bevy_server::{Plugin as ServerPlugin, ReceiveEvents, ServerConfig, UserKey}; -use laurelin_shared::server::protocol::protocol; +use laurelin_shared::{server::protocol::protocol, types::user::UserPub}; mod systems; @@ -27,7 +27,7 @@ pub struct Config { /// Temporary runtime data #[derive(Resource)] pub struct RuntimeTemp { - pub afterauth_details: HashMap, + pub afterauth_details: HashMap, } #[derive(Resource)] diff --git a/server/src/systems/event/mod.rs b/server/src/systems/event/mod.rs index e36baa4..1aff9a6 100644 --- a/server/src/systems/event/mod.rs +++ b/server/src/systems/event/mod.rs @@ -50,7 +50,7 @@ pub(crate) fn auth_events( ResponseRegister::Ok(user) => { server.accept_connection(&user_key); temp.afterauth_details - .insert(user_key, (user.username, wrapped.cookie)); + .insert(user_key, (user, wrapped.cookie)); } } } @@ -62,7 +62,7 @@ pub(crate) fn auth_events( ResponseLogin::Ok(user) => { server.accept_connection(&user_key); temp.afterauth_details - .insert(user_key, (user.username, wrapped.cookie)); + .insert(user_key, (user, wrapped.cookie)); } } } @@ -86,7 +86,8 @@ pub(crate) fn connect_events( server.send_message::( &user_key, &AfterAuth { - username: aa_details.0.clone(), + id: aa_details.0.id.to_string().clone(), + username: aa_details.0.username.clone(), cookie: aa_details.1.clone(), }, ); diff --git a/shared/src/server/messages/auth.rs b/shared/src/server/messages/auth.rs index 9dc5e5d..66c43c4 100644 --- a/shared/src/server/messages/auth.rs +++ b/shared/src/server/messages/auth.rs @@ -30,13 +30,15 @@ impl Auth { pub struct AfterAuth { pub cookie: String, pub username: String, + pub id: String, } impl AfterAuth { - pub fn new(cookie: &str, username: &str) -> Self { + pub fn new(cookie: &str, username: &str, id: &str) -> Self { Self { cookie: cookie.to_string(), username: username.to_string(), + id: id.to_string(), } } } -- 2.44.1