From 0d27882150d5d18f8d74bfad5c3f0fd56ff75e79 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Thu, 9 Nov 2023 01:18:52 +0200 Subject: [PATCH] feat(unreal2): Add password rule check (#149) * feat: add initial password checking * feat: add password string check and made the field a bool * chore: fix formatting * feat: add password to has_password common response --- crates/lib/src/protocols/unreal2/protocol.rs | 11 +++++++++-- crates/lib/src/protocols/unreal2/types.rs | 12 ++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/lib/src/protocols/unreal2/protocol.rs b/crates/lib/src/protocols/unreal2/protocol.rs index 0dde6ca..46f16c8 100644 --- a/crates/lib/src/protocols/unreal2/protocol.rs +++ b/crates/lib/src/protocols/unreal2/protocol.rs @@ -167,10 +167,17 @@ impl Unreal2Protocol { /// Make a full server query. pub fn query(&mut self, gather_settings: &GatheringSettings) -> GDResult { // Fetch the server info, this can only handle one response packet - let server_info = self.query_server_info()?; + let mut server_info = self.query_server_info()?; let mutators_and_rules = if gather_settings.mutators_and_rules { - self.query_mutators_and_rules()? + let response = self.query_mutators_and_rules()?; + + if let Some(password) = response.rules.get("GamePassword") { + let string = password.concat().to_lowercase(); + server_info.password = string == "true"; + } + + response } else { MutatorsAndRules::default() }; diff --git a/crates/lib/src/protocols/unreal2/types.rs b/crates/lib/src/protocols/unreal2/types.rs index 594e76f..468e9e8 100644 --- a/crates/lib/src/protocols/unreal2/types.rs +++ b/crates/lib/src/protocols/unreal2/types.rs @@ -45,6 +45,7 @@ pub struct ServerInfo { pub game_type: String, pub num_players: u32, pub max_players: u32, + pub password: bool, } impl ServerInfo { @@ -59,6 +60,7 @@ impl ServerInfo { game_type: buffer.read_string::(None)?, num_players: buffer.read()?, max_players: buffer.read()?, + password: false, }) } } @@ -178,16 +180,20 @@ pub struct Response { } impl CommonResponse for Response { - fn map(&self) -> Option<&str> { Some(&self.server_info.map) } + fn as_original(&self) -> GenericResponse { GenericResponse::Unreal2(self) } fn name(&self) -> Option<&str> { Some(&self.server_info.name) } fn game_mode(&self) -> Option<&str> { Some(&self.server_info.game_type) } - fn players_online(&self) -> u32 { self.server_info.num_players } + fn map(&self) -> Option<&str> { Some(&self.server_info.map) } fn players_maximum(&self) -> u32 { self.server_info.max_players } + fn players_online(&self) -> u32 { self.server_info.num_players } + + fn has_password(&self) -> Option { Some(self.server_info.password) } + fn players(&self) -> Option> { Some( self.players @@ -197,8 +203,6 @@ impl CommonResponse for Response { .collect(), ) } - - fn as_original(&self) -> GenericResponse { GenericResponse::Unreal2(self) } } /// What data to gather, purely used only with the query function.