From d086d49cdc488e316945dab85ca0e98d1ab42654 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Sat, 26 Nov 2022 16:15:01 +0200 Subject: [PATCH] Team Fortress Classic support. --- CHANGELOG.md | 1 + GAMES.md | 1 + examples/master_querant.rs | 3 ++- src/games/mod.rs | 2 ++ src/games/tfc.rs | 12 ++++++++++++ src/protocols/valve/types.rs | 4 +++- 6 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/games/tfc.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index b94f5e7..a238bf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Who knows what the future holds... [ARK: Survival Evolved](https://store.steampowered.com/app/346110/ARK_Survival_Evolved/) support. [Unturned](https://store.steampowered.com/app/304930/Unturned/) support. [The Forest](https://store.steampowered.com/app/242760/The_Forest/) support. +[Team Fortress Classic](https://store.steampowered.com/app/20/Team_Fortress_Classic/) support. # 0.0.5 - 15/11/2022 Added `SocketBind` error, regarding failing to bind a socket. diff --git a/GAMES.md b/GAMES.md index 73a222e..52cfdb4 100644 --- a/GAMES.md +++ b/GAMES.md @@ -22,6 +22,7 @@ | ASE | ARK: Survival Evolved | Valve Protocol | | | UNTURNED | Unturned | Valve Protocol | | | TF | The Forest | Valve Protocol | Use the query port. | +| TFC | Team Fortress Classic | Valve Protocol | | ## Planned to add support: _ diff --git a/examples/master_querant.rs b/examples/master_querant.rs index 62b4d57..c1a5c9d 100644 --- a/examples/master_querant.rs +++ b/examples/master_querant.rs @@ -1,6 +1,6 @@ use std::env; -use gamedig::{aliens, ase, asrd, cscz, csgo, css, dod, dods, GDResult, gm, hl2dm, ins, insmic, inss, l4d, l4d2, mc, sdtd, tf, tf2, ts, unturned}; +use gamedig::{aliens, ase, asrd, cscz, csgo, css, dod, dods, GDResult, gm, hl2dm, ins, insmic, inss, l4d, l4d2, mc, sdtd, tf, tf2, tfc, ts, unturned}; use gamedig::protocols::minecraft::{LegacyGroup, Server}; use gamedig::protocols::valve; use gamedig::protocols::valve::App; @@ -51,6 +51,7 @@ fn main() -> GDResult<()> { "ase" => println!("{:#?}", ase::query(ip, port)?), "unturned" => println!("{:#?}", unturned::query(ip, port)?), "tf" => println!("{:#?}", tf::query(ip, port)?), + "tfc" => println!("{:#?}", tfc::query(ip, port)?), "_src" => println!("{:#?}", valve::query(ip, 27015, App::Source(None), None, None)?), "_gld" => println!("{:#?}", valve::query(ip, 27015, App::GoldSrc(false), None, None)?), "_gld_f" => println!("{:#?}", valve::query(ip, 27015, App::GoldSrc(true), None, None)?), diff --git a/src/games/mod.rs b/src/games/mod.rs index 7f60cc8..3e41830 100644 --- a/src/games/mod.rs +++ b/src/games/mod.rs @@ -43,3 +43,5 @@ pub mod ase; pub mod unturned; /// The Forest pub mod tf; +/// Team Fortress Classic +pub mod tfc; diff --git a/src/games/tfc.rs b/src/games/tfc.rs new file mode 100644 index 0000000..aa8eef2 --- /dev/null +++ b/src/games/tfc.rs @@ -0,0 +1,12 @@ +use crate::GDResult; +use crate::protocols::valve; +use crate::protocols::valve::{game, SteamID}; + +pub fn query(address: &str, port: Option) -> GDResult { + let valve_response = valve::query(address, match port { + None => 27015, + Some(port) => port + }, SteamID::TFC.as_app(), None, None)?; + + Ok(game::Response::new_from_valve_response(valve_response)) +} diff --git a/src/protocols/valve/types.rs b/src/protocols/valve/types.rs index 76e3367..4757fbb 100644 --- a/src/protocols/valve/types.rs +++ b/src/protocols/valve/types.rs @@ -145,6 +145,8 @@ pub enum Request { #[repr(u32)] #[derive(PartialEq, Clone)] pub enum SteamID { + /// Team Fortress Classic + TFC = 20, /// Day of Defeat DOD = 30, /// Counter-Strike: Condition Zero @@ -191,7 +193,7 @@ impl SteamID { /// Get ID as App (the engine is specified). pub fn as_app(&self) -> App { match self { - SteamID::CSCZ | SteamID::DOD => App::GoldSrc(false), + SteamID::TFC | SteamID::DOD | SteamID::CSCZ => App::GoldSrc(false), x => App::Source(Some(x.clone() as u32)) } }