Skip to content

Commit

Permalink
[Protocol] Gamespy1 make more player fields optional (gamedig#88)
Browse files Browse the repository at this point in the history
These fields seem to be missing from bf1942 queries so make them
optional.
  • Loading branch information
Douile committed Aug 21, 2023
1 parent 95ac774 commit 9aa446f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
35 changes: 11 additions & 24 deletions src/protocols/gamespy/protocols/one/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,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)?
Expand All @@ -182,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);
Expand Down
10 changes: 5 additions & 5 deletions src/protocols/gamespy/protocols/one/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9aa446f

Please sign in to comment.