mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 07:17:27 +00:00
[Crate] Changed all address &str to &Ipv4Addr
This commit is contained in:
parent
a69896f737
commit
e620398615
65 changed files with 171 additions and 93 deletions
|
|
@ -7,6 +7,8 @@ Protocols:
|
|||
1. Added standard and serde derives to `GatheringSettings`.
|
||||
|
||||
### Breaking:
|
||||
- Every function that used `address: &str` has been changed to `address: &Ipv4Addr`.
|
||||
|
||||
Services:
|
||||
- Valve Master Query:
|
||||
1. Removed Filter and SearchFilters lifetimes and changed `&'a str` to `String` and `&'a [&'a str]` to `Vec<String>`
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ Pick a game/service/protocol (check the [GAMES](GAMES.md), [SERVICES](SERVICES.m
|
|||
use gamedig::games::tf2;
|
||||
|
||||
fn main() {
|
||||
let response = tf2::query("127.0.0.1", None); // None is the default port (which is 27015), could also be Some(27015)
|
||||
let response = tf2::query(&"127.0.0.1".parse().unwrap(), None);
|
||||
// None is the default port (which is 27015), could also be Some(27015)
|
||||
|
||||
match response { // Result type, must check what it is...
|
||||
Err(error) => println!("Couldn't query, error: {}", error),
|
||||
Ok(r) => println!("{:#?}", r)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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};
|
||||
use std::env;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
fn main() -> GDResult<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
|
@ -19,7 +20,7 @@ fn main() -> GDResult<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let ip = args[2].as_str();
|
||||
let ip = &args[2].as_str().parse::<Ipv4Addr>().unwrap();
|
||||
let port = match args.len() == 4 {
|
||||
false => {
|
||||
if args[1].starts_with("_") {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use gamedig::games::mc;
|
|||
fn main() {
|
||||
// or Some(<port>), None is the default protocol port (which is 25565 for java
|
||||
// and 19132 for bedrock)
|
||||
let response = mc::query("127.0.0.1", None);
|
||||
let response = mc::query(&"127.0.0.1".parse().unwrap(), None);
|
||||
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {}", error),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use gamedig::games::tf2;
|
||||
|
||||
fn main() {
|
||||
let response = tf2::query("127.0.0.1", None); // or Some(27015), None is the default protocol port (which is 27015)
|
||||
let response = tf2::query(&"127.0.0.1".parse().unwrap(), None);
|
||||
// or Some(27015), None is the default protocol port (which is 27015)
|
||||
|
||||
match response {
|
||||
// Result type, must check what it is...
|
||||
Err(error) => println!("Couldn't query, error: {}", error),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(2304),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27020),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDError::TypeParse,
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let mut valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(7780),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(address, port.unwrap_or(23000), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27004),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::three::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::three::query(address, port.unwrap_or(64100), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::protocols::valve::{Engine, Environment, Server, ValveProtocol};
|
||||
use crate::GDResult;
|
||||
|
|
@ -42,11 +43,11 @@ pub struct Response {
|
|||
pub time_left: u16,
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<Response> {
|
||||
query_with_timeout(address, port, TimeoutSettings::default())
|
||||
}
|
||||
|
||||
pub fn query_with_timeout(address: &str, port: Option<u16>, timeout_settings: TimeoutSettings) -> GDResult<Response> {
|
||||
pub fn query_with_timeout(address: &Ipv4Addr, port: Option<u16>, timeout_settings: TimeoutSettings) -> GDResult<Response> {
|
||||
let mut client = ValveProtocol::new(address, port.unwrap_or(5478), Some(timeout_settings))?;
|
||||
let mut buffer = client.get_request_data(
|
||||
&Engine::GoldSrc(true),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27131),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::minecraft::{self, BedrockResponse, JavaResponse, LegacyGroup},
|
||||
GDError,
|
||||
|
|
@ -6,7 +7,7 @@ use crate::{
|
|||
|
||||
/// Query with all the protocol variants one by one (Java -> Bedrock -> Legacy
|
||||
/// (1.6 -> 1.4 -> Beta 1.8)).
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_java(address, port) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
|
@ -23,22 +24,22 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<JavaResponse> {
|
|||
}
|
||||
|
||||
/// Query a Java Server.
|
||||
pub fn query_java(address: &str, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
pub fn query_java(address: &Ipv4Addr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
minecraft::query_java(address, port_or_java_default(port), None)
|
||||
}
|
||||
|
||||
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
||||
pub fn query_legacy(address: &str, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
pub fn query_legacy(address: &Ipv4Addr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
minecraft::query_legacy(address, port_or_java_default(port), None)
|
||||
}
|
||||
|
||||
/// Query a specific (Java) Legacy Server.
|
||||
pub fn query_legacy_specific(group: LegacyGroup, address: &str, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
pub fn query_legacy_specific(group: LegacyGroup, address: &Ipv4Addr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
minecraft::query_legacy_specific(group, address, port_or_java_default(port), None)
|
||||
}
|
||||
|
||||
/// Query a Bedrock Server.
|
||||
pub fn query_bedrock(address: &str, port: Option<u16>) -> GDResult<BedrockResponse> {
|
||||
pub fn query_bedrock(address: &Ipv4Addr, port: Option<u16>) -> GDResult<BedrockResponse> {
|
||||
minecraft::query_bedrock(address, port_or_bedrock_default(port), None)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27005),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(7776),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(16261),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(26900),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(address, port.unwrap_or(25601), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -93,7 +94,7 @@ impl Response {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(address, port.unwrap_or(7778), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<game::Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! ```
|
||||
//! use gamedig::games::tf2;
|
||||
//!
|
||||
//! let response = tf2::query("127.0.0.1", None); // None is the default port (which is 27015), could also be Some(27015)
|
||||
//! let response = tf2::query(&"127.0.0.1".parse().unwrap(), None); // None is the default port (which is 27015), could also be Some(27015)
|
||||
//! match response { // Result type, must check what it is...
|
||||
//! Err(error) => println!("Couldn't query, error: {}", error),
|
||||
//! Ok(r) => println!("{:#?}", r)
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ use crate::{
|
|||
|
||||
use crate::protocols::gamespy::common::has_password;
|
||||
use std::collections::HashMap;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
fn get_server_values(
|
||||
address: &str,
|
||||
address: &Ipv4Addr,
|
||||
port: u16,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<HashMap<String, String>> {
|
||||
|
|
@ -177,7 +178,7 @@ fn extract_players(server_vars: &mut HashMap<String, String>, players_maximum: u
|
|||
/// If there are parsing problems using the `query` function, you can directly
|
||||
/// get the server's values using this function.
|
||||
pub fn query_vars(
|
||||
address: &str,
|
||||
address: &Ipv4Addr,
|
||||
port: u16,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<HashMap<String, String>> {
|
||||
|
|
@ -187,7 +188,7 @@ pub fn query_vars(
|
|||
/// Query a server by providing the address, the port and timeout settings.
|
||||
/// Providing None to the timeout settings results in using the default values.
|
||||
/// (TimeoutSettings::[default](TimeoutSettings::default)).
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
let mut server_vars = query_vars(address, port, timeout_settings)?;
|
||||
|
||||
let players_maximum = server_vars
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use crate::protocols::types::TimeoutSettings;
|
|||
use crate::socket::{Socket, UdpSocket};
|
||||
use crate::{GDError, GDResult};
|
||||
use std::collections::HashMap;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
const THIS_SESSION_ID: u32 = 1;
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ struct GameSpy3 {
|
|||
const PACKET_SIZE: usize = 2048;
|
||||
|
||||
impl GameSpy3 {
|
||||
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ impl GameSpy3 {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_server_packets(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Vec<Vec<u8>>> {
|
||||
fn get_server_packets(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Vec<Vec<u8>>> {
|
||||
let mut gs3 = GameSpy3::new(address, port, timeout_settings)?;
|
||||
|
||||
let challenge = gs3.make_initial_handshake()?;
|
||||
|
|
@ -164,7 +165,7 @@ fn data_to_map(packet: &[u8]) -> GDResult<(HashMap<String, String>, Vec<u8>)> {
|
|||
/// If there are parsing problems using the `query` function, you can directly
|
||||
/// get the server's values using this function.
|
||||
pub fn query_vars(
|
||||
address: &str,
|
||||
address: &Ipv4Addr,
|
||||
port: u16,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<HashMap<String, String>> {
|
||||
|
|
@ -307,7 +308,7 @@ fn parse_players_and_teams(packets: Vec<Vec<u8>>) -> GDResult<(Vec<Player>, Vec<
|
|||
/// Query a server by providing the address, the port and timeout settings.
|
||||
/// Providing None to the timeout settings results in using the default values.
|
||||
/// (TimeoutSettings::[default](TimeoutSettings::default)).
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
let packets = get_server_packets(address, port, timeout_settings)?;
|
||||
|
||||
let (mut server_vars, remaining_data) = data_to_map(packets.get(0).ok_or(GDError::PacketBad)?)?;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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::Ipv4Addr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -18,7 +19,7 @@ pub struct Bedrock {
|
|||
}
|
||||
|
||||
impl Bedrock {
|
||||
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ impl Bedrock {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::new(address, port, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -30,7 +31,7 @@ pub struct Java {
|
|||
}
|
||||
|
||||
impl Java {
|
||||
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -138,7 +139,7 @@ impl Java {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
Java::new(address, port, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -15,7 +16,7 @@ pub struct LegacyBV1_8 {
|
|||
}
|
||||
|
||||
impl LegacyBV1_8 {
|
||||
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ impl LegacyBV1_8 {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyBV1_8::new(address, port, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -15,7 +16,7 @@ pub struct LegacyV1_4 {
|
|||
}
|
||||
|
||||
impl LegacyV1_4 {
|
||||
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ impl LegacyV1_4 {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyV1_4::new(address, port, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -15,7 +16,7 @@ pub struct LegacyV1_6 {
|
|||
}
|
||||
|
||||
impl LegacyV1_6 {
|
||||
fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ impl LegacyV1_6 {
|
|||
LegacyV1_6::get_response(&mut buffer)
|
||||
}
|
||||
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyV1_6::new(address, port, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::Ipv4Addr;
|
||||
use crate::{
|
||||
protocols::minecraft::{
|
||||
protocol::{
|
||||
|
|
@ -24,7 +25,7 @@ mod legacy_v1_6;
|
|||
|
||||
/// Queries a Minecraft server with all the protocol variants one by one (Java
|
||||
/// -> Bedrock -> Legacy (1.6 -> 1.4 -> Beta 1.8)).
|
||||
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_java(address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
|
@ -41,12 +42,12 @@ pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>
|
|||
}
|
||||
|
||||
/// Query a Java Server.
|
||||
pub fn query_java(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query_java(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
Java::query(address, port, timeout_settings)
|
||||
}
|
||||
|
||||
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
||||
pub fn query_legacy(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
pub fn query_legacy(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_6, address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
|
@ -65,7 +66,7 @@ pub fn query_legacy(address: &str, port: u16, timeout_settings: Option<TimeoutSe
|
|||
/// Query a specific (Java) Legacy Server.
|
||||
pub fn query_legacy_specific(
|
||||
group: LegacyGroup,
|
||||
address: &str,
|
||||
address: &Ipv4Addr,
|
||||
port: u16,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<JavaResponse> {
|
||||
|
|
@ -77,6 +78,6 @@ pub fn query_legacy_specific(
|
|||
}
|
||||
|
||||
/// Query a Bedrock Server.
|
||||
pub fn query_bedrock(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
pub fn query_bedrock(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::query(address, port, timeout_settings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use bzip2_rs::decoder::Decoder;
|
|||
|
||||
use crate::protocols::valve::Packet;
|
||||
use std::collections::HashMap;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)] //remove this later on
|
||||
|
|
@ -124,7 +125,7 @@ pub(crate) struct ValveProtocol {
|
|||
static PACKET_SIZE: usize = 6144;
|
||||
|
||||
impl ValveProtocol {
|
||||
pub fn new(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
pub fn new(address: &Ipv4Addr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address, port)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
|
|
@ -411,7 +412,7 @@ impl ValveProtocol {
|
|||
/// (GatherSettings::[default](GatheringSettings::default),
|
||||
/// TimeoutSettings::[default](TimeoutSettings::default)).
|
||||
pub fn query(
|
||||
address: &str,
|
||||
address: &Ipv4Addr,
|
||||
port: u16,
|
||||
engine: Engine,
|
||||
gather_settings: Option<GatheringSettings>,
|
||||
|
|
@ -428,7 +429,7 @@ pub fn query(
|
|||
}
|
||||
|
||||
fn get_response(
|
||||
address: &str,
|
||||
address: &Ipv4Addr,
|
||||
port: u16,
|
||||
engine: Engine,
|
||||
gather_settings: GatheringSettings,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{GDError, GDResult};
|
|||
use std::net::Ipv4Addr;
|
||||
|
||||
/// The default master ip, which is the one for Source.
|
||||
pub const DEFAULT_MASTER_IP: &str = "hl2master.steampowered.com";
|
||||
pub const DEFAULT_MASTER_IP: Ipv4Addr = Ipv4Addr::new(208, 64, 201, 194); // hl2master.steampowered.com
|
||||
/// The default master port.
|
||||
pub const DEFAULT_MASTER_PORT: u16 = 27011;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ pub struct ValveMasterServer {
|
|||
|
||||
impl ValveMasterServer {
|
||||
/// Construct a new struct.
|
||||
pub fn new(master_ip: &str, master_port: u16) -> GDResult<Self> {
|
||||
pub fn new(master_ip: &Ipv4Addr, master_port: u16) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(master_ip, master_port)?;
|
||||
socket.apply_timeout(None)?;
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ impl ValveMasterServer {
|
|||
/// faster as it results in less packets being sent, received and processed but
|
||||
/// yields less ips.
|
||||
pub fn query_singular(region: Region, search_filters: Option<SearchFilters>) -> GDResult<Vec<(Ipv4Addr, u16)>> {
|
||||
let mut master_server = ValveMasterServer::new(DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
|
||||
let mut ips = master_server.query_specific(region, &search_filters, "0.0.0.0", 0)?;
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ pub fn query_singular(region: Region, search_filters: Option<SearchFilters>) ->
|
|||
|
||||
/// Make a complete query.
|
||||
pub fn query(region: Region, search_filters: Option<SearchFilters>) -> GDResult<Vec<(Ipv4Addr, u16)>> {
|
||||
let mut master_server = ValveMasterServer::new(DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
|
||||
master_server.query(region, search_filters)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ use std::{
|
|||
io::{Read, Write},
|
||||
net,
|
||||
};
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
const DEFAULT_PACKET_SIZE: usize = 1024;
|
||||
|
||||
pub trait Socket {
|
||||
fn new(address: &str, port: u16) -> GDResult<Self>
|
||||
fn new(address: &Ipv4Addr, port: u16) -> GDResult<Self>
|
||||
where Self: Sized;
|
||||
|
||||
fn apply_timeout(&self, timeout_settings: Option<TimeoutSettings>) -> GDResult<()>;
|
||||
|
|
@ -27,7 +28,7 @@ pub struct TcpSocket {
|
|||
}
|
||||
|
||||
impl Socket for TcpSocket {
|
||||
fn new(address: &str, port: u16) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16) -> GDResult<Self> {
|
||||
let complete_address = address_and_port_as_string(address, port);
|
||||
|
||||
Ok(Self {
|
||||
|
|
@ -64,7 +65,7 @@ pub struct UdpSocket {
|
|||
}
|
||||
|
||||
impl Socket for UdpSocket {
|
||||
fn new(address: &str, port: u16) -> GDResult<Self> {
|
||||
fn new(address: &Ipv4Addr, port: u16) -> GDResult<Self> {
|
||||
let complete_address = address_and_port_as_string(address, port);
|
||||
let socket = net::UdpSocket::bind("0.0.0.0:0").map_err(|_| SocketBind)?;
|
||||
|
||||
|
|
@ -99,6 +100,7 @@ impl Socket for UdpSocket {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::IpAddr;
|
||||
use std::thread;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -115,8 +117,13 @@ mod tests {
|
|||
stream.write(&buf).unwrap();
|
||||
});
|
||||
|
||||
let address = match bound_address.ip() {
|
||||
IpAddr::V4(a) => a,
|
||||
_ => panic!("address not ipv4!")
|
||||
};
|
||||
|
||||
// Create a TCP socket and send a message to the server
|
||||
let mut socket = TcpSocket::new(&*bound_address.ip().to_string(), bound_address.port()).unwrap();
|
||||
let mut socket = TcpSocket::new(&address, bound_address.port()).unwrap();
|
||||
let message = b"hello, world!";
|
||||
socket.send(message).unwrap();
|
||||
|
||||
|
|
@ -146,8 +153,13 @@ mod tests {
|
|||
socket.send_to(&buf, src_addr).unwrap();
|
||||
});
|
||||
|
||||
let address = match bound_address.ip() {
|
||||
IpAddr::V4(a) => a,
|
||||
_ => panic!("address not ipv4!")
|
||||
};
|
||||
|
||||
// Create a UDP socket and send a message to the server
|
||||
let mut socket = UdpSocket::new(&*bound_address.ip().to_string(), bound_address.port()).unwrap();
|
||||
let mut socket = UdpSocket::new(&address, bound_address.port()).unwrap();
|
||||
let message = b"hello, world!";
|
||||
socket.send(message).unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use crate::{
|
|||
};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
||||
match size.cmp(&expected) {
|
||||
|
|
@ -13,16 +14,18 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn address_and_port_as_string(address: &str, port: u16) -> String { format!("{}:{}", address, port) }
|
||||
pub fn address_and_port_as_string(address: &Ipv4Addr, port: u16) -> String { format!("{}:{}", address, port) }
|
||||
|
||||
pub fn u8_lower_upper(n: u8) -> (u8, u8) { (n & 15, n >> 4) }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[test]
|
||||
fn address_and_port_as_string() {
|
||||
assert_eq!(
|
||||
super::address_and_port_as_string("192.168.0.1", 27015),
|
||||
super::address_and_port_as_string(&Ipv4Addr::new(192, 168, 0, 1), 27015),
|
||||
"192.168.0.1:27015"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue