DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

f2de86d05f6458f905521a221c7470b86207f285 — Jonni Liljamo 1 year, 9 months ago 6f1526b
feat: add id to CfgUser and AfterAuth
M client/src/cfg/mod.rs => client/src/cfg/mod.rs +3 -0
@@ 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(),
        }

M client/src/plugins/menu/ui/play/ui.rs => client/src/plugins/menu/ui/play/ui.rs +11 -11
@@ 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);
                                        }
                                    }
                                },

M client/src/plugins/networking/systems/events/receive/mod.rs => client/src/plugins/networking/systems/events/receive/mod.rs +1 -0
@@ 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;


M server/src/main.rs => server/src/main.rs +2 -2
@@ 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<UserKey, (String, String)>,
    pub afterauth_details: HashMap<UserKey, (UserPub, String)>,
}

#[derive(Resource)]

M server/src/systems/event/mod.rs => server/src/systems/event/mod.rs +4 -3
@@ 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::<AfterAuthChannel, AfterAuth>(
            &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(),
            },
        );

M shared/src/server/messages/auth.rs => shared/src/server/messages/auth.rs +3 -1
@@ 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(),
        }
    }
}