[Protocol] Make gamespy1 parsing less likely to fail (#107)

* [Protocol] Gamespy1 don't skip "playername" field (#88)

* [Protocol] Gamespy1 make more player fields optional (#88)

These fields seem to be missing from bf1942 queries so make them
optional.
This commit is contained in:
Tom 2023-09-27 14:07:42 +00:00 committed by GitHub
parent 5bd609af72
commit efc1828b29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 30 deletions

View file

@ -113,7 +113,8 @@ fn extract_players(server_vars: &mut HashMap<String, String>, players_maximum: u
}; };
let early_return = match kind { let early_return = match kind {
"team" | "player" | "ping" | "face" | "skin" | "mesh" | "frags" | "ngsecret" | "deaths" | "health" => false, "team" | "player" | "playername" | "ping" | "face" | "skin" | "mesh" | "frags" | "ngsecret" | "deaths"
| "health" => false,
_x => true, // println!("UNKNOWN {id} {x} {value}"); _x => true, // println!("UNKNOWN {id} {x} {value}");
}; };
@ -143,30 +144,19 @@ fn extract_players(server_vars: &mut HashMap<String, String>, players_maximum: u
.clone() .clone()
} }
}, },
team: player_data team: match player_data.get("team") {
.get("team") Some(t) => Some(t.trim().parse().map_err(|e| TypeParse.context(e))?),
.ok_or(GDErrorKind::PacketBad)? None => None,
.trim() },
.parse()
.map_err(|e| TypeParse.context(e))?,
ping: player_data ping: player_data
.get("ping") .get("ping")
.ok_or(GDErrorKind::PacketBad)? .ok_or(GDErrorKind::PacketBad)?
.trim() .trim()
.parse() .parse()
.map_err(|e| TypeParse.context(e))?, .map_err(|e| TypeParse.context(e))?,
face: player_data face: player_data.get("face").cloned(),
.get("face") skin: player_data.get("skin").cloned(),
.ok_or(GDErrorKind::PacketBad)? mesh: player_data.get("mesh").cloned(),
.clone(),
skin: player_data
.get("skin")
.ok_or(GDErrorKind::PacketBad)?
.clone(),
mesh: player_data
.get("mesh")
.ok_or(GDErrorKind::PacketBad)?
.clone(),
score: player_data score: player_data
.get("frags") .get("frags")
.ok_or(GDErrorKind::PacketBad)? .ok_or(GDErrorKind::PacketBad)?
@ -181,12 +171,10 @@ fn extract_players(server_vars: &mut HashMap<String, String>, players_maximum: u
Some(v) => Some(v.trim().parse().map_err(|e| TypeParse.context(e))?), Some(v) => Some(v.trim().parse().map_err(|e| TypeParse.context(e))?),
None => None, None => None,
}, },
secret: player_data secret: match player_data.get("ngsecret") {
.get("ngsecret") Some(s) => Some(s.to_lowercase().parse().map_err(|e| TypeParse.context(e))?),
.ok_or(GDErrorKind::PacketBad)? None => None,
.to_lowercase() },
.parse()
.map_err(|e| TypeParse.context(e))?,
}; };
players.push(new_player); players.push(new_player);

View file

@ -12,16 +12,16 @@ use crate::protocols::GenericResponse;
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Player { pub struct Player {
pub name: String, pub name: String,
pub team: u8, pub team: Option<u8>,
/// The ping from the server's perspective. /// The ping from the server's perspective.
pub ping: u16, pub ping: u16,
pub face: String, pub face: Option<String>,
pub skin: String, pub skin: Option<String>,
pub mesh: String, pub mesh: Option<String>,
pub score: i32, pub score: i32,
pub deaths: Option<u32>, pub deaths: Option<u32>,
pub health: Option<u32>, pub health: Option<u32>,
pub secret: bool, pub secret: Option<bool>,
} }
impl CommonPlayer for Player { impl CommonPlayer for Player {