diff --git a/src/login/character.rs b/src/login/character.rs index abcaef3..64caa0c 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -31,7 +31,8 @@ pub enum CharacterError { pub enum RecvCharacterPacket { Login(Login), RequestSettings(RequestSettings), - CharSelect(CharSelect) + CharSelect(CharSelect), + Checksum(Checksum), } impl RecvServerPacket for RecvCharacterPacket { @@ -40,6 +41,7 @@ impl RecvServerPacket for RecvCharacterPacket { 0x93 => Ok(RecvCharacterPacket::Login(Login::from_bytes(data)?)), 0xE0 => Ok(RecvCharacterPacket::RequestSettings(RequestSettings::from_bytes(data)?)), 0xE3 => Ok(RecvCharacterPacket::CharSelect(CharSelect::from_bytes(data)?)), + 0x1E8 => Ok(RecvCharacterPacket::Checksum(Checksum::from_bytes(data)?)), _ => Err(PacketParseError::WrongPacketForServerType) } } @@ -52,6 +54,7 @@ pub enum SendCharacterPacket { LoginWelcome(LoginWelcome), SendKeyAndTeamSettings(SendKeyAndTeamSettings), CharAck(CharAck), + ChecksumAck(ChecksumAck), } impl SendServerPacket for SendCharacterPacket { @@ -61,6 +64,7 @@ impl SendServerPacket for SendCharacterPacket { SendCharacterPacket::LoginWelcome(pkt) => pkt.as_bytes(), SendCharacterPacket::SendKeyAndTeamSettings(pkt) => pkt.as_bytes(), SendCharacterPacket::CharAck(pkt) => pkt.as_bytes(), + SendCharacterPacket::ChecksumAck(pkt) => pkt.as_bytes(), //SendLoginPacket::RedirectClient(pkt) => pkt.as_bytes(), } } @@ -115,6 +119,13 @@ impl CharacterServerState { code: 2, })] } + + fn validate_checksum(&mut self) -> Vec { + vec![SendCharacterPacket::ChecksumAck(ChecksumAck { + flag: 0, + ack: 1, + })] + } } impl ServerState for CharacterServerState { @@ -147,6 +158,9 @@ impl ServerState for CharacterServerState { RecvCharacterPacket::CharSelect(sel) => { Box::new(self.char_select(sel).into_iter()) } + RecvCharacterPacket::Checksum(checksum) => { + Box::new(self.validate_checksum().into_iter()) + } } } } @@ -200,4 +214,17 @@ mod test { assert!(bytes[2] == 0xE2); assert!(bytes.len() == 0xAFC); } -} + + #[test] + fn test_user_checksum() { + struct TestData {} + impl DataAccess for TestData{} + let shared = SharedLoginState::new(TestData {}); + let mut server = CharacterServerState::new(shared); + let send = server.handle(&RecvCharacterPacket::Checksum(Checksum {flag: 0})).collect::>(); + assert!(send.len() == 1); + + let bytes = send[0].as_bytes(); + assert!(bytes == [0xC, 0, 0xE8, 0x02, 0,0,0,0, 1,0,0,0]); + } +} \ No newline at end of file