From 7b2cad22ec267547786cd2554aae056f9c359e12 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Sat, 26 Nov 2022 15:38:13 +0200 Subject: [PATCH] Unturned support. --- README.md | 4 ++-- examples/master_querant.rs | 3 ++- src/games/mod.rs | 2 ++ src/games/unturned.rs | 12 ++++++++++++ src/protocols/valve/protocol.rs | 2 +- src/protocols/valve/types.rs | 2 ++ 6 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/games/unturned.rs diff --git a/README.md b/README.md index 6f67b44..ecbf8a3 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ MSRV is `1.58.1` and the code is cross-platform. To see the supported (or the planned to support) games/services/protocols, see [GAMES](GAMES.md), [SERVICES](SERVICES.md) and [PROTOCOLS](PROTOCOLS.md) respectively. ## Usage -Just pick a game/service/protocol, provide the ip and the port (can be optional) then query on it. +Just pick a game/service/protocol, provide the ip and the port (can be optional) (some use a special query port) then query on it. Team Fortress 2 query example: ```rust use gamedig::games::tf2; @@ -26,7 +26,7 @@ fn main() { } } ``` -Response: +Response (note that some games have a different structure): ```json5 { protocol: 17, diff --git a/examples/master_querant.rs b/examples/master_querant.rs index 1190f6c..64d3d9b 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, tf2, ts}; +use gamedig::{aliens, ase, asrd, cscz, csgo, css, dod, dods, GDResult, gm, hl2dm, ins, insmic, inss, l4d, l4d2, mc, sdtd, tf2, ts, unturned}; use gamedig::protocols::minecraft::{LegacyGroup, Server}; use gamedig::protocols::valve; use gamedig::protocols::valve::App; @@ -49,6 +49,7 @@ fn main() -> GDResult<()> { "mc_legacy_v1_6" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::V1_6), ip, port)?), "7dtd" => println!("{:#?}", sdtd::query(ip, port)?), "ase" => println!("{:#?}", ase::query(ip, port)?), + "unturned" => println!("{:#?}", unturned::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 63189ee..31db2ab 100644 --- a/src/games/mod.rs +++ b/src/games/mod.rs @@ -39,3 +39,5 @@ pub mod mc; pub mod sdtd; /// ARK: Survival Evolved pub mod ase; +/// Unturned +pub mod unturned; diff --git a/src/games/unturned.rs b/src/games/unturned.rs new file mode 100644 index 0000000..4d9c9b9 --- /dev/null +++ b/src/games/unturned.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::UNTURNED.as_app(), None, None)?; + + Ok(game::Response::new_from_valve_response(valve_response)) +} diff --git a/src/protocols/valve/protocol.rs b/src/protocols/valve/protocol.rs index 238098f..dcae027 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 = 1600; +static PACKET_SIZE: usize = 4096; impl ValveProtocol { fn new(address: &str, port: u16, timeout_settings: Option) -> GDResult { diff --git a/src/protocols/valve/types.rs b/src/protocols/valve/types.rs index 42c50ad..408c728 100644 --- a/src/protocols/valve/types.rs +++ b/src/protocols/valve/types.rs @@ -175,6 +175,8 @@ pub enum SteamID { INS = 222880, /// 7 Days To Die SDTD = 251570, + /// Unturned + UNTURNED = 304930, /// ARK: Survival Evolved ASE = 346110, /// Insurgency: Sandstorm