From 259e21a4abe20c1f2e65f95efdfa3e5cc69c7526 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Mon, 28 Nov 2022 00:51:09 +0200 Subject: [PATCH] Restored full CSGO query capabilities --- CHANGELOG.md | 2 +- GAMES.md | 54 +++++++++++++++--------------- src/games/csgo.rs | 59 +++------------------------------ src/protocols/valve/protocol.rs | 6 +--- src/protocols/valve/types.rs | 4 +-- 5 files changed, 35 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d3fcdc..5b2a72a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ Who knows what the future holds... [Counter-Strike](https://store.steampowered.com/app/10/CounterStrike/) support. [Arma 2: Operation Arrowhead](https://store.steampowered.com/app/33930/Arma_2_Operation_Arrowhead/) support. Tested `Alien Swarm` and `Insurgency: Modern Infantry Combat` and they work. -Increased Valve Protocol `PACKET_SIZE` from 1400 to 4096, some games send larger packets than the specified protocol size. +Increased Valve Protocol `PACKET_SIZE` from 1400 to 6144, some games send larger packets than the specified protocol size. # 0.0.5 - 15/11/2022 Added `SocketBind` error, regarding failing to bind a socket. diff --git a/GAMES.md b/GAMES.md index d95782b..ab3131c 100644 --- a/GAMES.md +++ b/GAMES.md @@ -1,33 +1,33 @@ A supported game is defined as a game that has been successfully tested, other games that use the implemented protocols might work too, but it isn't guaranteed. # Supported games: -| Game | Use name | Protocol | Notes | -|------------------------------------|----------|---------------------------|------------------------------------------------------------------------------| -| Team Fortress 2 | TF2 | Valve Protocol | | -| The Ship | TS | Valve Protocol (*Altered) | | -| Counter-Strike: Global Offensive | CSGO | Valve Protocol | The server wouldn't respond the to Rules query since the 21 Feb 2014 update. | -| Counter-Strike: Source | CSS | Valve Protocol | | -| Day of Defeat: Source | DODS | Valve Protocol | | -| Left 4 Dead | L4D | Valve Protocol | | -| Left 4 Dead 2 | L4D2 | Valve Protocol | | -| Half-Life 2 Deathmatch | HL2DM | Valve Protocol | | -| Alien Swarm | ALIENS | Valve Protocol | | -| Alien Swarm: Reactive Drop | ASRD | Valve Protocol | | -| Insurgency | INS | Valve Protocol | | -| Insurgency: Sandstorm | INSS | Valve Protocol | Use the query port. | -| Insurgency: Modern Infantry Combat | INSMIC | Valve Protocol | | -| Counter-Strike: Condition Zero | CSCZ | Valve Protocol (GoldSrc) | | -| Day of Defeat | DOD | Valve Protocol (GoldSrc) | | -| Minecraft | MC | Proprietary | Bedrock not supported yet. | -| 7 Days To Die | SDTD | Valve Protocol | | -| ARK: Survival Evolved | ASE | Valve Protocol | | -| Unturned | UNTURNED | Valve Protocol | | -| The Forest | TF | Valve Protocol (GoldSrc) | Use the query port. | -| Team Fortress Classic | TFC | Valve Protocol | | -| Sven Co-op | SC | Valve Protocol (GoldSrc) | | -| Rust | RUST | Valve Protocol | | -| Counter-Strike | CS | Valve Protocol (GoldSrc) | | -| Arma 2: Operation Arrowhead | ARMA2OA | Valve Protocol | Use the query port. | +| Game | Use name | Protocol | Notes | +|------------------------------------|----------|---------------------------|-------------------------------------------------------------------------------------------| +| Team Fortress 2 | TF2 | Valve Protocol | | +| The Ship | TS | Valve Protocol (*Altered) | | +| Counter-Strike: Global Offensive | CSGO | Valve Protocol | The server must have the cvar `host_players_show` set to `2` to get the full player list. | +| Counter-Strike: Source | CSS | Valve Protocol | | +| Day of Defeat: Source | DODS | Valve Protocol | | +| Left 4 Dead | L4D | Valve Protocol | | +| Left 4 Dead 2 | L4D2 | Valve Protocol | | +| Half-Life 2 Deathmatch | HL2DM | Valve Protocol | | +| Alien Swarm | ALIENS | Valve Protocol | | +| Alien Swarm: Reactive Drop | ASRD | Valve Protocol | | +| Insurgency | INS | Valve Protocol | | +| Insurgency: Sandstorm | INSS | Valve Protocol | Use the query port. | +| Insurgency: Modern Infantry Combat | INSMIC | Valve Protocol | | +| Counter-Strike: Condition Zero | CSCZ | Valve Protocol (GoldSrc) | | +| Day of Defeat | DOD | Valve Protocol (GoldSrc) | | +| Minecraft | MC | Proprietary | Bedrock not supported yet. | +| 7 Days To Die | SDTD | Valve Protocol | | +| ARK: Survival Evolved | ASE | Valve Protocol | | +| Unturned | UNTURNED | Valve Protocol | | +| The Forest | TF | Valve Protocol (GoldSrc) | Use the query port. | +| Team Fortress Classic | TFC | Valve Protocol | | +| Sven Co-op | SC | Valve Protocol (GoldSrc) | | +| Rust | RUST | Valve Protocol | | +| Counter-Strike | CS | Valve Protocol (GoldSrc) | | +| Arma 2: Operation Arrowhead | ARMA2OA | Valve Protocol | Use the query port. | ## Planned to add support: _ diff --git a/src/games/csgo.rs b/src/games/csgo.rs index 2ad965e..3786606 100644 --- a/src/games/csgo.rs +++ b/src/games/csgo.rs @@ -1,63 +1,12 @@ use crate::GDResult; use crate::protocols::valve; -use crate::protocols::valve::{Server, GatheringSettings, get_optional_extracted_data, SteamID}; -use crate::protocols::valve::game::Player; +use crate::protocols::valve::{game, SteamID}; -#[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 -} - -impl Response { - pub fn new_from_valve_response(response: valve::Response) -> Self { - let (port, steam_id, tv_port, tv_name, keywords) = get_optional_extracted_data(response.info.extra_data); - - 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 - } - } -} - -pub fn query(address: &str, port: Option) -> GDResult { +pub fn query(address: &str, port: Option) -> GDResult { let valve_response = valve::query(address, match port { None => 27015, Some(port) => port - }, SteamID::CSGO.as_app(), Some(GatheringSettings { - players: true, - rules: false // cause csgo doesnt reply with rules anymore - }), None)?; + }, SteamID::CSGO.as_app(), None, None)?; - Ok(Response::new_from_valve_response(valve_response)) + Ok(game::Response::new_from_valve_response(valve_response)) } diff --git a/src/protocols/valve/protocol.rs b/src/protocols/valve/protocol.rs index dcae027..c1985ba 100644 --- a/src/protocols/valve/protocol.rs +++ b/src/protocols/valve/protocol.rs @@ -143,7 +143,7 @@ struct ValveProtocol { socket: UdpSocket } -static PACKET_SIZE: usize = 4096; +static PACKET_SIZE: usize = 6144; impl ValveProtocol { fn new(address: &str, port: u16, timeout_settings: Option) -> GDResult { @@ -383,10 +383,6 @@ impl ValveProtocol { /// Get the server rules's. fn get_server_rules(&mut self, app: &App, protocol: u8) -> GDResult>> { - if *app == SteamID::CSGO.as_app() { //cause csgo wont respond to this since feb 21 2014 update - return Ok(None); - } - let buf = self.get_request_data(&app, protocol, Request::RULES)?; let mut pos = 0; diff --git a/src/protocols/valve/types.rs b/src/protocols/valve/types.rs index 45355b2..cca0341 100644 --- a/src/protocols/valve/types.rs +++ b/src/protocols/valve/types.rs @@ -290,7 +290,7 @@ pub mod game { 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(), + players_details: response.players.unwrap_or(vec![]).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, @@ -302,7 +302,7 @@ pub mod game { tv_port, tv_name, keywords, - rules: response.rules.unwrap() + rules: response.rules.unwrap_or(vec![]) } } }