[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 {
"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}");
};
@ -143,30 +144,19 @@ fn extract_players(server_vars: &mut HashMap<String, String>, players_maximum: u
.clone()
}
},
team: player_data
.get("team")
.ok_or(GDErrorKind::PacketBad)?
.trim()
.parse()
.map_err(|e| TypeParse.context(e))?,
team: match player_data.get("team") {
Some(t) => Some(t.trim().parse().map_err(|e| TypeParse.context(e))?),
None => None,
},
ping: player_data
.get("ping")
.ok_or(GDErrorKind::PacketBad)?
.trim()
.parse()
.map_err(|e| TypeParse.context(e))?,
face: player_data
.get("face")
.ok_or(GDErrorKind::PacketBad)?
.clone(),
skin: player_data
.get("skin")
.ok_or(GDErrorKind::PacketBad)?
.clone(),
mesh: player_data
.get("mesh")
.ok_or(GDErrorKind::PacketBad)?
.clone(),
face: player_data.get("face").cloned(),
skin: player_data.get("skin").cloned(),
mesh: player_data.get("mesh").cloned(),
score: player_data
.get("frags")
.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))?),
None => None,
},
secret: player_data
.get("ngsecret")
.ok_or(GDErrorKind::PacketBad)?
.to_lowercase()
.parse()
.map_err(|e| TypeParse.context(e))?,
secret: match player_data.get("ngsecret") {
Some(s) => Some(s.to_lowercase().parse().map_err(|e| TypeParse.context(e))?),
None => None,
},
};
players.push(new_player);

View file

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