From 83bbd5d428c488df339804a3432772621ffb1905 Mon Sep 17 00:00:00 2001 From: cosminperram Date: Sat, 22 Oct 2022 19:25:54 +0300 Subject: [PATCH] Added Insurgency and Insurgency: Sandstorm implementation. --- CHANGELOG.md | 2 + GAMES.md | 26 +++++++------ examples/ins.rs | 10 +++++ examples/inss.rs | 10 +++++ src/games/ins.rs | 83 ++++++++++++++++++++++++++++++++++++++++++ src/games/inss.rs | 83 ++++++++++++++++++++++++++++++++++++++++++ src/games/mod.rs | 4 ++ src/protocols/valve.rs | 4 ++ 8 files changed, 210 insertions(+), 12 deletions(-) create mode 100644 examples/ins.rs create mode 100644 examples/inss.rs create mode 100644 src/games/ins.rs create mode 100644 src/games/inss.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 5427d4c..e9188b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Who knows what the future holds... Queries now support DNS resolve. [Alien Swarm](https://store.steampowered.com/app/630/Alien_Swarm/) implementation. [Alien Swarm: Reactive Drop](https://store.steampowered.com/app/563560/Alien_Swarm_Reactive_Drop/) implementation. +[Insurgency](https://store.steampowered.com/app/222880/Insurgency/) implementation. +[Insurgency: Sandstorm](https://store.steampowered.com/app/581320/Insurgency_Sandstorm/) implementation. # 0.0.3 - 22/10/2022 Valve protocol now properly supports multi-packet responses (compressed ones not tested). diff --git a/GAMES.md b/GAMES.md index e5ce055..925aa2d 100644 --- a/GAMES.md +++ b/GAMES.md @@ -1,17 +1,19 @@ # Supported games: -| ID | Name | Protocol | Notes | -|--------|----------------------------------|----------------|------------------------------------------------------------------------------| -| TF2 | Team Fortress 2 | Valve Protocol | | -| TS | The Ship | Valve Protocol | | -| CSGO | Counter-Strike: Global Offensive | Valve Protocol | The server wouldn't respond the to Rules query since the 21 Feb 2014 update. | -| CSS | Counter-Strike: Source | Valve Protocol | If protocol is 7, queries with multi-packet responses will crash. | -| DODS | Day of Defeat: Source | Valve Protocol | | -| L4D | Left 4 Dead | Valve Protocol | | -| L4D2 | Left 4 Dead 2 | Valve Protocol | | -| HL2DM | Half-Life 2 Deathmatch | Valve Protocol | | -| ALIENS | Alien Swarm | Valve Protocol | Not tested. | -| ASRD | Alien Swarm: Reactive Drop | Valve Protocol | | +| ID | Name | Protocol | Notes | +|--------|-------------------------------------|----------------|------------------------------------------------------------------------------| +| TF2 | Team Fortress 2 | Valve Protocol | | +| TS | The Ship | Valve Protocol | | +| CSGO | Counter-Strike: Global Offensive | Valve Protocol | The server wouldn't respond the to Rules query since the 21 Feb 2014 update. | +| CSS | Counter-Strike: Source | Valve Protocol | If protocol is 7, queries with multi-packet responses will crash. | +| DODS | Day of Defeat: Source | Valve Protocol | | +| L4D | Left 4 Dead | Valve Protocol | | +| L4D2 | Left 4 Dead 2 | Valve Protocol | | +| HL2DM | Half-Life 2 Deathmatch | Valve Protocol | | +| ALIENS | Alien Swarm | Valve Protocol | Not tested. | +| ASRD | Alien Swarm: Reactive Drop | Valve Protocol | | +| INS | Insurgency | Valve Protocol | | +| INSS | Insurgency: Sandstorm | Valve Protocol | Here you need to use the query port, not the server port. | ## Planned to add support: All Valve titles. diff --git a/examples/ins.rs b/examples/ins.rs new file mode 100644 index 0000000..5eb9882 --- /dev/null +++ b/examples/ins.rs @@ -0,0 +1,10 @@ + +use gamedig::games::ins; + +fn main() { + let response = ins::query("101.100.139.94", Some(27016)); + match response { + Err(error) => println!("Couldn't query, error: {error}"), + Ok(r) => println!("{:?}", r) + } +} diff --git a/examples/inss.rs b/examples/inss.rs new file mode 100644 index 0000000..ce88c6e --- /dev/null +++ b/examples/inss.rs @@ -0,0 +1,10 @@ + +use gamedig::games::inss; + +fn main() { + let response = inss::query("109.195.19.160", None); //The query port, not the server port + match response { + Err(error) => println!("Couldn't query, error: {error}"), + Ok(r) => println!("{:?}", r) + } +} diff --git a/src/games/ins.rs b/src/games/ins.rs new file mode 100644 index 0000000..627ade8 --- /dev/null +++ b/src/games/ins.rs @@ -0,0 +1,83 @@ +use crate::{GDResult, valve}; +use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer}; + +#[derive(Debug)] +pub struct Player { + pub name: String, + pub score: u32, + pub duration: f32 +} + +impl Player { + fn from_valve_response(player: &ServerPlayer) -> Self { + Self { + name: player.name.clone(), + score: player.score, + duration: player.duration + } + } +} + +#[derive(Debug)] +pub struct Response { + pub protocol: u8, + pub name: String, + pub map: String, + pub game: String, + pub players: u8, + pub players_details: Vec, + pub max_players: u8, + pub bots: u8, + pub server_type: Server, + pub has_password: bool, + pub vac_secured: bool, + pub version: String, + pub port: Option, + pub steam_id: Option, + pub tv_port: Option, + pub tv_name: Option, + pub keywords: Option, + pub rules: Vec +} + +impl Response { + pub fn new_from_valve_response(response: valve::Response) -> Self { + let (port, steam_id, tv_port, tv_name, keywords) = match response.info.extra_data { + None => (None, None, None, None, None), + Some(ed) => (ed.port, ed.steam_id, ed.tv_port, ed.tv_name, ed.keywords) + }; + + Self { + protocol: response.info.protocol, + name: response.info.name, + map: response.info.map, + game: response.info.game, + players: response.info.players, + players_details: response.players.unwrap().iter().map(|p| Player::from_valve_response(p)).collect(), + max_players: response.info.max_players, + bots: response.info.bots, + server_type: response.info.server_type, + has_password: response.info.has_password, + vac_secured: response.info.vac_secured, + version: response.info.version, + port, + steam_id, + tv_port, + tv_name, + keywords, + rules: response.rules.unwrap() + } + } +} + +pub fn query(address: &str, port: Option) -> GDResult { + let valve_response = ValveProtocol::query(App::INS, address, match port { + None => 27015, + Some(port) => port + }, GatheringSettings { + players: true, + rules: true + })?; + + Ok(Response::new_from_valve_response(valve_response)) +} diff --git a/src/games/inss.rs b/src/games/inss.rs new file mode 100644 index 0000000..af844d3 --- /dev/null +++ b/src/games/inss.rs @@ -0,0 +1,83 @@ +use crate::{GDResult, valve}; +use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer}; + +#[derive(Debug)] +pub struct Player { + pub name: String, + pub score: u32, + pub duration: f32 +} + +impl Player { + fn from_valve_response(player: &ServerPlayer) -> Self { + Self { + name: player.name.clone(), + score: player.score, + duration: player.duration + } + } +} + +#[derive(Debug)] +pub struct Response { + pub protocol: u8, + pub name: String, + pub map: String, + pub game: String, + pub players: u8, + pub players_details: Vec, + pub max_players: u8, + pub bots: u8, + pub server_type: Server, + pub has_password: bool, + pub vac_secured: bool, + pub version: String, + pub port: Option, + pub steam_id: Option, + pub tv_port: Option, + pub tv_name: Option, + pub keywords: Option, + pub rules: Vec +} + +impl Response { + pub fn new_from_valve_response(response: valve::Response) -> Self { + let (port, steam_id, tv_port, tv_name, keywords) = match response.info.extra_data { + None => (None, None, None, None, None), + Some(ed) => (ed.port, ed.steam_id, ed.tv_port, ed.tv_name, ed.keywords) + }; + + Self { + protocol: response.info.protocol, + name: response.info.name, + map: response.info.map, + game: response.info.game, + players: response.info.players, + players_details: response.players.unwrap().iter().map(|p| Player::from_valve_response(p)).collect(), + max_players: response.info.max_players, + bots: response.info.bots, + server_type: response.info.server_type, + has_password: response.info.has_password, + vac_secured: response.info.vac_secured, + version: response.info.version, + port, + steam_id, + tv_port, + tv_name, + keywords, + rules: response.rules.unwrap() + } + } +} + +pub fn query(address: &str, port: Option) -> GDResult { + let valve_response = ValveProtocol::query(App::INSS, address, match port { + None => 27131, + Some(port) => port + }, GatheringSettings { + players: true, + rules: true + })?; + + Ok(Response::new_from_valve_response(valve_response)) +} diff --git a/src/games/mod.rs b/src/games/mod.rs index 82c677c..4dd9dcc 100644 --- a/src/games/mod.rs +++ b/src/games/mod.rs @@ -23,3 +23,7 @@ pub mod hl2dm; pub mod aliens; /// Alien Swarm: Reactive Drop pub mod asrd; +/// Insurgency +pub mod ins; +/// Insurgency: Sandstorm +pub mod inss; diff --git a/src/protocols/valve.rs b/src/protocols/valve.rs index fd2b98d..f36a07b 100644 --- a/src/protocols/valve.rs +++ b/src/protocols/valve.rs @@ -146,6 +146,10 @@ pub enum App { TS = 2400, /// Garry's Mod GM = 4000, + /// Insurgency + INS = 222880, + /// Insurgency: Sandstorm + INSS = 581320, /// Alien Swarm: Reactive Drop ASRD = 563560, }