|
|
@ -469,13 +469,17 @@ where |
|
|
|
cur.expect(GetServerInfoResponse::HEADER)?; |
|
|
|
cur.expect(GetServerInfoResponse::HEADER)?; |
|
|
|
|
|
|
|
|
|
|
|
if !cur.as_slice().starts_with(b"\\") { |
|
|
|
if !cur.as_slice().starts_with(b"\\") { |
|
|
|
let s = cur.get_str(cur.remaining())?; |
|
|
|
let s = cur.get_bytes(cur.remaining())?; |
|
|
|
let p = s.rfind(':').ok_or(Error::InvalidPacket)?; |
|
|
|
let p = s |
|
|
|
let msg = &s[p + 1..]; |
|
|
|
.iter() |
|
|
|
match msg.trim() { |
|
|
|
.rev() |
|
|
|
"wrong version" => return Err(Error::InvalidProtocolVersion), |
|
|
|
.position(|c| *c == b':') |
|
|
|
_ => return Err(Error::InvalidPacket), |
|
|
|
.ok_or(Error::InvalidPacket)?; |
|
|
|
} |
|
|
|
let msg = &s[s.len() - p..]; |
|
|
|
|
|
|
|
return match msg { |
|
|
|
|
|
|
|
b" wrong version\n" => Err(Error::InvalidProtocolVersion), |
|
|
|
|
|
|
|
_ => Err(Error::InvalidPacket), |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let mut ret = Self::default(); |
|
|
|
let mut ret = Self::default(); |
|
|
@ -645,6 +649,15 @@ mod tests { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn get_server_info_response_wrong_version() { |
|
|
|
|
|
|
|
let s = b"\xff\xff\xff\xffinfo\nfoobar: wrong version\n"; |
|
|
|
|
|
|
|
assert_eq!(Packet::decode(s), Err(Error::InvalidProtocolVersion)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let s = b"\xff\xff\xff\xffinfo\nfoobar\xff: wrong version\n"; |
|
|
|
|
|
|
|
assert_eq!(Packet::decode(s), Err(Error::InvalidProtocolVersion)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn server_add_bots_is_a_number() { |
|
|
|
fn server_add_bots_is_a_number() { |
|
|
|
let s = b"0\n\\protocol\\48\\challenge\\4161802725\\players\\0\\max\\32\\bots\\3\\gamedir\\valve\\map\\rats_bathroom\\type\\d\\password\\0\\os\\l\\secure\\0\\lan\\0\\version\\0.19.4\\region\\255\\product\\valve\\nat\\0"; |
|
|
|
let s = b"0\n\\protocol\\48\\challenge\\4161802725\\players\\0\\max\\32\\bots\\3\\gamedir\\valve\\map\\rats_bathroom\\type\\d\\password\\0\\os\\l\\secure\\0\\lan\\0\\version\\0.19.4\\region\\255\\product\\valve\\nat\\0"; |
|
|
|