mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
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
This commit is contained in:
parent
f01cac8fed
commit
0d27882150
2 changed files with 17 additions and 6 deletions
|
|
@ -167,10 +167,17 @@ impl Unreal2Protocol {
|
|||
/// Make a full server query.
|
||||
pub fn query(&mut self, gather_settings: &GatheringSettings) -> GDResult<Response> {
|
||||
// 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()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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::<Unreal2StringDecoder>(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<bool> { Some(self.server_info.password) }
|
||||
|
||||
fn players(&self) -> Option<Vec<&dyn crate::protocols::types::CommonPlayer>> {
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue