Added Insurgency and Insurgency: Sandstorm implementation.

This commit is contained in:
cosminperram 2022-10-22 19:25:54 +03:00
parent 14abf3d1ab
commit 83bbd5d428
8 changed files with 210 additions and 12 deletions

View file

@ -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).

View file

@ -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.

10
examples/ins.rs Normal file
View file

@ -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)
}
}

10
examples/inss.rs Normal file
View file

@ -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)
}
}

83
src/games/ins.rs Normal file
View file

@ -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<Player>,
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<u16>,
pub steam_id: Option<u64>,
pub tv_port: Option<u16>,
pub tv_name: Option<String>,
pub keywords: Option<String>,
pub rules: Vec<ServerRule>
}
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<u16>) -> GDResult<Response> {
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))
}

83
src/games/inss.rs Normal file
View file

@ -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<Player>,
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<u16>,
pub steam_id: Option<u64>,
pub tv_port: Option<u16>,
pub tv_name: Option<String>,
pub keywords: Option<String>,
pub rules: Vec<ServerRule>
}
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<u16>) -> GDResult<Response> {
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))
}

View file

@ -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;

View file

@ -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,
}