7 Days To Die support.

This commit is contained in:
CosminPerRam 2022-11-25 20:10:16 +02:00
parent 2f640e93d5
commit e689bc766e
8 changed files with 38 additions and 20 deletions

View file

@ -2,7 +2,8 @@
Who knows what the future holds... Who knows what the future holds...
# 0.0.6 - ??/??/2022 # 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 # 0.0.5 - 15/11/2022
Added `SocketBind` error, regarding failing to bind a socket. Added `SocketBind` error, regarding failing to bind a socket.

View file

@ -1,5 +1,5 @@
# Supported games: # Supported services:
| ID | Name | Notes | | ID | Name | Notes |
|-----|------|-------| |-----|------|-------|
| --- | ---- | ----- | | --- | ---- | ----- |

View file

@ -1,6 +1,6 @@
use std::env; 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::minecraft::{LegacyGroup, Server};
use gamedig::protocols::valve; use gamedig::protocols::valve;
use gamedig::protocols::valve::App; 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_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_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)?), "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)?), "_src" => println!("{:#?}", valve::query(ip, 27015, App::Source(None), None, None)?),
"_gld" => println!("{:#?}", valve::query(ip, 27015, App::GoldSrc(false), 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)?), "_gld_f" => println!("{:#?}", valve::query(ip, 27015, App::GoldSrc(true), None, None)?),

View file

@ -35,3 +35,5 @@ pub mod cscz;
pub mod dod; pub mod dod;
/// Minecraft /// Minecraft
pub mod mc; pub mod mc;
/// 7 Days To Die
pub mod sdtd;

12
src/games/sdtd.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::GDResult;
use crate::protocols::valve;
use crate::protocols::valve::{game, SteamID};
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
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))
}

View file

@ -31,16 +31,16 @@ SOFTWARE.
use crate::{GDError, GDResult}; use crate::{GDError, GDResult};
use crate::utils::buffer::get_u8; 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)] #[derive(Debug)]
pub enum Server { pub enum Server {
/// Java Edition /// Java Edition.
Java, Java,
/// Legacy Java /// Legacy Java.
Legacy(LegacyGroup) Legacy(LegacyGroup)
} }
/// Legacy Java (Versions) Groups /// Legacy Java (Versions) Groups.
#[derive(Debug)] #[derive(Debug)]
pub enum LegacyGroup { pub enum LegacyGroup {
/// 1.6 /// 1.6
@ -51,35 +51,35 @@ pub enum LegacyGroup {
VB1_8 VB1_8
} }
/// Information about a player /// Information about a player.
#[derive(Debug)] #[derive(Debug)]
pub struct Player { pub struct Player {
pub name: String, pub name: String,
pub id: String pub id: String
} }
/// A query response /// A query response.
#[derive(Debug)] #[derive(Debug)]
pub struct Response { pub struct Response {
/// Version name, example: "1.19.2" /// Version name, example: "1.19.2".
pub version_name: String, pub version_name: String,
/// Version protocol, example: 760 (for 1.19.2) /// Version protocol, example: 760 (for 1.19.2).
pub version_protocol: i32, pub version_protocol: i32,
/// Number of server capacity /// Number of server capacity.
pub max_players: u32, pub max_players: u32,
/// Number of online players /// Number of online players.
pub online_players: u32, pub online_players: u32,
/// Some online players (can be missing) /// Some online players (can be missing).
pub sample_players: Option<Vec<Player>>, pub sample_players: Option<Vec<Player>>,
/// Server's description or MOTD /// Server's description or MOTD.
pub description: String, pub description: String,
/// The favicon (can be missing) /// The favicon (can be missing).
pub favicon: Option<String>, pub favicon: Option<String>,
/// Tells if the chat preview is enabled (can be missing) /// Tells if the chat preview is enabled (can be missing).
pub previews_chat: Option<bool>, pub previews_chat: Option<bool>,
/// Tells if secure chat is enforced (can be missing) /// Tells if secure chat is enforced (can be missing).
pub enforces_secure_chat: Option<bool>, pub enforces_secure_chat: Option<bool>,
/// Tell's the server type /// Tell's the server type.
pub server_type: Server pub server_type: Server
} }

View file

@ -143,7 +143,7 @@ struct ValveProtocol {
socket: UdpSocket socket: UdpSocket
} }
static PACKET_SIZE: usize = 1400; static PACKET_SIZE: usize = 1600;
impl ValveProtocol { impl ValveProtocol {
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> { fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {

View file

@ -173,6 +173,8 @@ pub enum SteamID {
INSMIC = 17700, INSMIC = 17700,
/// Insurgency /// Insurgency
INS = 222880, INS = 222880,
/// 7 Days To Die
SDTD = 251570,
/// Insurgency: Sandstorm /// Insurgency: Sandstorm
INSS = 581320, INSS = 581320,
/// Alien Swarm: Reactive Drop /// Alien Swarm: Reactive Drop