From e689bc766e4a5544adbe37426cdeb17792220266 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Fri, 25 Nov 2022 20:10:16 +0200 Subject: [PATCH] 7 Days To Die support. --- CHANGELOG.md | 3 ++- SERVICES.md | 2 +- examples/master_querant.rs | 3 ++- src/games/mod.rs | 2 ++ src/games/sdtd.rs | 12 ++++++++++++ src/protocols/minecraft/types.rs | 32 ++++++++++++++++---------------- src/protocols/valve/protocol.rs | 2 +- src/protocols/valve/types.rs | 2 ++ 8 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 src/games/sdtd.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index c1fe3c3..9d98442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ Who knows what the future holds... # 0.0.6 - ??/??/2022 -[Minecraft](https://www.minecraft.com) implementation (bedrock not supported yet). +[Minecraft](https://www.minecraft.com) implementation (bedrock not supported yet). +[7 Days To Die](https://store.steampowered.com/app/251570/7_Days_to_Die/) implementation. # 0.0.5 - 15/11/2022 Added `SocketBind` error, regarding failing to bind a socket. diff --git a/SERVICES.md b/SERVICES.md index 38f4669..c1033d2 100644 --- a/SERVICES.md +++ b/SERVICES.md @@ -1,5 +1,5 @@ -# Supported games: +# Supported services: | ID | Name | Notes | |-----|------|-------| | --- | ---- | ----- | diff --git a/examples/master_querant.rs b/examples/master_querant.rs index 0992fa1..cb6bd4e 100644 --- a/examples/master_querant.rs +++ b/examples/master_querant.rs @@ -1,6 +1,6 @@ use std::env; -use gamedig::{aliens, asrd, cscz, csgo, css, dod, dods, GDResult, gm, hl2dm, ins, insmic, inss, l4d, l4d2, mc, tf2, ts}; +use gamedig::{aliens, asrd, cscz, csgo, css, dod, dods, GDResult, gm, hl2dm, ins, insmic, inss, l4d, l4d2, mc, sdtd, tf2, ts}; use gamedig::protocols::minecraft::{LegacyGroup, Server}; use gamedig::protocols::valve; use gamedig::protocols::valve::App; @@ -47,6 +47,7 @@ fn main() -> GDResult<()> { "mc_legacy_vb1_8" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::VB1_8), ip, port)?), "mc_legacy_v1_4" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::V1_4), ip, port)?), "mc_legacy_v1_6" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::V1_6), ip, port)?), + "7dtd" => println!("{:#?}", sdtd::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 6bee154..5fe9863 100644 --- a/src/games/mod.rs +++ b/src/games/mod.rs @@ -35,3 +35,5 @@ pub mod cscz; pub mod dod; /// Minecraft pub mod mc; +/// 7 Days To Die +pub mod sdtd; diff --git a/src/games/sdtd.rs b/src/games/sdtd.rs new file mode 100644 index 0000000..7ca1ec6 --- /dev/null +++ b/src/games/sdtd.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 => 26900, + Some(port) => port + }, SteamID::SDTD.as_app(), None, None)?; + + Ok(game::Response::new_from_valve_response(valve_response)) +} diff --git a/src/protocols/minecraft/types.rs b/src/protocols/minecraft/types.rs index 60d17b0..46cfa0c 100644 --- a/src/protocols/minecraft/types.rs +++ b/src/protocols/minecraft/types.rs @@ -31,16 +31,16 @@ SOFTWARE. use crate::{GDError, GDResult}; use crate::utils::buffer::get_u8; -/// The type of Minecraft Server you want to query +/// The type of Minecraft Server you want to query. #[derive(Debug)] pub enum Server { - /// Java Edition + /// Java Edition. Java, - /// Legacy Java + /// Legacy Java. Legacy(LegacyGroup) } -/// Legacy Java (Versions) Groups +/// Legacy Java (Versions) Groups. #[derive(Debug)] pub enum LegacyGroup { /// 1.6 @@ -51,35 +51,35 @@ pub enum LegacyGroup { VB1_8 } -/// Information about a player +/// Information about a player. #[derive(Debug)] pub struct Player { pub name: String, pub id: String } -/// A query response +/// A query response. #[derive(Debug)] pub struct Response { - /// Version name, example: "1.19.2" + /// Version name, example: "1.19.2". pub version_name: String, - /// Version protocol, example: 760 (for 1.19.2) + /// Version protocol, example: 760 (for 1.19.2). pub version_protocol: i32, - /// Number of server capacity + /// Number of server capacity. pub max_players: u32, - /// Number of online players + /// Number of online players. pub online_players: u32, - /// Some online players (can be missing) + /// Some online players (can be missing). pub sample_players: Option>, - /// Server's description or MOTD + /// Server's description or MOTD. pub description: String, - /// The favicon (can be missing) + /// The favicon (can be missing). pub favicon: Option, - /// Tells if the chat preview is enabled (can be missing) + /// Tells if the chat preview is enabled (can be missing). pub previews_chat: Option, - /// Tells if secure chat is enforced (can be missing) + /// Tells if secure chat is enforced (can be missing). pub enforces_secure_chat: Option, - /// Tell's the server type + /// Tell's the server type. pub server_type: Server } diff --git a/src/protocols/valve/protocol.rs b/src/protocols/valve/protocol.rs index a3990fc..238098f 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 = 1400; +static PACKET_SIZE: usize = 1600; 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 158f3e6..b9fb839 100644 --- a/src/protocols/valve/types.rs +++ b/src/protocols/valve/types.rs @@ -173,6 +173,8 @@ pub enum SteamID { INSMIC = 17700, /// Insurgency INS = 222880, + /// 7 Days To Die + SDTD = 251570, /// Insurgency: Sandstorm INSS = 581320, /// Alien Swarm: Reactive Drop