mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
[Protocol] Replace IpAddr with SocketAddr in protocols (#44)
* [Crate] Replace IpAddr with SocketAddr in protocols * [Crate] Remove usage of address.to_string in socket * [Crate] Update CHANGELOG.md
This commit is contained in:
parent
596d15df78
commit
e0830bdae5
70 changed files with 215 additions and 286 deletions
|
|
@ -16,6 +16,7 @@ Games:
|
|||
|
||||
### Breaking:
|
||||
- Every function that used `&str` for the address has been changed to `&IpAddr` (thanks [@Douile](https://github.com/Douile) for the re-re-write).
|
||||
- Protocols now use `&SocketAddr` instead of `address: &str, port: u16`.
|
||||
|
||||
Services:
|
||||
- Valve Master Query:
|
||||
|
|
|
|||
|
|
@ -4,7 +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, quake2, quake1, quake3a, hll, sof2};
|
||||
use std::env;
|
||||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
fn main() -> GDResult<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
|
@ -31,6 +31,7 @@ fn main() -> GDResult<()> {
|
|||
}
|
||||
true => Some(args[3].parse::<u16>().expect("Invalid port!")),
|
||||
};
|
||||
let address = &SocketAddr::new(ip.clone(), port.unwrap_or(0));
|
||||
|
||||
match args[1].as_str() {
|
||||
"aliens" => println!("{:#?}", aliens::query(ip, port)?),
|
||||
|
|
@ -52,19 +53,19 @@ fn main() -> GDResult<()> {
|
|||
"_src" => {
|
||||
println!(
|
||||
"{:#?}",
|
||||
valve::query(ip, port.unwrap(), Engine::Source(None), None, None)?
|
||||
valve::query(address, Engine::Source(None), None, None)?
|
||||
)
|
||||
}
|
||||
"_gld" => {
|
||||
println!(
|
||||
"{:#?}",
|
||||
valve::query(ip, port.unwrap(), Engine::GoldSrc(false), None, None)?
|
||||
valve::query(address, Engine::GoldSrc(false), None, None)?
|
||||
)
|
||||
}
|
||||
"_gld_f" => {
|
||||
println!(
|
||||
"{:#?}",
|
||||
valve::query(ip, port.unwrap(), Engine::GoldSrc(true), None, None)?
|
||||
valve::query(address, Engine::GoldSrc(true), None, None)?
|
||||
)
|
||||
}
|
||||
"mc" => println!("{:#?}", mc::query(ip, port)?),
|
||||
|
|
@ -114,18 +115,18 @@ fn main() -> GDResult<()> {
|
|||
"avorion" => println!("{:#?}", avorion::query(ip, port)?),
|
||||
"ohd" => println!("{:#?}", ohd::query(ip, port)?),
|
||||
"vr" => println!("{:#?}", vr::query(ip, port)?),
|
||||
"_gamespy1" => println!("{:#?}", gamespy::one::query(ip, port.unwrap(), None)),
|
||||
"_gamespy1_vars" => println!("{:#?}", gamespy::one::query_vars(ip, port.unwrap(), None)),
|
||||
"_gamespy1" => println!("{:#?}", gamespy::one::query(address, None)),
|
||||
"_gamespy1_vars" => println!("{:#?}", gamespy::one::query_vars(address, None)),
|
||||
"ut" => println!("{:#?}", ut::query(ip, port)),
|
||||
"bf1942" => println!("{:#?}", bf1942::query(ip, port)),
|
||||
"ss" => println!("{:#?}", ss::query(ip, port)),
|
||||
"_gamespy3" => println!("{:#?}", gamespy::three::query(ip, port.unwrap(), None)),
|
||||
"_gamespy3_vars" => println!("{:#?}", gamespy::three::query_vars(ip, port.unwrap(), None)),
|
||||
"_gamespy3" => println!("{:#?}", gamespy::three::query(address, None)),
|
||||
"_gamespy3_vars" => println!("{:#?}", gamespy::three::query_vars(address, None)),
|
||||
"ffow" => println!("{:#?}", ffow::query(ip, port)),
|
||||
"cw" => println!("{:#?}", cw::query(ip, port)),
|
||||
"_quake1" => println!("{:#?}", quake::one::query(ip, port.unwrap(), None)),
|
||||
"_quake2" => println!("{:#?}", quake::two::query(ip, port.unwrap(), None)),
|
||||
"_quake3" => println!("{:#?}", quake::three::query(ip, port.unwrap(), None)),
|
||||
"_quake1" => println!("{:#?}", quake::one::query(address, None)),
|
||||
"_quake2" => println!("{:#?}", quake::two::query(address, None)),
|
||||
"_quake3" => println!("{:#?}", quake::three::query(address, None)),
|
||||
"quake2" => println!("{:#?}", quake2::query(ip, port)?),
|
||||
"quake1" => println!("{:#?}", quake1::query(ip, port)?),
|
||||
"quake3a" => println!("{:#?}", quake3a::query(ip, port)?),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::ALIENS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::AOC.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(2304),
|
||||
&SocketAddr::new(*address, port.unwrap_or(2304)),
|
||||
SteamApp::ARMA2OA.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::ASE.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(2304)),
|
||||
SteamApp::ASRD.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27020),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27020)),
|
||||
SteamApp::AVORION.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDError::TypeParse,
|
||||
|
|
@ -7,8 +7,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let mut valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(7780),
|
||||
&SocketAddr::new(*address, port.unwrap_or(7780)),
|
||||
SteamApp::BAT1944.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::BB2.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(address, port.unwrap_or(23000), None)
|
||||
gamespy::one::query(&SocketAddr::new(*address, port.unwrap_or(23000)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::BM.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27016)),
|
||||
SteamApp::BO.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::CCURE.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27004),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27004)),
|
||||
SteamApp::COSU.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::CS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::CSCZ.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::CSGO.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::CSS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::three::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::three::query(address, port.unwrap_or(64100), None)
|
||||
gamespy::three::query(&SocketAddr::new(*address, port.unwrap_or(64100)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::DOD.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::DODS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::DOI.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27016)),
|
||||
SteamApp::DST.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::types::TimeoutSettings;
|
||||
use crate::protocols::valve::{Engine, Environment, Server, ValveProtocol};
|
||||
use crate::GDResult;
|
||||
|
|
@ -48,7 +48,7 @@ pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
|||
}
|
||||
|
||||
pub fn query_with_timeout(address: &IpAddr, port: Option<u16>, timeout_settings: TimeoutSettings) -> GDResult<Response> {
|
||||
let mut client = ValveProtocol::new(address, port.unwrap_or(5478), Some(timeout_settings))?;
|
||||
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,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27016)),
|
||||
SteamApp::GM.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::HL2DM.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::HLDMS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(26420),
|
||||
&SocketAddr::new(*address, port.unwrap_or(26420)),
|
||||
SteamApp::HLL.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::INS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::INSMIC.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27131),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27131)),
|
||||
SteamApp::INSS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::L4D.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::L4D2.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::minecraft::{self, BedrockResponse, JavaResponse, LegacyGroup},
|
||||
GDError,
|
||||
|
|
@ -25,22 +25,22 @@ pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<JavaResponse> {
|
|||
|
||||
/// Query a Java Server.
|
||||
pub fn query_java(address: &IpAddr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
minecraft::query_java(address, port_or_java_default(port), None)
|
||||
minecraft::query_java(&SocketAddr::new(*address, port_or_java_default(port)), None)
|
||||
}
|
||||
|
||||
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
||||
pub fn query_legacy(address: &IpAddr, port: Option<u16>) -> GDResult<JavaResponse> {
|
||||
minecraft::query_legacy(address, port_or_java_default(port), None)
|
||||
minecraft::query_legacy(&SocketAddr::new(*address, port_or_java_default(port)), None)
|
||||
}
|
||||
|
||||
/// 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, 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(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) }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27005),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27005)),
|
||||
SteamApp::OHD.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(7776),
|
||||
&SocketAddr::new(*address, port.unwrap_or(7776)),
|
||||
SteamApp::ONSET.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(16261),
|
||||
&SocketAddr::new(*address, port.unwrap_or(16261)),
|
||||
SteamApp::PZ.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::one::Player;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::one::query(address, port.unwrap_or(27500), None)
|
||||
quake::one::query(&SocketAddr::new(*address, port.unwrap_or(27500)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::two::Player;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::two::query(address, port.unwrap_or(27910), None)
|
||||
quake::two::query(&SocketAddr::new(*address, port.unwrap_or(27910)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::two::Player;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::three::query(address, port.unwrap_or(27960), None)
|
||||
quake::three::query(&SocketAddr::new(*address, port.unwrap_or(27960)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27016)),
|
||||
SteamApp::ROR2.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::RUST.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::SC.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(26900),
|
||||
&SocketAddr::new(*address, port.unwrap_or(26900)),
|
||||
SteamApp::SDTD.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake;
|
||||
use crate::protocols::quake::Response;
|
||||
use crate::protocols::quake::two::Player;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response<Player>> {
|
||||
quake::three::query(address, port.unwrap_or(20100), None)
|
||||
quake::three::query(&SocketAddr::new(*address, port.unwrap_or(20100)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(address, port.unwrap_or(25601), None)
|
||||
gamespy::one::query(&SocketAddr::new(*address, port.unwrap_or(25601)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27016)),
|
||||
SteamApp::TF.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::TF2.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::TFC.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -96,8 +96,7 @@ impl Response {
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::TS.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27015),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27015)),
|
||||
SteamApp::UNTURNED.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::protocols::gamespy;
|
||||
use crate::protocols::gamespy::one::Response;
|
||||
use crate::GDResult;
|
||||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
|
||||
gamespy::one::query(address, port.unwrap_or(7778), None)
|
||||
gamespy::one::query(&SocketAddr::new(*address, port.unwrap_or(7778)), None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use crate::{
|
||||
protocols::valve::{self, game, SteamApp},
|
||||
GDResult,
|
||||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
|
||||
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
|
||||
let valve_response = valve::query(
|
||||
address,
|
||||
port.unwrap_or(27016),
|
||||
&SocketAddr::new(*address, port.unwrap_or(27016)),
|
||||
SteamApp::VR.as_engine(),
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -8,17 +8,15 @@ use crate::{
|
|||
GDError,
|
||||
GDResult,
|
||||
};
|
||||
|
||||
use crate::protocols::gamespy::common::has_password;
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
fn get_server_values(
|
||||
address: &IpAddr,
|
||||
port: u16,
|
||||
address: &SocketAddr,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<HashMap<String, String>> {
|
||||
let mut socket = UdpSocket::new(address, port)?;
|
||||
let mut socket = UdpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
socket.send("\\status\\xserverquery".as_bytes())?;
|
||||
|
|
@ -178,18 +176,17 @@ 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: &IpAddr,
|
||||
port: u16,
|
||||
address: &SocketAddr,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<HashMap<String, String>> {
|
||||
get_server_values(address, port, timeout_settings)
|
||||
get_server_values(address, timeout_settings)
|
||||
}
|
||||
|
||||
/// 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: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
let mut server_vars = query_vars(address, port, timeout_settings)?;
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
let mut server_vars = query_vars(address, timeout_settings)?;
|
||||
|
||||
let players_maximum = server_vars
|
||||
.remove("maxplayers")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::protocols::types::TimeoutSettings;
|
|||
use crate::socket::{Socket, UdpSocket};
|
||||
use crate::{GDError, GDResult};
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
const THIS_SESSION_ID: u32 = 1;
|
||||
|
||||
|
|
@ -43,8 +43,8 @@ struct GameSpy3 {
|
|||
const PACKET_SIZE: usize = 2048;
|
||||
|
||||
impl GameSpy3 {
|
||||
fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address, port)?;
|
||||
fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -104,8 +104,8 @@ impl GameSpy3 {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_server_packets(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Vec<Vec<u8>>> {
|
||||
let mut gs3 = GameSpy3::new(address, port, timeout_settings)?;
|
||||
fn get_server_packets(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Vec<Vec<u8>>> {
|
||||
let mut gs3 = GameSpy3::new(address, timeout_settings)?;
|
||||
|
||||
let challenge = gs3.make_initial_handshake()?;
|
||||
gs3.send_data_request(challenge)?;
|
||||
|
|
@ -165,11 +165,10 @@ 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: &IpAddr,
|
||||
port: u16,
|
||||
address: &SocketAddr,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<HashMap<String, String>> {
|
||||
let packets = get_server_packets(address, port, timeout_settings)?;
|
||||
let packets = get_server_packets(address, timeout_settings)?;
|
||||
|
||||
let mut vars = HashMap::new();
|
||||
|
||||
|
|
@ -308,8 +307,8 @@ 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: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
let packets = get_server_packets(address, port, timeout_settings)?;
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
let packets = get_server_packets(address, timeout_settings)?;
|
||||
|
||||
let (mut server_vars, remaining_data) = data_to_map(packets.get(0).ok_or(GDError::PacketBad)?)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +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::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -19,8 +19,8 @@ pub struct Bedrock {
|
|||
}
|
||||
|
||||
impl Bedrock {
|
||||
fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address, port)?;
|
||||
fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -93,7 +93,7 @@ impl Bedrock {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::new(address, port, timeout_settings)?.get_info()
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::new(address, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -31,8 +31,8 @@ pub struct Java {
|
|||
}
|
||||
|
||||
impl Java {
|
||||
fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -139,7 +139,7 @@ impl Java {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
Java::new(address, port, timeout_settings)?.get_info()
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
Java::new(address, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -16,8 +16,8 @@ pub struct LegacyBV1_8 {
|
|||
}
|
||||
|
||||
impl LegacyBV1_8 {
|
||||
fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -60,7 +60,7 @@ impl LegacyBV1_8 {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyBV1_8::new(address, port, timeout_settings)?.get_info()
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyBV1_8::new(address, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -16,8 +16,8 @@ pub struct LegacyV1_4 {
|
|||
}
|
||||
|
||||
impl LegacyV1_4 {
|
||||
fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -64,7 +64,7 @@ impl LegacyV1_4 {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyV1_4::new(address, port, timeout_settings)?.get_info()
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyV1_4::new(address, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
bufferer::{Bufferer, Endianess},
|
||||
protocols::{
|
||||
|
|
@ -16,8 +16,8 @@ pub struct LegacyV1_6 {
|
|||
}
|
||||
|
||||
impl LegacyV1_6 {
|
||||
fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address, port)?;
|
||||
fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = TcpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -93,7 +93,7 @@ impl LegacyV1_6 {
|
|||
LegacyV1_6::get_response(&mut buffer)
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyV1_6::new(address, port, timeout_settings)?.get_info()
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
LegacyV1_6::new(address, timeout_settings)?.get_info()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use crate::{
|
||||
protocols::minecraft::{
|
||||
protocol::{
|
||||
|
|
@ -25,16 +25,16 @@ 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: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_java(address, port, timeout_settings.clone()) {
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_java(address, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_bedrock(address, port, timeout_settings.clone()) {
|
||||
if let Ok(response) = query_bedrock(address, timeout_settings.clone()) {
|
||||
return Ok(JavaResponse::from_bedrock_response(response));
|
||||
}
|
||||
|
||||
if let Ok(response) = query_legacy(address, port, timeout_settings) {
|
||||
if let Ok(response) = query_legacy(address, timeout_settings) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
|
|
@ -42,21 +42,21 @@ pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettin
|
|||
}
|
||||
|
||||
/// Query a Java Server.
|
||||
pub fn query_java(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
Java::query(address, port, timeout_settings)
|
||||
pub fn query_java(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
Java::query(address, timeout_settings)
|
||||
}
|
||||
|
||||
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
||||
pub fn query_legacy(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_6, address, port, timeout_settings.clone()) {
|
||||
pub fn query_legacy(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_6, address, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_4, address, port, timeout_settings.clone()) {
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_4, address, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::VB1_8, address, port, timeout_settings) {
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::VB1_8, address, timeout_settings) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
|
|
@ -66,18 +66,17 @@ pub fn query_legacy(address: &IpAddr, port: u16, timeout_settings: Option<Timeou
|
|||
/// Query a specific (Java) Legacy Server.
|
||||
pub fn query_legacy_specific(
|
||||
group: LegacyGroup,
|
||||
address: &IpAddr,
|
||||
port: u16,
|
||||
address: &SocketAddr,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<JavaResponse> {
|
||||
match group {
|
||||
LegacyGroup::V1_6 => LegacyV1_6::query(address, port, timeout_settings),
|
||||
LegacyGroup::V1_4 => LegacyV1_4::query(address, port, timeout_settings),
|
||||
LegacyGroup::VB1_8 => LegacyBV1_8::query(address, port, timeout_settings),
|
||||
LegacyGroup::V1_6 => LegacyV1_6::query(address, timeout_settings),
|
||||
LegacyGroup::V1_4 => LegacyV1_4::query(address, timeout_settings),
|
||||
LegacyGroup::VB1_8 => LegacyBV1_8::query(address, timeout_settings),
|
||||
}
|
||||
}
|
||||
|
||||
/// Query a Bedrock Server.
|
||||
pub fn query_bedrock(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::query(address, port, timeout_settings)
|
||||
pub fn query_bedrock(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::query(address, timeout_settings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::bufferer::{Bufferer, Endianess};
|
||||
use crate::{GDError, GDResult};
|
||||
|
|
@ -15,8 +15,8 @@ pub(crate) trait QuakeClient {
|
|||
fn parse_player_string(data: Iter<&str>) -> GDResult<Self::Player>;
|
||||
}
|
||||
|
||||
fn get_data<Client: QuakeClient>(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Bufferer> {
|
||||
let mut socket = UdpSocket::new(address, port)?;
|
||||
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())?;
|
||||
|
|
@ -78,8 +78,8 @@ fn get_players<Client: QuakeClient>(bufferer: &mut Bufferer) -> GDResult<Vec<Cli
|
|||
Ok(players)
|
||||
}
|
||||
|
||||
pub(crate) fn client_query<Client: QuakeClient>(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Client::Player>> {
|
||||
let mut bufferer = get_data::<Client>(address, port, timeout_settings)?;
|
||||
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)?;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::Response;
|
||||
|
|
@ -72,6 +72,6 @@ impl QuakeClient for QuakeOne {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeOne>(address, port, timeout_settings)
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeOne>(address, timeout_settings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::GDResult;
|
||||
use crate::protocols::quake::two::{Player, QuakeTwo};
|
||||
|
|
@ -23,6 +23,6 @@ impl QuakeClient for QuakeThree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeThree>(address, port, timeout_settings)
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeThree>(address, timeout_settings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
use std::slice::Iter;
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::quake::one::QuakeOne;
|
||||
|
|
@ -47,6 +47,6 @@ impl QuakeClient for QuakeTwo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn query(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeTwo>(address, port, timeout_settings)
|
||||
pub fn query(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response<Player>> {
|
||||
client_query::<QuakeTwo>(address, timeout_settings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use bzip2_rs::decoder::Decoder;
|
|||
|
||||
use crate::protocols::valve::Packet;
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)] //remove this later on
|
||||
|
|
@ -125,8 +125,8 @@ pub(crate) struct ValveProtocol {
|
|||
static PACKET_SIZE: usize = 6144;
|
||||
|
||||
impl ValveProtocol {
|
||||
pub fn new(address: &IpAddr, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address, port)?;
|
||||
pub fn new(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(address)?;
|
||||
socket.apply_timeout(timeout_settings)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -412,8 +412,7 @@ impl ValveProtocol {
|
|||
/// (GatherSettings::[default](GatheringSettings::default),
|
||||
/// TimeoutSettings::[default](TimeoutSettings::default)).
|
||||
pub fn query(
|
||||
address: &IpAddr,
|
||||
port: u16,
|
||||
address: &SocketAddr,
|
||||
engine: Engine,
|
||||
gather_settings: Option<GatheringSettings>,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
|
|
@ -421,7 +420,6 @@ pub fn query(
|
|||
let response_gather_settings = gather_settings.unwrap_or_default();
|
||||
get_response(
|
||||
address,
|
||||
port,
|
||||
engine,
|
||||
response_gather_settings,
|
||||
timeout_settings,
|
||||
|
|
@ -429,13 +427,12 @@ pub fn query(
|
|||
}
|
||||
|
||||
fn get_response(
|
||||
address: &IpAddr,
|
||||
port: u16,
|
||||
address: &SocketAddr,
|
||||
engine: Engine,
|
||||
gather_settings: GatheringSettings,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<Response> {
|
||||
let mut client = ValveProtocol::new(address, port, timeout_settings)?;
|
||||
let mut client = ValveProtocol::new(address, timeout_settings)?;
|
||||
|
||||
let info = client.get_server_info(&engine)?;
|
||||
let protocol = info.protocol;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ use crate::bufferer::{Bufferer, Endianess};
|
|||
use crate::socket::{Socket, UdpSocket};
|
||||
use crate::valve_master_server::{Region, SearchFilters};
|
||||
use crate::{GDError, GDResult};
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
|
||||
/// The default master ip, which is the one for Source.
|
||||
pub const DEFAULT_MASTER_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(208, 64, 201, 194)); // hl2master.steampowered.com
|
||||
/// The default master port.
|
||||
pub const DEFAULT_MASTER_PORT: u16 = 27011;
|
||||
pub const DEFAULT_MASTER_ADDRESS: SocketAddr
|
||||
= SocketAddr::new(IpAddr::V4(Ipv4Addr::new(208, 64, 201, 194)), 27011); // hl2master.steampowered.com
|
||||
|
||||
fn construct_payload(region: Region, filters: &Option<SearchFilters>, last_ip: &str, last_port: u16) -> Vec<u8> {
|
||||
let filters_bytes: Vec<u8> = match filters {
|
||||
|
|
@ -43,8 +42,8 @@ pub struct ValveMasterServer {
|
|||
|
||||
impl ValveMasterServer {
|
||||
/// Construct a new struct.
|
||||
pub fn new(master_ip: &IpAddr, master_port: u16) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(master_ip, master_port)?;
|
||||
pub fn new(master_address: &SocketAddr) -> GDResult<Self> {
|
||||
let socket = UdpSocket::new(master_address)?;
|
||||
socket.apply_timeout(None)?;
|
||||
|
||||
Ok(Self { socket })
|
||||
|
|
@ -123,7 +122,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<(IpAddr, u16)>> {
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_ADDRESS)?;
|
||||
|
||||
let mut ips = master_server.query_specific(region, &search_filters, "0.0.0.0", 0)?;
|
||||
|
||||
|
|
@ -138,7 +137,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<(IpAddr, u16)>> {
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_IP, DEFAULT_MASTER_PORT)?;
|
||||
let mut master_server = ValveMasterServer::new(&DEFAULT_MASTER_ADDRESS)?;
|
||||
|
||||
master_server.query(region, search_filters)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
protocols::types::TimeoutSettings,
|
||||
utils::address_and_port_as_string,
|
||||
GDError::{PacketReceive, PacketSend, SocketBind, SocketConnect},
|
||||
GDResult,
|
||||
};
|
||||
|
|
@ -9,12 +8,12 @@ use std::{
|
|||
io::{Read, Write},
|
||||
net,
|
||||
};
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
const DEFAULT_PACKET_SIZE: usize = 1024;
|
||||
|
||||
pub trait Socket {
|
||||
fn new(address: &IpAddr, port: u16) -> GDResult<Self>
|
||||
fn new(address: &SocketAddr) -> GDResult<Self>
|
||||
where Self: Sized;
|
||||
|
||||
fn apply_timeout(&self, timeout_settings: Option<TimeoutSettings>) -> GDResult<()>;
|
||||
|
|
@ -28,11 +27,9 @@ pub struct TcpSocket {
|
|||
}
|
||||
|
||||
impl Socket for TcpSocket {
|
||||
fn new(address: &IpAddr, port: u16) -> GDResult<Self> {
|
||||
let complete_address = address_and_port_as_string(address, port);
|
||||
|
||||
fn new(address: &SocketAddr) -> GDResult<Self> {
|
||||
Ok(Self {
|
||||
socket: net::TcpStream::connect(complete_address).map_err(|_| SocketConnect)?,
|
||||
socket: net::TcpStream::connect(address).map_err(|_| SocketConnect)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -61,17 +58,16 @@ impl Socket for TcpSocket {
|
|||
|
||||
pub struct UdpSocket {
|
||||
socket: net::UdpSocket,
|
||||
complete_address: String,
|
||||
address: SocketAddr,
|
||||
}
|
||||
|
||||
impl Socket for UdpSocket {
|
||||
fn new(address: &IpAddr, port: u16) -> GDResult<Self> {
|
||||
let complete_address = address_and_port_as_string(address, port);
|
||||
fn new(address: &SocketAddr) -> GDResult<Self> {
|
||||
let socket = net::UdpSocket::bind("0.0.0.0:0").map_err(|_| SocketBind)?;
|
||||
|
||||
Ok(Self {
|
||||
socket,
|
||||
complete_address,
|
||||
address: address.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +81,7 @@ impl Socket for UdpSocket {
|
|||
|
||||
fn send(&mut self, data: &[u8]) -> GDResult<()> {
|
||||
self.socket
|
||||
.send_to(data, &self.complete_address)
|
||||
.send_to(data, &self.address)
|
||||
.map_err(|_| PacketSend)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -116,10 +112,8 @@ mod tests {
|
|||
stream.write(&buf).unwrap();
|
||||
});
|
||||
|
||||
let address = bound_address.ip();
|
||||
|
||||
// Create a TCP socket and send a message to the server
|
||||
let mut socket = TcpSocket::new(&address, bound_address.port()).unwrap();
|
||||
let mut socket = TcpSocket::new(&bound_address).unwrap();
|
||||
let message = b"hello, world!";
|
||||
socket.send(message).unwrap();
|
||||
|
||||
|
|
@ -149,10 +143,8 @@ mod tests {
|
|||
socket.send_to(&buf, src_addr).unwrap();
|
||||
});
|
||||
|
||||
let address = bound_address.ip();
|
||||
|
||||
// Create a UDP socket and send a message to the server
|
||||
let mut socket = UdpSocket::new(&address, bound_address.port()).unwrap();
|
||||
let mut socket = UdpSocket::new(&bound_address).unwrap();
|
||||
let message = b"hello, world!";
|
||||
socket.send(message).unwrap();
|
||||
|
||||
|
|
|
|||
14
src/utils.rs
14
src/utils.rs
|
|
@ -2,9 +2,7 @@ use crate::{
|
|||
GDError::{PacketOverflow, PacketUnderflow},
|
||||
GDResult,
|
||||
};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::net::IpAddr;
|
||||
|
||||
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
||||
match size.cmp(&expected) {
|
||||
|
|
@ -14,22 +12,10 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn address_and_port_as_string(address: &IpAddr, 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::{IpAddr, Ipv4Addr};
|
||||
|
||||
#[test]
|
||||
fn address_and_port_as_string() {
|
||||
assert_eq!(
|
||||
super::address_and_port_as_string(&IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), 27015),
|
||||
"192.168.0.1:27015"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn u8_lower_upper() {
|
||||
assert_eq!(super::u8_lower_upper(171), (11, 10));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue