mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[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:
parent
3dbc6498ed
commit
d302d1173f
11 changed files with 339 additions and 8 deletions
77
src/protocols/quake/one.rs
Normal file
77
src/protocols/quake/one.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
use std::net::IpAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::client::{QuakeClient, client_query};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Quake 1 player data.
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Player {
|
||||
/// Player's server id.
|
||||
pub id: u8,
|
||||
pub score: u8,
|
||||
pub time: u8,
|
||||
pub ping: u8,
|
||||
pub name: String,
|
||||
pub skin: String,
|
||||
pub color_primary: u8,
|
||||
pub color_secondary: u8
|
||||
}
|
||||
|
||||
pub(crate) struct QuakeOne;
|
||||
impl QuakeClient for QuakeOne {
|
||||
type Player = Player;
|
||||
|
||||
fn get_send_header<'a>() -> &'a str {
|
||||
"status"
|
||||
}
|
||||
|
||||
fn get_response_header<'a>() -> &'a [u8] {
|
||||
&[0x6E]
|
||||
}
|
||||
|
||||
fn parse_player_string(mut data: Iter<&str>) -> GDResult<Self::Player> {
|
||||
Ok(Player {
|
||||
id: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
},
|
||||
score: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
},
|
||||
time: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
},
|
||||
ping: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
},
|
||||
name: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.to_string()
|
||||
},
|
||||
skin: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.to_string()
|
||||
},
|
||||
color_primary: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
},
|
||||
color_secondary: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeOne>(address, port, timeout_settings)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue