From fe03515871a967db3d1ee260a736cb9e41048460 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 25 Nov 2020 22:05:55 -0700 Subject: [PATCH] basic multiple login check --- src/login/character.rs | 22 ++++++++++++++++------ src/ship/packet/builder/lobby.rs | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/login/character.rs b/src/login/character.rs index 895ce7e..7516514 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -323,10 +323,13 @@ impl CharacterServerState { Ok(user) => { if let Some(connected_client) = self.connected_clients.get(&user.id) { if let Some(expires) = connected_client.expires { - if expires < chrono::Utc::now() { + if expires > chrono::Utc::now() { return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::new()))]); } } + else { + return Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(AccountStatus::AlreadyOnline, Session::new()))]); + } } let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new()); @@ -337,7 +340,7 @@ impl CharacterServerState { self.connected_clients.insert(user.id.clone(), ConnectedClient { ship_id: None, - expires: Some(chrono::Utc::now() + chrono::Duration::minutes(1)), + expires: None, //Some(chrono::Utc::now() + chrono::Duration::minutes(1)), }); client.user = Some(user); @@ -509,11 +512,19 @@ impl CharacterServerState { ]) } - fn select_ship(&mut self, menuselect: &MenuSelect) -> Result, anyhow::Error> { + fn select_ship(&mut self, id: ClientId, menuselect: &MenuSelect) -> Result, anyhow::Error> { if menuselect.menu != SHIP_MENU_ID { Err(CharacterError::InvalidMenuSelection(menuselect.menu, menuselect.item))?; } + if let Some(client) = self.clients.get(&id) { + if let Some(user) = &client.user { + if let Some(cc) = self.connected_clients.get_mut(&user.id) { + cc.ship_id = Some(ServerId(menuselect.item as usize)); + } + } + } + let ship = self.ships.get(&ServerId(menuselect.item as usize)) .ok_or(CharacterError::InvalidMenuSelection(menuselect.menu, menuselect.item))?; Ok(vec![SendCharacterPacket::RedirectClient(RedirectClient::new(u32::from_le_bytes(ship.ip.octets()), ship.port))]) @@ -604,9 +615,8 @@ impl ServerState for CharacterServerState { async fn on_disconnect(&mut self, id: ClientId) -> Result, anyhow::Error> { if let Some(client) = self.clients.remove(&id) { - if let Some(mut user) = client.user { - user.at_character= false; - self.entity_gateway.save_user(&user).await; + if let Some(user) = client.user { + self.connected_clients.remove(&user.id); } } Ok(Vec::new()) diff --git a/src/ship/packet/builder/lobby.rs b/src/ship/packet/builder/lobby.rs index 5e7d33b..b0a0d8e 100644 --- a/src/ship/packet/builder/lobby.rs +++ b/src/ship/packet/builder/lobby.rs @@ -13,7 +13,7 @@ pub fn join_lobby(id: ClientId, clients: &Clients, item_manager: &ItemManager, level_table: &CharacterLevelTable) - -> Result { + -> Result { let lobby_clients = client_location.get_clients_in_lobby(lobby).map_err(|err| -> ClientLocationError { err.into() })?; let playerinfo = lobby_clients.iter() .map(|area_client| {