mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
[Crate] Enforce formatting in CI (#46)
* [CI] Check formatting * Format all files
This commit is contained in:
parent
a6279177bb
commit
b95b2abe0f
76 changed files with 251 additions and 170 deletions
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
|
|
@ -28,3 +28,10 @@ jobs:
|
|||
override: true
|
||||
- name: Run MSRV
|
||||
run: cargo build
|
||||
- name: Install nightly
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: rustfmt
|
||||
- name: Run formatting check
|
||||
run: cargo +nightly fmt --check --verbose
|
||||
|
|
|
|||
|
|
@ -1,8 +1,62 @@
|
|||
use gamedig::protocols::{gamespy, quake};
|
||||
use gamedig::protocols::minecraft::LegacyGroup;
|
||||
use gamedig::protocols::valve;
|
||||
use gamedig::protocols::valve::Engine;
|
||||
use gamedig::{aliens, aoc, arma2oa, ase, asrd, avorion, bat1944, bb2, bf1942, bm, bo, ccure, cosu, cs, cscz, csgo, css, dod, dods, doi, dst, ffow, gm, hl2dm, hldms, ins, insmic, inss, l4d, l4d2, mc, ohd, onset, pz, ror2, rust, sc, sdtd, ss, tf, tf2, tfc, ts, unturned, ut, vr, GDResult, cw, quake2, quake1, quake3a, hll, sof2};
|
||||
use gamedig::protocols::{gamespy, quake};
|
||||
use gamedig::{
|
||||
aliens,
|
||||
aoc,
|
||||
arma2oa,
|
||||
ase,
|
||||
asrd,
|
||||
avorion,
|
||||
bat1944,
|
||||
bb2,
|
||||
bf1942,
|
||||
bm,
|
||||
bo,
|
||||
ccure,
|
||||
cosu,
|
||||
cs,
|
||||
cscz,
|
||||
csgo,
|
||||
css,
|
||||
cw,
|
||||
dod,
|
||||
dods,
|
||||
doi,
|
||||
dst,
|
||||
ffow,
|
||||
gm,
|
||||
hl2dm,
|
||||
hldms,
|
||||
hll,
|
||||
ins,
|
||||
insmic,
|
||||
inss,
|
||||
l4d,
|
||||
l4d2,
|
||||
mc,
|
||||
ohd,
|
||||
onset,
|
||||
pz,
|
||||
quake1,
|
||||
quake2,
|
||||
quake3a,
|
||||
ror2,
|
||||
rust,
|
||||
sc,
|
||||
sdtd,
|
||||
sof2,
|
||||
ss,
|
||||
tf,
|
||||
tf2,
|
||||
tfc,
|
||||
ts,
|
||||
unturned,
|
||||
ut,
|
||||
vr,
|
||||
GDResult,
|
||||
};
|
||||
use std::env;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use gamedig::games::tf2;
|
|||
|
||||
fn main() {
|
||||
let response = tf2::query(&"127.0.0.1".parse().unwrap(), None);
|
||||
// or Some(27015), None is the default protocol port (which is 27015)
|
||||
// or Some(27015), None is the default protocol port (which is 27015)
|
||||
|
||||
match response {
|
||||
// Result type, must check what it is...
|
||||
|
|
|
|||
|
|
@ -108,13 +108,9 @@ impl Bufferer {
|
|||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn get_string_utf8(&mut self) -> GDResult<String> {
|
||||
self.get_string_utf8_until(0)
|
||||
}
|
||||
pub fn get_string_utf8(&mut self) -> GDResult<String> { self.get_string_utf8_until(0) }
|
||||
|
||||
pub fn get_string_utf8_newline(&mut self) -> GDResult<String> {
|
||||
self.get_string_utf8_until(10)
|
||||
}
|
||||
pub fn get_string_utf8_newline(&mut self) -> GDResult<String> { self.get_string_utf8_until(10) }
|
||||
|
||||
pub fn get_string_utf8_optional(&mut self) -> GDResult<String> {
|
||||
match self.get_string_utf8() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDError::TypeParse,
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let mut valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(&SocketAddr::new(*address, port.unwrap_or(23000)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::three::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::three::query(&SocketAddr::new(*address, port.unwrap_or(64100)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::protocols::valve::{Engine, Environment, Server, ValveProtocol};
|
||||
use crate::GDResult;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
/// The query response.
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
@ -47,8 +47,15 @@ pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
|||
query_with_timeout(address, port, TimeoutSettings::default())
|
||||
}
|
||||
|
||||
pub fn query_with_timeout(address: &IpAddr, port: Option<u16>, timeout_settings: TimeoutSettings) -> GDResult<Response> {
|
||||
let mut client = ValveProtocol::new(&SocketAddr::new(*address, port.unwrap_or(5478)), Some(timeout_settings))?;
|
||||
pub fn query_with_timeout(
|
||||
address: &IpAddr,
|
||||
port: Option<u16>,
|
||||
timeout_settings: TimeoutSettings,
|
||||
) -> GDResult<Response> {
|
||||
let mut client = ValveProtocol::new(
|
||||
&SocketAddr::new(*address, port.unwrap_or(5478)),
|
||||
Some(timeout_settings),
|
||||
)?;
|
||||
let mut buffer = client.get_request_data(
|
||||
&Engine::GoldSrc(true),
|
||||
0,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::minecraft::{self, BedrockResponse, JavaResponse, LegacyGroup},
|
||||
GDError,
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
/// Query with all the protocol variants one by one (Java -> Bedrock -> Legacy
|
||||
/// (1.6 -> 1.4 -> Beta 1.8)).
|
||||
|
|
@ -35,12 +35,19 @@ pub fn query_legacy(address: &IpAddr, port: Option<u16>) -> GDResult<JavaRespons
|
|||
|
||||
/// Query a specific (Java) Legacy Server.
|
||||
pub fn query_legacy_specific(group: LegacyGroup, address: &IpAddr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
minecraft::query_legacy_specific(group, &SocketAddr::new(*address, port_or_java_default(port)), None)
|
||||
minecraft::query_legacy_specific(
|
||||
group,
|
||||
&SocketAddr::new(*address, port_or_java_default(port)),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
/// Query a Bedrock Server.
|
||||
pub fn query_bedrock(address: &IpAddr, port: Option<u16>) -> GDResult<BedrockResponse> {
|
||||
minecraft::query_bedrock(&SocketAddr::new(*address, port_or_bedrock_default(port)), None)
|
||||
minecraft::query_bedrock(
|
||||
&SocketAddr::new(*address, port_or_bedrock_default(port)),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn port_or_java_default(port: Option<u16>) -> u16 { port.unwrap_or(25565) }
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ pub mod cscz;
|
|||
pub mod csgo;
|
||||
/// Counter-Strike: Source
|
||||
pub mod css;
|
||||
/// Crysis Wars
|
||||
pub mod cw;
|
||||
/// Day of Defeat
|
||||
pub mod dod;
|
||||
/// Day of Defeat: Source
|
||||
|
|
@ -50,6 +52,8 @@ pub mod gm;
|
|||
pub mod hl2dm;
|
||||
/// Half-Life Deathmatch: Source
|
||||
pub mod hldms;
|
||||
/// Hell Let Loose
|
||||
pub mod hll;
|
||||
/// Insurgency
|
||||
pub mod ins;
|
||||
/// Insurgency: Modern Infantry Combat
|
||||
|
|
@ -68,6 +72,12 @@ pub mod ohd;
|
|||
pub mod onset;
|
||||
/// Project Zomboid
|
||||
pub mod pz;
|
||||
/// Quake 1
|
||||
pub mod quake1;
|
||||
/// Quake 2
|
||||
pub mod quake2;
|
||||
/// Quake 3: Arena
|
||||
pub mod quake3a;
|
||||
/// Risk of Rain 2
|
||||
pub mod ror2;
|
||||
/// Rust
|
||||
|
|
@ -76,6 +86,8 @@ pub mod rust;
|
|||
pub mod sc;
|
||||
/// 7 Days To Die
|
||||
pub mod sdtd;
|
||||
/// Soldier of Fortune 2
|
||||
pub mod sof2;
|
||||
/// Serious Sam
|
||||
pub mod ss;
|
||||
/// The Forest
|
||||
|
|
@ -92,15 +104,3 @@ pub mod unturned;
|
|||
pub mod ut;
|
||||
/// V Rising
|
||||
pub mod vr;
|
||||
/// Crysis Wars
|
||||
pub mod cw;
|
||||
/// Quake 2
|
||||
pub mod quake2;
|
||||
/// Quake 1
|
||||
pub mod quake1;
|
||||
/// Quake 3: Arena
|
||||
pub mod quake3a;
|
||||
/// Hell Let Loose
|
||||
pub mod hll;
|
||||
/// Soldier of Fortune 2
|
||||
pub mod sof2;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::one::Player;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::one::query(&SocketAddr::new(*address, port.unwrap_or(27500)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::two::Player;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::two::query(&SocketAddr::new(*address, port.unwrap_or(27910)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::two::Player;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::three::query(&SocketAddr::new(*address, port.unwrap_or(27960)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::two::Player;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::three::query(&SocketAddr::new(*address, port.unwrap_or(20100)), None)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(&SocketAddr::new(*address, port.unwrap_or(25601)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(&SocketAddr::new(*address, port.unwrap_or(7778)), None)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
//! # Crate features:
|
||||
//! Enabled by default: None
|
||||
//!
|
||||
//! `serde` - enables json serialization/deserialization for all response types. <br>
|
||||
//! `no_games` - disables the included games support. <br>
|
||||
//! `serde` - enables json serialization/deserialization for all response types.
|
||||
//! <br> `no_games` - disables the included games support. <br>
|
||||
//! `no_services` - disables the included services support.
|
||||
|
||||
pub mod errors;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::protocols::gamespy::common::has_password;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -8,7 +9,6 @@ use crate::{
|
|||
GDError,
|
||||
GDResult,
|
||||
};
|
||||
use crate::protocols::gamespy::common::has_password;
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// This file has code that has been documented by the NodeJS GameDig library
|
||||
// (MIT) from https://github.com/gamedig/node-gamedig/blob/master/protocols/minecraftbedrock.js
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -13,6 +12,7 @@ use crate::{
|
|||
GDError::{PacketBad, TypeParse},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct Bedrock {
|
||||
socket: UdpSocket,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -9,6 +8,7 @@ use crate::{
|
|||
GDError::{JsonParse, PacketBad},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -10,6 +9,7 @@ use crate::{
|
|||
GDError::{PacketBad, ProtocolFormat},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct LegacyBV1_8 {
|
||||
socket: TcpSocket,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -10,6 +9,7 @@ use crate::{
|
|||
GDError::{PacketBad, ProtocolFormat},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct LegacyV1_4 {
|
||||
socket: TcpSocket,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -10,6 +9,7 @@ use crate::{
|
|||
GDError::{PacketBad, ProtocolFormat},
|
||||
GDResult,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct LegacyV1_6 {
|
||||
socket: TcpSocket,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
protocols::minecraft::{
|
||||
protocol::{
|
||||
|
|
@ -16,6 +15,7 @@ use crate::{
|
|||
GDError::AutoQuery,
|
||||
GDResult,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
mod bedrock;
|
||||
mod java;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
pub mod gamespy;
|
||||
/// Reference: [Server List Ping](https://wiki.vg/Server_List_Ping)
|
||||
pub mod minecraft;
|
||||
/// Reference: [node-GameDig](https://github.com/gamedig/node-gamedig/blob/master/protocols/quake1.js)
|
||||
pub mod quake;
|
||||
/// General types that are used by all protocols.
|
||||
pub mod types;
|
||||
/// Reference: [Server Query](https://developer.valvesoftware.com/wiki/Server_queries)
|
||||
pub mod valve;
|
||||
/// Reference: [node-GameDig](https://github.com/gamedig/node-gamedig/blob/master/protocols/quake1.js)
|
||||
pub mod quake;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::bufferer::{Bufferer, Endianess};
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::types::Response;
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::socket::{Socket, UdpSocket};
|
||||
use crate::{GDError, GDResult};
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
|
||||
pub(crate) trait QuakeClient {
|
||||
type Player;
|
||||
|
|
@ -15,11 +15,21 @@ pub(crate) trait QuakeClient {
|
|||
fn parse_player_string(data: Iter<&str>) -> GDResult<Self::Player>;
|
||||
}
|
||||
|
||||
fn get_data<Client: QuakeClient>(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Bufferer> {
|
||||
fn get_data<Client: QuakeClient>(
|
||||
address: &SocketAddr,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<Bufferer> {
|
||||
let mut socket = UdpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
socket.send(&[&[0xFF, 0xFF, 0xFF, 0xFF], Client::get_send_header().as_bytes(), &[0x00]].concat())?;
|
||||
socket.send(
|
||||
&[
|
||||
&[0xFF, 0xFF, 0xFF, 0xFF],
|
||||
Client::get_send_header().as_bytes(),
|
||||
&[0x00],
|
||||
]
|
||||
.concat(),
|
||||
)?;
|
||||
|
||||
let data = socket.receive(None)?;
|
||||
let mut bufferer = Bufferer::new_with_data(Endianess::Little, &data);
|
||||
|
|
@ -78,27 +88,34 @@ fn get_players<Client: QuakeClient>(bufferer: &mut Bufferer) -> GDResult<Vec<Cli
|
|||
Ok(players)
|
||||
}
|
||||
|
||||
pub(crate) fn client_query<Client: QuakeClient>(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Client::Player>> {
|
||||
pub(crate) fn client_query<Client: QuakeClient>(
|
||||
address: &SocketAddr,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<Response<Client::Player>> {
|
||||
let mut bufferer = get_data::<Client>(address, timeout_settings)?;
|
||||
|
||||
let mut server_vars = get_server_values(&mut bufferer)?;
|
||||
let players = get_players::<Client>(&mut bufferer)?;
|
||||
|
||||
Ok(Response {
|
||||
name: server_vars.remove("hostname")
|
||||
name: server_vars
|
||||
.remove("hostname")
|
||||
.or(server_vars.remove("sv_hostname"))
|
||||
.ok_or(GDError::PacketBad)?,
|
||||
map: server_vars.remove("mapname")
|
||||
map: server_vars
|
||||
.remove("mapname")
|
||||
.or(server_vars.remove("map"))
|
||||
.ok_or(GDError::PacketBad)?,
|
||||
players_online: players.len() as u8,
|
||||
players_maximum: server_vars.remove("maxclients")
|
||||
players_maximum: server_vars
|
||||
.remove("maxclients")
|
||||
.or(server_vars.remove("sv_maxclients"))
|
||||
.ok_or(GDError::PacketBad)?
|
||||
.parse()
|
||||
.map_err(|_| GDError::TypeParse)?,
|
||||
players,
|
||||
version: server_vars.remove("version")
|
||||
version: server_vars
|
||||
.remove("version")
|
||||
.or(server_vars.remove("*version"))
|
||||
.ok_or(GDError::PacketBad)?,
|
||||
unused_entries: server_vars,
|
||||
|
|
@ -108,6 +125,6 @@ pub(crate) fn client_query<Client: QuakeClient>(address: &SocketAddr, timeout_se
|
|||
pub(crate) fn remove_wrapping_quotes<'a>(string: &&'a str) -> &'a str {
|
||||
match string.starts_with('\"') && string.ends_with('\"') {
|
||||
false => string,
|
||||
true => &string[1..string.len() - 1]
|
||||
true => &string[1 .. string.len() - 1],
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
pub mod one;
|
||||
pub mod two;
|
||||
pub mod three;
|
||||
pub mod two;
|
||||
|
||||
/// All types used by the implementation.
|
||||
pub mod types;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::client::{client_query, remove_wrapping_quotes, QuakeClient};
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::client::{QuakeClient, client_query, remove_wrapping_quotes};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::{GDError, GDResult};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
|
||||
/// Quake 1 player data.
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
@ -19,54 +19,50 @@ pub struct Player {
|
|||
pub name: String,
|
||||
pub skin: String,
|
||||
pub color_primary: u8,
|
||||
pub color_secondary: u8
|
||||
pub color_secondary: u8,
|
||||
}
|
||||
|
||||
pub(crate) struct QuakeOne;
|
||||
impl QuakeClient for QuakeOne {
|
||||
type Player = Player;
|
||||
|
||||
fn get_send_header<'a>() -> &'a str {
|
||||
"status"
|
||||
}
|
||||
fn get_send_header<'a>() -> &'a str { "status" }
|
||||
|
||||
fn get_response_header<'a>() -> &'a str {
|
||||
"n"
|
||||
}
|
||||
fn get_response_header<'a>() -> &'a str { "n" }
|
||||
|
||||
fn parse_player_string(mut data: Iter<&str>) -> GDResult<Self::Player> {
|
||||
Ok(Player {
|
||||
id: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
score: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
time: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
ping: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
name: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => remove_wrapping_quotes(v).to_string()
|
||||
Some(v) => remove_wrapping_quotes(v).to_string(),
|
||||
},
|
||||
skin: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => remove_wrapping_quotes(v).to_string()
|
||||
Some(v) => remove_wrapping_quotes(v).to_string(),
|
||||
},
|
||||
color_primary: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
color_secondary: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,20 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake::client::{client_query, QuakeClient};
|
||||
use crate::protocols::quake::two::{Player, QuakeTwo};
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::client::{QuakeClient, client_query};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::GDResult;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
|
||||
struct QuakeThree;
|
||||
impl QuakeClient for QuakeThree {
|
||||
type Player = Player;
|
||||
|
||||
fn get_send_header<'a>() -> &'a str {
|
||||
"getstatus"
|
||||
}
|
||||
fn get_send_header<'a>() -> &'a str { "getstatus" }
|
||||
|
||||
fn get_response_header<'a>() -> &'a str {
|
||||
"statusResponse\n"
|
||||
}
|
||||
fn get_response_header<'a>() -> &'a str { "statusResponse\n" }
|
||||
|
||||
fn parse_player_string(data: Iter<&str>) -> GDResult<Self::Player> {
|
||||
QuakeTwo::parse_player_string(data)
|
||||
}
|
||||
fn parse_player_string(data: Iter<&str>) -> GDResult<Self::Player> { QuakeTwo::parse_player_string(data) }
|
||||
}
|
||||
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::client::{client_query, remove_wrapping_quotes, QuakeClient};
|
||||
use crate::protocols::quake::one::QuakeOne;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::client::{QuakeClient, client_query, remove_wrapping_quotes};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::{GDError, GDResult};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
|
||||
/// Quake 2 player data.
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
@ -14,35 +14,31 @@ use serde::{Deserialize, Serialize};
|
|||
pub struct Player {
|
||||
pub frags: i16,
|
||||
pub ping: u16,
|
||||
pub name: String
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub(crate) struct QuakeTwo;
|
||||
impl QuakeClient for QuakeTwo {
|
||||
type Player = Player;
|
||||
|
||||
fn get_send_header<'a>() -> &'a str {
|
||||
QuakeOne::get_send_header()
|
||||
}
|
||||
fn get_send_header<'a>() -> &'a str { QuakeOne::get_send_header() }
|
||||
|
||||
fn get_response_header<'a>() -> &'a str {
|
||||
"print\n"
|
||||
}
|
||||
fn get_response_header<'a>() -> &'a str { "print\n" }
|
||||
|
||||
fn parse_player_string(mut data: Iter<&str>) -> GDResult<Self::Player> {
|
||||
Ok(Player {
|
||||
frags: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
ping: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?
|
||||
Some(v) => v.parse().map_err(|_| GDError::PacketBad)?,
|
||||
},
|
||||
name: match data.next() {
|
||||
None => Err(GDError::PacketBad)?,
|
||||
Some(v) => remove_wrapping_quotes(v).to_string()
|
||||
}
|
||||
Some(v) => remove_wrapping_quotes(v).to_string(),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// General server information's.
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
|
|||
|
|
@ -418,12 +418,7 @@ pub fn query(
|
|||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<Response> {
|
||||
let response_gather_settings = gather_settings.unwrap_or_default();
|
||||
get_response(
|
||||
address,
|
||||
engine,
|
||||
response_gather_settings,
|
||||
timeout_settings,
|
||||
)
|
||||
get_response(address, engine, response_gather_settings, timeout_settings)
|
||||
}
|
||||
|
||||
fn get_response(
|
||||
|
|
|
|||
|
|
@ -71,7 +71,12 @@ impl ValveMasterServer {
|
|||
|
||||
let mut ips: Vec<(IpAddr, u16)> = Vec::new();
|
||||
while buf.remaining_length() > 0 {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(buf.get_u8()?, buf.get_u8()?, buf.get_u8()?, buf.get_u8()?));
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(
|
||||
buf.get_u8()?,
|
||||
buf.get_u8()?,
|
||||
buf.get_u8()?,
|
||||
buf.get_u8()?,
|
||||
));
|
||||
let port = buf.get_u16()?;
|
||||
|
||||
ips.push((ip, port));
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ pub enum Filter {
|
|||
HasTags(Vec<String>),
|
||||
MatchName(String),
|
||||
MatchVersion(String),
|
||||
/// Restrict to only a server if an IP hosts (on different ports) multiple servers.
|
||||
/// Restrict to only a server if an IP hosts (on different ports) multiple
|
||||
/// servers.
|
||||
RestrictUniqueIP(bool),
|
||||
/// Query for servers on a specific address.
|
||||
OnAddress(String),
|
||||
|
|
@ -133,7 +134,8 @@ impl Filter {
|
|||
/// .insert(Filter::IsEmpty(false))
|
||||
/// .insert(Filter::CanHavePassword(false));
|
||||
/// ```
|
||||
/// This will construct filters that search for servers that can't have a password, are not empty and run App ID 440.
|
||||
/// This will construct filters that search for servers that can't have a
|
||||
/// password, are not empty and run App ID 440.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SearchFilters {
|
||||
filters: HashMap<Discriminant<Filter>, Filter>,
|
||||
|
|
@ -208,8 +210,14 @@ impl SearchFilters {
|
|||
bytes.extend(filter.to_bytes())
|
||||
}
|
||||
|
||||
bytes.extend(SearchFilters::special_filter_to_bytes("nand", &self.nand_filters));
|
||||
bytes.extend(SearchFilters::special_filter_to_bytes("nor", &self.nor_filters));
|
||||
bytes.extend(SearchFilters::special_filter_to_bytes(
|
||||
"nand",
|
||||
&self.nand_filters,
|
||||
));
|
||||
bytes.extend(SearchFilters::special_filter_to_bytes(
|
||||
"nor",
|
||||
&self.nor_filters,
|
||||
));
|
||||
|
||||
bytes.extend([0x00]);
|
||||
bytes
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ use crate::{
|
|||
GDResult,
|
||||
};
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
net,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
const DEFAULT_PACKET_SIZE: usize = 1024;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue