[Protocol] Valve: support app and dedicated app id

This commit is contained in:
CosminPerRam 2023-02-18 21:44:17 +02:00
parent fe46359e47
commit 150bc1762e
48 changed files with 259 additions and 179 deletions

View file

@ -1,7 +1,14 @@
Who knows what the future holds... Who knows what the future holds...
# 0.1.Y - DD/MM/2023 # 0.X.Y - DD/MM/2023
### Changes:
None.
### Breaking:
None.
# 0.2.0 - 18/02/2023
### Changes: ### Changes:
Games: Games:
- [Don't Starve Together](https://store.steampowered.com/app/322330/Dont_Starve_Together/) support. - [Don't Starve Together](https://store.steampowered.com/app/322330/Dont_Starve_Together/) support.
@ -13,8 +20,20 @@ Games:
- [Avorion](https://store.steampowered.com/app/445220/Avorion/) support. - [Avorion](https://store.steampowered.com/app/445220/Avorion/) support.
- [Operation: Harsh Doorstop](https://store.steampowered.com/app/736590/Operation_Harsh_Doorstop/) support. - [Operation: Harsh Doorstop](https://store.steampowered.com/app/736590/Operation_Harsh_Doorstop/) support.
Protocols:
- Valve:
1. `appid` is now a field in the `Response` struct.
### Breaking: ### Breaking:
Nothing. Protocols:
- Valve:
due to some games being able to host a server from within the game AND from a dedicated server,
if you were to query one of them, the query would fail for the other one, as the `SteamID` enum
for that game could specify only one id.
1. `SteamID` is now `SteamApp`, was an u32 enum, and now it's a simple enum.
2. `App` is now `Engine`, the `Source` enum's structure has been changed from `Option<u32>` to
`Option<u32, Option<u32>>`, where the first parameter is the game app id and the second is
the dedicated server app id (if there is one).
# 0.1.0 - 17/01/2023 # 0.1.0 - 17/01/2023
### Changes: ### Changes:

View file

@ -1,6 +1,6 @@
[package] [package]
name = "gamedig" name = "gamedig"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
authors = ["CosminPerRam [cosmin.p@live.com]", "node-GameDig [https://github.com/gamedig/node-gamedig]"] authors = ["CosminPerRam [cosmin.p@live.com]", "node-GameDig [https://github.com/gamedig/node-gamedig]"]
license = "MIT" license = "MIT"

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022 CosminPerRam Copyright (c) 2023 CosminPerRam
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -15,7 +15,7 @@ use gamedig::games::tf2;
fn main() { fn main() {
let response = tf2::query("127.0.0.1", None); // None is the default port (which is 27015), could also be Some(27015) let response = tf2::query("127.0.0.1", None); // None is the default port (which is 27015), could also be Some(27015)
match response { match response { // Result type, must check what it is...
Err(error) => println!("Couldn't query, error: {}", error), Err(error) => println!("Couldn't query, error: {}", error),
Ok(r) => println!("{:#?}", r) Ok(r) => println!("{:#?}", r)
} }
@ -28,6 +28,7 @@ Response (note that some games have a different structure):
name: "Team Fortress 2 Dedicated Server.", name: "Team Fortress 2 Dedicated Server.",
map: "ctf_turbine", map: "ctf_turbine",
game: "tf2", game: "tf2",
appid: 440,
players_online: 0, players_online: 0,
players_details: [], players_details: [],
players_maximum: 69, players_maximum: 69,

View file

@ -3,7 +3,7 @@ use std::env;
use gamedig::{aliens, aoc, arma2oa, ase, asrd, avorion, bat1944, bb2, bm, bo, ccure, cosu, cs, cscz, csgo, css, dod, dods, doi, dst, GDResult, gm, hl2dm, hldms, ins, insmic, inss, l4d, l4d2, mc, ohd, onset, pz, ror2, rust, sc, sdtd, tf, tf2, tfc, ts, unturned}; use gamedig::{aliens, aoc, arma2oa, ase, asrd, avorion, bat1944, bb2, bm, bo, ccure, cosu, cs, cscz, csgo, css, dod, dods, doi, dst, GDResult, gm, hl2dm, hldms, ins, insmic, inss, l4d, l4d2, mc, ohd, onset, pz, ror2, rust, sc, sdtd, tf, tf2, tfc, ts, unturned};
use gamedig::protocols::minecraft::LegacyGroup; use gamedig::protocols::minecraft::LegacyGroup;
use gamedig::protocols::valve; use gamedig::protocols::valve;
use gamedig::protocols::valve::App; use gamedig::protocols::valve::Engine;
fn main() -> GDResult<()> { fn main() -> GDResult<()> {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
@ -48,9 +48,9 @@ fn main() -> GDResult<()> {
"ts" => println!("{:#?}", ts::query(ip, port)?), "ts" => println!("{:#?}", ts::query(ip, port)?),
"cscz" => println!("{:#?}", cscz::query(ip, port)?), "cscz" => println!("{:#?}", cscz::query(ip, port)?),
"dod" => println!("{:#?}", dod::query(ip, port)?), "dod" => println!("{:#?}", dod::query(ip, port)?),
"_src" => println!("{:#?}", valve::query(ip, port.unwrap(), App::Source(None), None, None)?), "_src" => println!("{:#?}", valve::query(ip, port.unwrap(), Engine::Source(None), None, None)?),
"_gld" => println!("{:#?}", valve::query(ip, port.unwrap(), App::GoldSrc(false), None, None)?), "_gld" => println!("{:#?}", valve::query(ip, port.unwrap(), Engine::GoldSrc(false), None, None)?),
"_gld_f" => println!("{:#?}", valve::query(ip, port.unwrap(), App::GoldSrc(true), None, None)?), "_gld_f" => println!("{:#?}", valve::query(ip, port.unwrap(), Engine::GoldSrc(true), None, None)?),
"mc" => println!("{:#?}", mc::query(ip, port)?), "mc" => println!("{:#?}", mc::query(ip, port)?),
"mc_java" => println!("{:#?}", mc::query_java(ip, port)?), "mc_java" => println!("{:#?}", mc::query_java(ip, port)?),
"mc_bedrock" => println!("{:#?}", mc::query_bedrock(ip, port)?), "mc_bedrock" => println!("{:#?}", mc::query_bedrock(ip, port)?),

View file

@ -3,7 +3,7 @@ use gamedig::games::tf2;
fn main() { fn main() {
let response = tf2::query("127.0.0.1", None); //or Some(27015), None is the default protocol port (which is 27015) let response = tf2::query("127.0.0.1", None); //or Some(27015), None is the default protocol port (which is 27015)
match response { match response { // Result type, must check what it is...
Err(error) => println!("Couldn't query, error: {}", error), Err(error) => println!("Couldn't query, error: {}", error),
Ok(r) => println!("{:#?}", r) Ok(r) => println!("{:#?}", r)
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::ALIENS.as_app(), None, None)?; }, SteamApp::ALIENS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::AOC.as_app(), None, None)?; }, SteamApp::AOC.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 2304, None => 2304,
Some(port) => port Some(port) => port
}, SteamID::ARMA2OA.as_app(), None, None)?; }, SteamApp::ARMA2OA.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::ASE.as_app(), None, None)?; }, SteamApp::ASE.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::ASRD.as_app(), None, None)?; }, SteamApp::ASRD.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27020, None => 27020,
Some(port) => port Some(port) => port
}, SteamID::AVORION.as_app(), None, None)?; }, SteamApp::AVORION.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,13 +1,13 @@
use crate::GDError::TypeParse; use crate::GDError::TypeParse;
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let mut valve_response = valve::query(address, match port { let mut valve_response = valve::query(address, match port {
None => 7780, None => 7780,
Some(port) => port Some(port) => port
}, SteamID::BAT1944.as_app(), None, None)?; }, SteamApp::BAT1944.as_engine(), None, None)?;
if let Some(rules) = &mut valve_response.rules { if let Some(rules) = &mut valve_response.rules {
if let Some(bat_max_players) = rules.get("bat_max_players_i") { if let Some(bat_max_players) = rules.get("bat_max_players_i") {

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::BB2.as_app(), None, None)?; }, SteamApp::BB2.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::BM.as_app(), None, None)?; }, SteamApp::BM.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27016, None => 27016,
Some(port) => port Some(port) => port
}, SteamID::BO.as_app(), None, None)?; }, SteamApp::BO.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::CCURE.as_app(), None, None)?; }, SteamApp::CCURE.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27004, None => 27004,
Some(port) => port Some(port) => port
}, SteamID::COSU.as_app(), None, None)?; }, SteamApp::COSU.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::CS.as_app(), None, None)?; }, SteamApp::CS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::CSCZ.as_app(), None, None)?; }, SteamApp::CSCZ.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::CSGO.as_app(), None, None)?; }, SteamApp::CSGO.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::CSS.as_app(), None, None)?; }, SteamApp::CSS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::DOD.as_app(), None, None)?; }, SteamApp::DOD.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::DODS.as_app(), None, None)?; }, SteamApp::DODS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::DOI.as_app(), None, None)?; }, SteamApp::DOI.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27016, None => 27016,
Some(port) => port Some(port) => port
}, SteamID::DST.as_app(), None, None)?; }, SteamApp::DST.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::GM.as_app(), None, None)?; }, SteamApp::GM.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::HL2DM.as_app(), None, None)?; }, SteamApp::HL2DM.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::HLDMS.as_app(), None, None)?; }, SteamApp::HLDMS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::INS.as_app(), None, None)?; }, SteamApp::INS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::INSMIC.as_app(), None, None)?; }, SteamApp::INSMIC.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27131, None => 27131,
Some(port) => port Some(port) => port
}, SteamID::INSS.as_app(), None, None)?; }, SteamApp::INSS.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::L4D.as_app(), None, None)?; }, SteamApp::L4D.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::L4D2.as_app(), None, None)?; }, SteamApp::L4D2.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27005, None => 27005,
Some(port) => port Some(port) => port
}, SteamID::OHD.as_app(), None, None)?; }, SteamApp::OHD.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 7776, None => 7776,
Some(port) => port Some(port) => port
}, SteamID::ONSET.as_app(), None, None)?; }, SteamApp::ONSET.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 16261, None => 16261,
Some(port) => port Some(port) => port
}, SteamID::PZ.as_app(), None, None)?; }, SteamApp::PZ.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27016, None => 27016,
Some(port) => port Some(port) => port
}, SteamID::ROR2.as_app(), None, None)?; }, SteamApp::ROR2.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::RUST.as_app(), None, None)?; }, SteamApp::RUST.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::SC.as_app(), None, None)?; }, SteamApp::SC.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 26900, None => 26900,
Some(port) => port Some(port) => port
}, SteamID::SDTD.as_app(), None, None)?; }, SteamApp::SDTD.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27016, None => 27016,
Some(port) => port Some(port) => port
}, SteamID::TF.as_app(), None, None)?; }, SteamApp::TF.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::TF2.as_app(), None, None)?; }, SteamApp::TF2.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::TFC.as_app(), None, None)?; }, SteamApp::TFC.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{Server, ServerPlayer, get_optional_extracted_data, SteamID}; use crate::protocols::valve::{Server, ServerPlayer, get_optional_extracted_data, SteamApp};
#[derive(Debug)] #[derive(Debug)]
pub struct TheShipPlayer { pub struct TheShipPlayer {
@ -85,7 +85,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::TS.as_app(), None, None)?; }, SteamApp::TS.as_engine(), None, None)?;
Ok(Response::new_from_valve_response(valve_response)) Ok(Response::new_from_valve_response(valve_response))
} }

View file

@ -1,12 +1,12 @@
use crate::GDResult; use crate::GDResult;
use crate::protocols::valve; use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID}; use crate::protocols::valve::{game, SteamApp};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> { pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
let valve_response = valve::query(address, match port { let valve_response = valve::query(address, match port {
None => 27015, None => 27015,
Some(port) => port Some(port) => port
}, SteamID::UNTURNED.as_app(), None, None)?; }, SteamApp::UNTURNED.as_engine(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response)) Ok(game::Response::new_from_valve_response(valve_response))
} }

View file

@ -4,7 +4,7 @@ use crate::GDResult;
use crate::bufferer::{Bufferer, Endianess}; use crate::bufferer::{Bufferer, Endianess};
use crate::GDError::{BadGame, Decompress, UnknownEnumCast}; use crate::GDError::{BadGame, Decompress, UnknownEnumCast};
use crate::protocols::types::TimeoutSettings; use crate::protocols::types::TimeoutSettings;
use crate::protocols::valve::{App, ModData, SteamID}; use crate::protocols::valve::{Engine, ModData, SteamApp};
use crate::protocols::valve::types::{Environment, ExtraData, GatheringSettings, Request, Response, Server, ServerInfo, ServerPlayer, TheShip}; use crate::protocols::valve::types::{Environment, ExtraData, GatheringSettings, Request, Response, Server, ServerInfo, ServerPlayer, TheShip};
use crate::socket::{Socket, UdpSocket}; use crate::socket::{Socket, UdpSocket};
use crate::utils::u8_lower_upper; use crate::utils::u8_lower_upper;
@ -77,18 +77,18 @@ struct SplitPacket {
} }
impl SplitPacket { impl SplitPacket {
fn new(app: &App, protocol: u8, buffer: &mut Bufferer) -> GDResult<Self> { fn new(engine: &Engine, protocol: u8, buffer: &mut Bufferer) -> GDResult<Self> {
let header = buffer.get_u32()?; let header = buffer.get_u32()?;
let id = buffer.get_u32()?; let id = buffer.get_u32()?;
let (total, number, size, compressed, decompressed_size, uncompressed_crc32) = match app { let (total, number, size, compressed, decompressed_size, uncompressed_crc32) = match engine {
App::GoldSrc(_) => { Engine::GoldSrc(_) => {
let (lower, upper) = u8_lower_upper(buffer.get_u8()?); let (lower, upper) = u8_lower_upper(buffer.get_u8()?);
(lower, upper, 0, false, None, None) (lower, upper, 0, false, None, None)
} }
App::Source(_) => { Engine::Source(_) => {
let total = buffer.get_u8()?; let total = buffer.get_u8()?;
let number = buffer.get_u8()?; let number = buffer.get_u8()?;
let size = match protocol == 7 && (*app == SteamID::CSS.as_app()) { //certain apps with protocol = 7 doesnt have this field let size = match protocol == 7 && (*engine == SteamApp::CSS.as_engine()) { //certain apps with protocol = 7 dont have this field
false => buffer.get_u16()?, false => buffer.get_u16()?,
true => 1248 true => 1248
}; };
@ -155,20 +155,20 @@ impl ValveProtocol {
}) })
} }
fn receive(&mut self, app: &App, protocol: u8, buffer_size: usize) -> GDResult<Packet> { fn receive(&mut self, engine: &Engine, protocol: u8, buffer_size: usize) -> GDResult<Packet> {
let data = self.socket.receive(Some(buffer_size))?; let data = self.socket.receive(Some(buffer_size))?;
let mut buffer = Bufferer::new_with_data(Endianess::Little, &data); let mut buffer = Bufferer::new_with_data(Endianess::Little, &data);
let header = buffer.get_u8()?; let header = buffer.get_u8()?;
buffer.move_position_backward(1); buffer.move_position_backward(1);
if header == 0xFE { //the packet is split if header == 0xFE { //the packet is split
let mut main_packet = SplitPacket::new(&app, protocol, &mut buffer)?; let mut main_packet = SplitPacket::new(&engine, protocol, &mut buffer)?;
let mut chunk_packets = Vec::with_capacity((main_packet.total - 1) as usize); let mut chunk_packets = Vec::with_capacity((main_packet.total - 1) as usize);
for _ in 1..main_packet.total { for _ in 1..main_packet.total {
let new_data = self.socket.receive(Some(buffer_size))?; let new_data = self.socket.receive(Some(buffer_size))?;
buffer = Bufferer::new_with_data(Endianess::Little, &new_data); buffer = Bufferer::new_with_data(Endianess::Little, &new_data);
let chunk_packet = SplitPacket::new(&app, protocol, &mut buffer)?; let chunk_packet = SplitPacket::new(&engine, protocol, &mut buffer)?;
chunk_packets.push(chunk_packet); chunk_packets.push(chunk_packet);
} }
@ -187,11 +187,11 @@ impl ValveProtocol {
} }
/// Ask for a specific request only. /// Ask for a specific request only.
fn get_request_data(&mut self, app: &App, protocol: u8, kind: Request) -> GDResult<Bufferer> { fn get_request_data(&mut self, engine: &Engine, protocol: u8, kind: Request) -> GDResult<Bufferer> {
let request_initial_packet = Packet::initial(kind).to_bytes(); let request_initial_packet = Packet::initial(kind).to_bytes();
self.socket.send(&request_initial_packet)?; self.socket.send(&request_initial_packet)?;
let packet = self.receive(app, protocol, PACKET_SIZE)?; let packet = self.receive(engine, protocol, PACKET_SIZE)?;
if packet.kind != 0x41 { //'A' if packet.kind != 0x41 { //'A'
let data = packet.payload.clone(); let data = packet.payload.clone();
@ -203,7 +203,7 @@ impl ValveProtocol {
self.socket.send(&challenge_packet)?; self.socket.send(&challenge_packet)?;
let data = self.receive(app, protocol, PACKET_SIZE)?.payload; let data = self.receive(engine, protocol, PACKET_SIZE)?.payload;
Ok(Bufferer::new_with_data(Endianess::Little, &data)) Ok(Bufferer::new_with_data(Endianess::Little, &data))
} }
@ -267,10 +267,10 @@ impl ValveProtocol {
} }
/// Get the server information's. /// Get the server information's.
fn get_server_info(&mut self, app: &App) -> GDResult<ServerInfo> { fn get_server_info(&mut self, engine: &Engine) -> GDResult<ServerInfo> {
let mut buffer = self.get_request_data(&app, 0, Request::INFO)?; let mut buffer = self.get_request_data(&engine, 0, Request::INFO)?;
if let App::GoldSrc(force) = app { if let Engine::GoldSrc(force) = engine {
if *force { if *force {
return ValveProtocol::get_goldsrc_server_info(&mut buffer); return ValveProtocol::get_goldsrc_server_info(&mut buffer);
} }
@ -299,7 +299,7 @@ impl ValveProtocol {
}; };
let has_password = buffer.get_u8()? == 1; let has_password = buffer.get_u8()? == 1;
let vac_secured = buffer.get_u8()? == 1; let vac_secured = buffer.get_u8()? == 1;
let the_ship = match *app == SteamID::TS.as_app() { let the_ship = match *engine == SteamApp::TS.as_engine() {
false => None, false => None,
true => Some(TheShip { true => Some(TheShip {
mode: buffer.get_u8()?, mode: buffer.get_u8()?,
@ -366,8 +366,8 @@ impl ValveProtocol {
} }
/// Get the server player's. /// Get the server player's.
fn get_server_players(&mut self, app: &App, protocol: u8) -> GDResult<Vec<ServerPlayer>> { fn get_server_players(&mut self, engine: &Engine, protocol: u8) -> GDResult<Vec<ServerPlayer>> {
let mut buffer = self.get_request_data(&app, protocol, Request::PLAYERS)?; let mut buffer = self.get_request_data(&engine, protocol, Request::PLAYERS)?;
let count = buffer.get_u8()? as usize; let count = buffer.get_u8()? as usize;
let mut players: Vec<ServerPlayer> = Vec::with_capacity(count); let mut players: Vec<ServerPlayer> = Vec::with_capacity(count);
@ -379,11 +379,11 @@ impl ValveProtocol {
let score = buffer.get_u32()?; let score = buffer.get_u32()?;
let duration = buffer.get_f32()?; let duration = buffer.get_f32()?;
let deaths = match *app == SteamID::TS.as_app() { let deaths = match *engine == SteamApp::TS.as_engine() {
false => None, false => None,
true => Some(buffer.get_u32()?) true => Some(buffer.get_u32()?)
}; };
let money = match *app == SteamID::TS.as_app() { let money = match *engine == SteamApp::TS.as_engine() {
false => None, false => None,
true => Some(buffer.get_u32()?) true => Some(buffer.get_u32()?)
}; };
@ -403,8 +403,8 @@ impl ValveProtocol {
} }
/// Get the server's rules. /// Get the server's rules.
fn get_server_rules(&mut self, app: &App, protocol: u8) -> GDResult<HashMap<String, String>> { fn get_server_rules(&mut self, engine: &Engine, protocol: u8) -> GDResult<HashMap<String, String>> {
let mut buffer = self.get_request_data(&app, protocol, Request::RULES)?; let mut buffer = self.get_request_data(&engine, protocol, Request::RULES)?;
let count = buffer.get_u16()? as usize; let count = buffer.get_u16()? as usize;
let mut rules: HashMap<String, String> = HashMap::with_capacity(count); let mut rules: HashMap<String, String> = HashMap::with_capacity(count);
@ -416,7 +416,7 @@ impl ValveProtocol {
rules.insert(name, value); rules.insert(name, value);
} }
if *app == SteamID::ROR2.as_app() { if *engine == SteamApp::ROR2.as_engine() {
rules.remove("Test"); rules.remove("Test");
} }
@ -426,20 +426,30 @@ impl ValveProtocol {
/// Query a server by providing the address, the port, the app, gather and timeout settings. /// Query a server by providing the address, the port, the app, gather and timeout settings.
/// Providing None to the settings results in using the default values for them (GatherSettings::[default](GatheringSettings::default), TimeoutSettings::[default](TimeoutSettings::default)). /// Providing None to the settings results in using the default values for them (GatherSettings::[default](GatheringSettings::default), TimeoutSettings::[default](TimeoutSettings::default)).
pub fn query(address: &str, port: u16, app: App, gather_settings: Option<GatheringSettings>, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> { pub fn query(address: &str, port: u16, engine: Engine, gather_settings: Option<GatheringSettings>, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
let response_gather_settings = gather_settings.unwrap_or(GatheringSettings::default()); let response_gather_settings = gather_settings.unwrap_or(GatheringSettings::default());
get_response(address, port, app, response_gather_settings, timeout_settings) get_response(address, port, engine, response_gather_settings, timeout_settings)
} }
fn get_response(address: &str, port: u16, app: App, gather_settings: GatheringSettings, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> { fn get_response(address: &str, port: u16, engine: Engine, gather_settings: GatheringSettings, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
let mut client = ValveProtocol::new(address, port, timeout_settings)?; let mut client = ValveProtocol::new(address, port, timeout_settings)?;
let info = client.get_server_info(&app)?; let info = client.get_server_info(&engine)?;
let protocol = info.protocol; let protocol = info.protocol;
if let App::Source(source_app) = &app { if let Engine::Source(source_app) = &engine {
if let Some(appid) = source_app { if let Some(appids) = source_app {
if *appid != info.appid { let mut is_specified_id = false;
if appids.0 == info.appid {
is_specified_id = true;
} else if let Some(dedicated_appid) = appids.1 {
if dedicated_appid == info.appid {
is_specified_id = true;
}
}
if !is_specified_id {
return Err(BadGame(format!("AppId: {}", info.appid))); return Err(BadGame(format!("AppId: {}", info.appid)));
} }
} }
@ -449,11 +459,11 @@ fn get_response(address: &str, port: u16, app: App, gather_settings: GatheringSe
info, info,
players: match gather_settings.players { players: match gather_settings.players {
false => None, false => None,
true => Some(client.get_server_players(&app, protocol)?) true => Some(client.get_server_players(&engine, protocol)?)
}, },
rules: match gather_settings.rules { rules: match gather_settings.rules {
false => None, false => None,
true => Some(client.get_server_rules(&app, protocol)?) true => Some(client.get_server_rules(&engine, protocol)?)
} }
}) })
} }

View file

@ -135,114 +135,161 @@ pub(crate) enum Request {
RULES = 0x56 RULES = 0x56
} }
/// Supported steam apps id's /// Supported steam apps
#[repr(u32)]
#[derive(PartialEq, Clone)] #[derive(PartialEq, Clone)]
pub enum SteamID { pub enum SteamApp {
/// Counter-Strike /// Counter-Strike
CS = 10, CS,
/// Team Fortress Classic /// Team Fortress Classic
TFC = 20, TFC,
/// Day of Defeat /// Day of Defeat
DOD = 30, DOD,
/// Counter-Strike: Condition Zero /// Counter-Strike: Condition Zero
CSCZ = 80, CSCZ,
/// Counter-Strike: Source /// Counter-Strike: Source
CSS = 240, CSS,
/// Day of Defeat: Source /// Day of Defeat: Source
DODS = 300, DODS,
/// Half-Life 2 Deathmatch /// Half-Life 2 Deathmatch
HL2DM = 320, HL2DM,
/// Half-Life Deathmatch: Source /// Half-Life Deathmatch: Source
HLDMS = 360, HLDMS,
/// Team Fortress 2 /// Team Fortress 2
TF2 = 440, TF2,
/// Left 4 Dead /// Left 4 Dead
L4D = 500, L4D,
/// Left 4 Dead /// Left 4 Dead
L4D2 = 550, L4D2,
/// Alien Swarm /// Alien Swarm
ALIENS = 630, ALIENS,
/// Counter-Strike: Global Offensive /// Counter-Strike: Global Offensive
CSGO = 730, CSGO,
/// The Ship /// The Ship
TS = 2400, TS,
/// Garry's Mod /// Garry's Mod
GM = 4000, GM,
/// Age of Chivalry /// Age of Chivalry
AOC = 17510, AOC,
/// Insurgency: Modern Infantry Combat /// Insurgency: Modern Infantry Combat
INSMIC = 17700, INSMIC,
/// ARMA 2: Operation Arrowhead /// ARMA 2: Operation Arrowhead
ARMA2OA = 33930, ARMA2OA,
/// Project Zomboid /// Project Zomboid
PZ = 108600, PZ,
/// Insurgency /// Insurgency
INS = 222880, INS,
/// Sven Co-op /// Sven Co-op
SC = 225840, SC,
/// 7 Days To Die /// 7 Days To Die
SDTD = 251570, SDTD,
/// Rust /// Rust
RUST = 252490, RUST,
/// Vallistic Overkill /// Vallistic Overkill
BO = 296300, BO,
/// Don't Starve Together /// Don't Starve Together
DST = 322320, DST,
/// BrainBread 2 /// BrainBread 2
BB2 = 346330, BB2,
/// Codename CURE /// Codename CURE
CCURE = 355180, CCURE,
/// Black Mesa /// Black Mesa
BM = 362890, BM,
/// Colony Survival /// Colony Survival
COSU = 366090, COSU,
/// Avorion /// Avorion
AVORION = 445220, AVORION,
/// Day of Infamy /// Day of Infamy
DOI = 447820, DOI,
/// The Forrest /// The Forest
TF = 556450, //this is the id for the dedicated server, for the game its 242760 TF,
/// Unturned /// Unturned
UNTURNED = 304930, UNTURNED,
/// ARK: Survival Evolved /// ARK: Survival Evolved
ASE = 346110, ASE,
/// Battalion 1944 /// Battalion 1944
BAT1944 = 489940, BAT1944,
/// Insurgency: Sandstorm /// Insurgency: Sandstorm
INSS = 581320, INSS,
/// Alien Swarm: Reactive Drop /// Alien Swarm: Reactive Drop
ASRD = 563560, ASRD,
/// Risk of Rain 2 /// Risk of Rain 2
ROR2 = 632360, ROR2,
/// Operation: Harsh Doorstop /// Operation: Harsh Doorstop
OHD = 950900, // this is the id for the dedicated server, for the game its 736590 OHD,
/// Onset /// Onset
ONSET = 1105810, ONSET,
} }
impl SteamID { impl SteamApp {
/// Get ID as App (the engine is specified). /// Get the specified app as engine.
pub fn as_app(&self) -> App { pub fn as_engine(&self) -> Engine {
match self { match self {
SteamID::CS | SteamID::TFC | SteamID::DOD | SteamID::CSCZ | SteamID::SC => App::GoldSrc(false), SteamApp::CS => Engine::GoldSrc(false), //10
x => App::Source(Some(x.clone() as u32)) SteamApp::TFC => Engine::GoldSrc(false), //20
SteamApp::DOD => Engine::GoldSrc(false), //30
SteamApp::CSCZ => Engine::GoldSrc(false), //80
SteamApp::CSS => Engine::new_source(240),
SteamApp::DODS => Engine::new_source(300),
SteamApp::HL2DM => Engine::new_source(320),
SteamApp::HLDMS => Engine::new_source(360),
SteamApp::TF2 => Engine::new_source(440),
SteamApp::L4D => Engine::new_source(500),
SteamApp::L4D2 => Engine::new_source(550),
SteamApp::ALIENS => Engine::new_source(630),
SteamApp::CSGO => Engine::new_source(730),
SteamApp::TS => Engine::new_source(2400),
SteamApp::GM => Engine::new_source(4000),
SteamApp::AOC => Engine::new_source(17510),
SteamApp::INSMIC => Engine::new_source(17700),
SteamApp::ARMA2OA => Engine::new_source(33930),
SteamApp::PZ => Engine::new_source(108600),
SteamApp::INS => Engine::new_source(222880),
SteamApp::SC => Engine::GoldSrc(false), //225840
SteamApp::SDTD => Engine::new_source(251570),
SteamApp::RUST => Engine::new_source(252490),
SteamApp::BO => Engine::new_source(296300),
SteamApp::DST => Engine::new_source(322320),
SteamApp::BB2 => Engine::new_source(346330),
SteamApp::CCURE => Engine::new_source(355180),
SteamApp::BM => Engine::new_source(362890),
SteamApp::COSU => Engine::new_source(366090),
SteamApp::AVORION => Engine::new_source(445220),
SteamApp::DOI => Engine::new_source(447820),
SteamApp::TF => Engine::new_source(556450),
SteamApp::UNTURNED => Engine::new_source(304930),
SteamApp::ASE => Engine::new_source(346110),
SteamApp::BAT1944 => Engine::new_source(489940),
SteamApp::INSS => Engine::new_source(581320),
SteamApp::ASRD => Engine::new_source(563560),
SteamApp::ROR2 => Engine::new_source(632360),
SteamApp::OHD => Engine::new_source_with_dedicated(736590, 950900),
SteamApp::ONSET => Engine::new_source(1105810)
} }
} }
} }
/// App type. /// Engine type.
#[derive(PartialEq, Clone)] #[derive(PartialEq, Clone)]
pub enum App { pub enum Engine {
/// A Source game, the argument represents the wanted response steam app id, if its **None**, /// A Source game, the argument represents the possible steam app ids, if its **None**, let
/// let the query find it, if its **Some**, the query fails if the response id is not the /// the query find it, if its **Some**, the query fails if the response id is not the first
/// specified one. /// one, which is the game app id, or the other one, which is the dedicated server app id.
Source(Option<u32>), Source(Option<(u32, Option<u32>)>),
/// A GoldSrc game, the argument indicates whether to enforce getting the obsolete A2S_INFO /// A GoldSrc game, the argument indicates whether to enforce
/// goldsrc response or not. /// requesting the obsolete A2S_INFO response or not.
GoldSrc(bool) GoldSrc(bool)
} }
impl Engine {
pub fn new_source(appid: u32) -> Self {
Engine::Source(Some((appid, None)))
}
pub fn new_source_with_dedicated(appid: u32, dedicated_appid: u32) -> Self {
Engine::Source(Some((appid, Some(dedicated_appid))))
}
}
/// What data to gather, purely used only with the query function. /// What data to gather, purely used only with the query function.
pub struct GatheringSettings { pub struct GatheringSettings {
pub players: bool, pub players: bool,
@ -298,6 +345,8 @@ pub mod game {
pub map: String, pub map: String,
/// The name of the game. /// The name of the game.
pub game: String, pub game: String,
/// Server's app id.
pub appid: u32,
/// Number of players on the server. /// Number of players on the server.
pub players_online: u8, pub players_online: u8,
/// Details about the server's players (not all players necessarily). /// Details about the server's players (not all players necessarily).
@ -337,6 +386,7 @@ pub mod game {
name: response.info.name, name: response.info.name,
map: response.info.map, map: response.info.map,
game: response.info.game, game: response.info.game,
appid: response.info.appid,
players_online: response.info.players_online, players_online: response.info.players_online,
players_details: response.players.unwrap_or(vec![]).iter().map(Player::from_valve_response).collect(), players_details: response.players.unwrap_or(vec![]).iter().map(Player::from_valve_response).collect(),
players_maximum: response.info.players_maximum, players_maximum: response.info.players_maximum,