[Protocol] Add quake protocols. (#35)

* [Protocol] Initial packet receive implementation

* [Protocol] Add key extraction

* [Protocol] Fix new Ipv4Addr query address and get string with unended

* [Protocol] Properly parse the received data

* [Protocol] Add parse players

* [Protocol] Add bots

* [Protocol] Extract into functions

* [Protocol] Remove quotes from player name

* [Protocol] Add two and three files

* [Protocol] Make quake queries very modular

* [Protocol] Remove the need of a client instance

* [Protocol] Revesed if statement

* [Protocol] Apply clippy fixes and replace String by &str in get send header

* [Protocol] Add one and three implementations

* [Protocol] Add quake2 and quake3 to master_querant

* [Protocol] Fix Q2 implementation

* [Protocol] Change from Ipv4Addr to IpAddr

* [Protocol] Fix Q3 response header

* [Protocol] Fix Q3 response

* [Crate] Add Q1, 2 and 3 to changelog and protocols

* [Protocol] Extract client into separate file and add some docs
This commit is contained in:
CosminPerRam 2023-05-30 15:33:41 +03:00 committed by GitHub
parent 3dbc6498ed
commit d302d1173f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 339 additions and 8 deletions

View file

@ -93,13 +93,13 @@ impl Bufferer {
Ok(value)
}
pub fn get_string_utf8(&mut self) -> GDResult<String> {
fn get_string_utf8_until(&mut self, until: u8) -> GDResult<String> {
let sub_buf = self.remaining_data();
if sub_buf.is_empty() {
return Err(PacketUnderflow);
}
let first_null_position = sub_buf.iter().position(|&x| x == 0).ok_or(PacketBad)?;
let first_null_position = sub_buf.iter().position(|&x| x == until).ok_or(PacketBad)?;
let value = std::str::from_utf8(&sub_buf[.. first_null_position])
.map_err(|_| PacketBad)?
.to_string();
@ -108,6 +108,14 @@ impl Bufferer {
Ok(value)
}
pub fn get_string_utf8(&mut self) -> GDResult<String> {
self.get_string_utf8_until(0)
}
pub fn get_string_utf8_newline(&mut self) -> GDResult<String> {
self.get_string_utf8_until(10)
}
pub fn get_string_utf8_optional(&mut self) -> GDResult<String> {
match self.get_string_utf8() {
Ok(data) => Ok(data),
@ -168,6 +176,8 @@ impl Bufferer {
pub fn remaining_length(&self) -> usize { self.data_length() - self.position }
pub fn is_remaining_empty(&self) -> bool { self.remaining_length() == 0 }
pub fn as_endianess(&self, endianess: Endianess) -> Self {
Bufferer {
data: self.data.clone(),