Unturned support.

This commit is contained in:
CosminPerRam 2022-11-26 15:38:13 +02:00
parent 999998f309
commit 7b2cad22ec
6 changed files with 21 additions and 4 deletions

View file

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

View file

@ -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)?),

View file

@ -39,3 +39,5 @@ pub mod mc;
pub mod sdtd;
/// ARK: Survival Evolved
pub mod ase;
/// Unturned
pub mod unturned;

12
src/games/unturned.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 => 27015,
Some(port) => port
}, SteamID::UNTURNED.as_app(), None, None)?;
Ok(game::Response::new_from_valve_response(valve_response))
}

View file

@ -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<TimeoutSettings>) -> GDResult<Self> {

View file

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