Games: Add Battalion 1944 from-rules server information's

This commit is contained in:
CosminPerRam 2023-01-13 23:52:45 +02:00
parent 9bcbfbc198
commit 4a7eb400db
3 changed files with 33 additions and 3 deletions

View file

@ -31,7 +31,7 @@ A supported game is defined as a game that has been successfully tested, other g
| Day of Infamy | DOI | Valve Protocol | |
| Half-Life Deathmatch: Source | HLDMS | Valve Protocol | |
| Risk of Rain 2 | ROR2 | Valve Protocol | Query port offset: 1. |
| Battalion 1944 | BAT1944 | Valve Protocol | Query port offset: 3. |
| Battalion 1944 | BAT1944 | Valve Protocol | Query port offset: 3. It is strongly recommended to also query the rules, as the game sends server information's in them. |
## Planned to add support:
_

View file

@ -70,7 +70,7 @@ fn main() -> GDResult<()> {
"doi" => println!("{:#?}", doi::query(ip, port)?),
"hldms" => println!("{:#?}", hldms::query(ip, port)?),
"ror2" => println!("{:#?}", ror2::query(ip, port)?),
"bat1944" => println!("{:?}", bat1944::query(ip, port)?),
"bat1944" => println!("{:#?}", bat1944::query(ip, port)?),
_ => panic!("Undefined game: {}", args[1])
};

View file

@ -1,12 +1,42 @@
use crate::GDError::TypeParse;
use crate::GDResult;
use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port {
let mut valve_response = valve::query(address, match port {
None => 7780,
Some(port) => port
}, SteamID::BAT1944.as_app(), 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(|_| TypeParse)?;
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(|_| TypeParse)?;
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 = bat_gamemode.clone();
rules.remove("bat_gamemode_s");
}
rules.remove("bat_map_s");
}
Ok(game::Response::new_from_valve_response(valve_response))
}