mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
[Protocol] Fix Quake 1 implementation.
This commit is contained in:
parent
f79f2ea2de
commit
c874b463e3
4 changed files with 21 additions and 32 deletions
|
|
@ -67,12 +67,12 @@ fn get_server_values(bufferer: &mut Bufferer) -> GDResult<HashMap<String, String
|
|||
fn get_players<Client: QuakeClient>(bufferer: &mut Bufferer) -> GDResult<Vec<Client::Player>> {
|
||||
let mut players: Vec<Client::Player> = Vec::new();
|
||||
|
||||
while !bufferer.is_remaining_empty() {
|
||||
while !bufferer.is_remaining_empty() && bufferer.remaining_data() != &[0x00] {
|
||||
let data = bufferer.get_string_utf8_newline()?;
|
||||
let data_split = data.split(' ').collect::<Vec<&str>>();
|
||||
let data_iter = data_split.iter();
|
||||
|
||||
players.push(Client::parse_player_string(data_iter)?)
|
||||
players.push(Client::parse_player_string(data_iter)?);
|
||||
}
|
||||
|
||||
Ok(players)
|
||||
|
|
@ -89,6 +89,7 @@ pub(crate) fn client_query<Client: QuakeClient>(address: &IpAddr, port: u16, tim
|
|||
.or(server_vars.remove("sv_hostname"))
|
||||
.ok_or(GDError::PacketBad)?,
|
||||
map: server_vars.remove("mapname")
|
||||
.or(server_vars.remove("map"))
|
||||
.ok_or(GDError::PacketBad)?,
|
||||
players_online: players.len() as u8,
|
||||
players_maximum: server_vars.remove("maxclients")
|
||||
|
|
@ -96,20 +97,17 @@ pub(crate) fn client_query<Client: QuakeClient>(address: &IpAddr, port: u16, tim
|
|||
.ok_or(GDError::PacketBad)?
|
||||
.parse()
|
||||
.map_err(|_| GDError::TypeParse)?,
|
||||
has_password: server_vars.remove("needpass")
|
||||
.or(server_vars.remove("g_needpass"))
|
||||
.ok_or(GDError::PacketBad)? == "1",
|
||||
players,
|
||||
frag_limit: server_vars.remove("fraglimit")
|
||||
.ok_or(GDError::PacketBad)?
|
||||
.parse()
|
||||
.map_err(|_| GDError::TypeParse)?,
|
||||
time_limit: server_vars.remove("timelimit")
|
||||
.ok_or(GDError::PacketBad)?
|
||||
.parse()
|
||||
.map_err(|_| GDError::TypeParse)?,
|
||||
version: server_vars.remove("version")
|
||||
.or(server_vars.remove("*version"))
|
||||
.ok_or(GDError::PacketBad)?,
|
||||
unused_entries: server_vars,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn remove_wrapping_quotes<'a>(string: &&'a str) -> &'a str {
|
||||
match string.starts_with('\"') && string.ends_with('\"') {
|
||||
false => string,
|
||||
true => &string[1..string.len() - 1]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ 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::quake::client::{QuakeClient, client_query, remove_wrapping_quotes};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -13,9 +13,9 @@ use serde::{Deserialize, Serialize};
|
|||
pub struct Player {
|
||||
/// Player's server id.
|
||||
pub id: u8,
|
||||
pub score: u8,
|
||||
pub time: u8,
|
||||
pub ping: u8,
|
||||
pub score: u16,
|
||||
pub time: u16,
|
||||
pub ping: u16,
|
||||
pub name: String,
|
||||
pub skin: String,
|
||||
pub color_primary: u8,
|
||||
|
|
@ -54,11 +54,11 @@ impl QuakeClient for QuakeOne {
|
|||
},
|
||||
name: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.to_string()
|
||||
Some(v) => remove_wrapping_quotes(v).to_string()
|
||||
},
|
||||
skin: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.to_string()
|
||||
Some(v) => remove_wrapping_quotes(v).to_string()
|
||||
},
|
||||
color_primary: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::slice::Iter;
|
|||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::one::QuakeOne;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::client::{QuakeClient, client_query};
|
||||
use crate::protocols::quake::client::{QuakeClient, client_query, remove_wrapping_quotes};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -12,8 +12,8 @@ use serde::{Deserialize, Serialize};
|
|||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Player {
|
||||
pub frags: u8,
|
||||
pub ping: u8,
|
||||
pub frags: u16,
|
||||
pub ping: u16,
|
||||
pub name: String
|
||||
}
|
||||
|
||||
|
|
@ -41,10 +41,7 @@ impl QuakeClient for QuakeTwo {
|
|||
},
|
||||
name: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => match v.starts_with('\"') && v.ends_with('\"') {
|
||||
false => v,
|
||||
true => &v[1..v.len() - 1]
|
||||
}.to_string()
|
||||
Some(v) => remove_wrapping_quotes(v).to_string()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,6 @@ pub struct Response<P> {
|
|||
pub players_online: u8,
|
||||
/// Maximum number of players the server reports it can hold.
|
||||
pub players_maximum: u8,
|
||||
/// Indicates whether the server requires a password.
|
||||
pub has_password: bool,
|
||||
/// Maximum server frags.
|
||||
pub frag_limit: u8,
|
||||
/// Maximum server time.
|
||||
pub time_limit: u8,
|
||||
/// The server version.
|
||||
pub version: String,
|
||||
/// Other server entries that weren't used.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue