Browse Source

adding checksum test (#3)

pbs
andy 5 years ago
committed by Gogs
parent
commit
efb773276b
  1. 31
      src/login/character.rs

31
src/login/character.rs

@ -31,7 +31,8 @@ pub enum CharacterError {
pub enum RecvCharacterPacket { pub enum RecvCharacterPacket {
Login(Login), Login(Login),
RequestSettings(RequestSettings), RequestSettings(RequestSettings),
CharSelect(CharSelect)
CharSelect(CharSelect),
Checksum(Checksum),
} }
impl RecvServerPacket for RecvCharacterPacket { impl RecvServerPacket for RecvCharacterPacket {
@ -40,6 +41,7 @@ impl RecvServerPacket for RecvCharacterPacket {
0x93 => Ok(RecvCharacterPacket::Login(Login::from_bytes(data)?)), 0x93 => Ok(RecvCharacterPacket::Login(Login::from_bytes(data)?)),
0xE0 => Ok(RecvCharacterPacket::RequestSettings(RequestSettings::from_bytes(data)?)), 0xE0 => Ok(RecvCharacterPacket::RequestSettings(RequestSettings::from_bytes(data)?)),
0xE3 => Ok(RecvCharacterPacket::CharSelect(CharSelect::from_bytes(data)?)), 0xE3 => Ok(RecvCharacterPacket::CharSelect(CharSelect::from_bytes(data)?)),
0x1E8 => Ok(RecvCharacterPacket::Checksum(Checksum::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType) _ => Err(PacketParseError::WrongPacketForServerType)
} }
} }
@ -52,6 +54,7 @@ pub enum SendCharacterPacket {
LoginWelcome(LoginWelcome), LoginWelcome(LoginWelcome),
SendKeyAndTeamSettings(SendKeyAndTeamSettings), SendKeyAndTeamSettings(SendKeyAndTeamSettings),
CharAck(CharAck), CharAck(CharAck),
ChecksumAck(ChecksumAck),
} }
impl SendServerPacket for SendCharacterPacket { impl SendServerPacket for SendCharacterPacket {
@ -61,6 +64,7 @@ impl SendServerPacket for SendCharacterPacket {
SendCharacterPacket::LoginWelcome(pkt) => pkt.as_bytes(), SendCharacterPacket::LoginWelcome(pkt) => pkt.as_bytes(),
SendCharacterPacket::SendKeyAndTeamSettings(pkt) => pkt.as_bytes(), SendCharacterPacket::SendKeyAndTeamSettings(pkt) => pkt.as_bytes(),
SendCharacterPacket::CharAck(pkt) => pkt.as_bytes(), SendCharacterPacket::CharAck(pkt) => pkt.as_bytes(),
SendCharacterPacket::ChecksumAck(pkt) => pkt.as_bytes(),
//SendLoginPacket::RedirectClient(pkt) => pkt.as_bytes(), //SendLoginPacket::RedirectClient(pkt) => pkt.as_bytes(),
} }
} }
@ -115,6 +119,13 @@ impl<DA: DataAccess> CharacterServerState<DA> {
code: 2, code: 2,
})] })]
} }
fn validate_checksum(&mut self) -> Vec<SendCharacterPacket> {
vec![SendCharacterPacket::ChecksumAck(ChecksumAck {
flag: 0,
ack: 1,
})]
}
} }
impl<DA: DataAccess> ServerState for CharacterServerState<DA> { impl<DA: DataAccess> ServerState for CharacterServerState<DA> {
@ -147,6 +158,9 @@ impl<DA: DataAccess> ServerState for CharacterServerState<DA> {
RecvCharacterPacket::CharSelect(sel) => { RecvCharacterPacket::CharSelect(sel) => {
Box::new(self.char_select(sel).into_iter()) 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[2] == 0xE2);
assert!(bytes.len() == 0xAFC); 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::<Vec<_>>();
assert!(send.len() == 1);
let bytes = send[0].as_bytes();
assert!(bytes == [0xC, 0, 0xE8, 0x02, 0,0,0,0, 1,0,0,0]);
}
}
Loading…
Cancel
Save