From 8b8e4af0f316a10d092937587b874ff34526be1a Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 4 Nov 2019 20:28:50 -0800 Subject: [PATCH] security_data -> session --- src/login/character.rs | 27 ++++++++-------- src/login/login.rs | 73 +++++++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/src/login/character.rs b/src/login/character.rs index d0347eb..ad5ddcf 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -135,7 +135,7 @@ struct ClientState { user: Option, characters: Option<[Option; 4]>, guildcard_data_buffer: Option>, - security_data: [u8; 40], + session: Session, } impl ClientState { @@ -145,7 +145,7 @@ impl ClientState { user: None, characters: None, guildcard_data_buffer: None, - security_data: [0; 40], + session: Session::new(), } } } @@ -197,15 +197,15 @@ impl CharacterServerState { let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?; Ok(match get_login_status(&self.entity_gateway, pkt) { Ok(user) => { - let mut response = LoginResponse::by_status(AccountStatus::Ok, [0; 40]); + let mut response = LoginResponse::by_status(AccountStatus::Ok, Session::new()); response.guildcard = user.guildcard.map_or(0, |gc| gc) as u32; response.team_id = user.team_id.map_or(0, |ti| ti) as u32; client.user = Some(user); - client.security_data = pkt.security_data; + client.session = pkt.session; vec![SendCharacterPacket::LoginResponse(response)] }, Err(err) => { - vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(err, [0; 40]))] + vec![SendCharacterPacket::LoginResponse(LoginResponse::by_status(err, Session::new()))] } }) } @@ -264,12 +264,11 @@ impl CharacterServerState { } else { let user = client.user.as_ref().unwrap(); - client.security_data[0..4].clone_from_slice(&[1,3,3,7]); - client.security_data[4] = select.slot as u8; - client.security_data[5] = 1; + client.session.action = SessionAction::SelectCharacter; + client.session.character_slot = select.slot as u8; Ok(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_char_select(user.guildcard.unwrap_or(0), user.team_id.unwrap_or(1), - client.security_data)), + client.session)), SendCharacterPacket::CharAck(CharAck { slot: select.slot, code: 1, @@ -348,7 +347,7 @@ impl ServerState for CharacterServerState { -> Result>, CharacterError> { Ok(match pkt { RecvCharacterPacket::Login(login) => { - if login.security_data[0..4] == [1,3,3,7] { + if login.session.action == SessionAction::SelectCharacter { Box::new(self.send_ship_list(id, login)?.into_iter().map(move |pkt| (id, pkt))) } else { @@ -398,6 +397,7 @@ impl ServerState for CharacterServerState { } )].into_iter().map(move |pkt| (id, pkt))) }, + // TODO: move USERFLAGS over to SessionAction RecvCharacterPacket::CharacterPreview(preview) => { let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?; let mut user = client.user.as_mut().unwrap(); @@ -417,14 +417,13 @@ impl ServerState for CharacterServerState { // TODO: dressing room stuff } - client.security_data[0..4].clone_from_slice(&[1,3,3,7]); - client.security_data[4] = preview.slot as u8; - client.security_data[5] = 1; + client.session.action = SessionAction::SelectCharacter; + client.session.character_slot = preview.slot as u8; user.flags = 0; self.entity_gateway.set_user(&user); Box::new(vec![SendCharacterPacket::LoginResponse(LoginResponse::by_char_select(user.guildcard.unwrap_or(0), user.team_id.unwrap_or(1), - client.security_data)), + client.session)), SendCharacterPacket::CharAck(CharAck { slot: preview.slot, code: 0 diff --git a/src/login/login.rs b/src/login/login.rs index b8d50f1..b47afc8 100644 --- a/src/login/login.rs +++ b/src/login/login.rs @@ -82,14 +82,14 @@ impl LoginServerState { fn validate_login(&mut self, pkt: &Login) -> Vec { match get_login_status(&self.entity_gateway, pkt) { Ok(_user) => { - let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.security_data)); + let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.session)); let ip = net::Ipv4Addr::new(127,0,0,1); let ip = u32::from_ne_bytes(ip.octets()); vec![response, SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::login::character::CHARACTER_PORT))] }, Err(err) => { - vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.security_data))] + vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.session))] } } } @@ -134,23 +134,28 @@ mod test { use super::*; const LOGIN_PACKET: RecvLoginPacket = RecvLoginPacket::Login(Login { - flag: 0, - tag: 65536, - guildcard: 0, - version: 65, - unknown1: [0, 0, 0, 255, 0, 14], - team: 0, - username: [116, 101, 115, 116, 117, 115, 101, 114, 0, 0, 0, 0, 0, 0, 0, 0], // utf8_to_array!("testuser", 16), - unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - password: [109, 121, 112, 97, 115, 115, 119, 111, 114, 100, 0, 0, 0, 0, 0, 0], // utf8_to_array!("mypassword", 16), - unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0], - hwinfo: [129, 1, 1, 1, 1, 1, 1, 1], - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - }); + tag: 65536, + guildcard: 0, + version: 65, + unknown1: [0, 0, 0, 255, 0, 14], + team: 0, + username: [116, 101, 115, 116, 117, 115, 101, 114, 0, 0, 0, 0, 0, 0, 0, 0], // utf8_to_array!("testuser", 16), + unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + password: [109, 121, 112, 97, 115, 115, 119, 111, 114, 100, 0, 0, 0, 0, 0, 0], // utf8_to_array!("mypassword", 16), + unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0], + hwinfo: [129, 1, 1, 1, 1, 1, 1, 1], + session: Session { + version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session_id: 0, + interserver_checksum: 0, + action: SessionAction::None, + character_slot: 0, + } + }); #[test] fn test_correct_login() { @@ -183,8 +188,14 @@ mod test { tag: 65536, guildcard: 0, team_id: 0, - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session: Session { + version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session_id: 0, + interserver_checksum: 0, + action: SessionAction::None, + character_slot: 0, + }, caps: 258 })), (ClientId(1), SendLoginPacket::RedirectClient(RedirectClient { @@ -214,8 +225,14 @@ mod test { tag: 65536, guildcard: 0, team_id: 0, - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session: Session { + version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session_id: 0, + interserver_checksum: 0, + action: SessionAction::None, + character_slot: 0, + }, caps: 258 }))]) } @@ -251,8 +268,14 @@ mod test { tag: 65536, guildcard: 0, team_id: 0, - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session: Session { + version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + session_id: 0, + interserver_checksum: 0, + action: SessionAction::None, + character_slot: 0, + }, caps: 258 }))]) }