mirror of
https://github.com/Tribufu/rust-gamedig
synced 2026-08-17 10:51:05 +00:00
* [Protocol] Standardize The Ship fields * [Protocol] Standardize FFOW fields * [Protocol] Rename Valve's protocol field to protocol_version * [Protocol] Rename Minecraft's version_protocol field to protocol_version * [Protocol] Rename Valve's version field to game_version * [Protocol] Rename Minecraft java version_name to game_version * [Crate] Reformat RESPONSES.md * [Protocol] Renamed Minecraft Java players_sample to players * [Protocol] Rename Quake (1,2,3) version field to game_version * [Protocol] Rename quake (1 and 2) game_type field to game_mode * [Protocol] Rename Valve, FFOW, TS game field to game_mode * [Generics] Rename game field/function to game_mode * [Protocol] Change players_minimum, _maximum and _bots from those who werent u8 or u32 to u32 * [Protocol] Change instances of player score field type from u32 to i32 * [Crate] Nicer gramar in CHANGELOG * [Protocol] Apply clippy fixes
46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
use crate::{
|
|
protocols::valve::{self, game, SteamApp},
|
|
GDErrorKind::TypeParse,
|
|
GDResult,
|
|
};
|
|
use std::net::{IpAddr, SocketAddr};
|
|
|
|
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
|
let mut valve_response = valve::query(
|
|
&SocketAddr::new(*address, port.unwrap_or(7780)),
|
|
SteamApp::BAT1944.as_engine(),
|
|
None,
|
|
None,
|
|
)?;
|
|
|
|
if let Some(rules) = &mut valve_response.rules {
|
|
if let Some(bat_max_players) = rules.get("bat_max_players_i") {
|
|
valve_response.info.players_maximum = bat_max_players.parse().map_err(|e| TypeParse.context(e))?;
|
|
rules.remove("bat_max_players_i");
|
|
}
|
|
|
|
if let Some(bat_player_count) = rules.get("bat_player_count_s") {
|
|
valve_response.info.players_online = bat_player_count.parse().map_err(|e| TypeParse.context(e))?;
|
|
rules.remove("bat_player_count_s");
|
|
}
|
|
|
|
if let Some(bat_has_password) = rules.get("bat_has_password_s") {
|
|
valve_response.info.has_password = bat_has_password == "Y";
|
|
rules.remove("bat_has_password_s");
|
|
}
|
|
|
|
if let Some(bat_name) = rules.get("bat_name_s") {
|
|
valve_response.info.name = bat_name.clone();
|
|
rules.remove("bat_name_s");
|
|
}
|
|
|
|
if let Some(bat_gamemode) = rules.get("bat_gamemode_s") {
|
|
valve_response.info.game_mode = bat_gamemode.clone();
|
|
rules.remove("bat_gamemode_s");
|
|
}
|
|
|
|
rules.remove("bat_map_s");
|
|
}
|
|
|
|
Ok(game::Response::new_from_valve_response(valve_response))
|
|
}
|