mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
Removed examples, added a master_querant change gather_settings to none (representing all)
This commit is contained in:
parent
83bbd5d428
commit
88a4c82158
28 changed files with 83 additions and 176 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -11,3 +11,6 @@ Cargo.lock
|
|||
|
||||
# Others
|
||||
.idea/
|
||||
.venv/
|
||||
|
||||
test_everything.py
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::asrd;
|
||||
|
||||
fn main() {
|
||||
let response = asrd::query("5.199.135.237", Some(30000));
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::csgo;
|
||||
|
||||
fn main() {
|
||||
let response = csgo::query("216.52.148.47", None);
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::css;
|
||||
|
||||
fn main() {
|
||||
let response = css::query("104.128.58.206", None);
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::dods;
|
||||
|
||||
fn main() {
|
||||
let response = dods::query("88.99.28.151", Some(27055));
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::gm;
|
||||
|
||||
fn main() {
|
||||
let response = gm::query("148.59.74.84", None);
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::hl2dm;
|
||||
|
||||
fn main() {
|
||||
let response = hl2dm::query("74.91.118.209", None);
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::ins;
|
||||
|
||||
fn main() {
|
||||
let response = ins::query("101.100.139.94", Some(27016));
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::inss;
|
||||
|
||||
fn main() {
|
||||
let response = inss::query("109.195.19.160", None); //The query port, not the server port
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::l4d;
|
||||
|
||||
fn main() {
|
||||
let response = l4d::query("207.246.72.170", Some(26999));
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::l4d2;
|
||||
|
||||
fn main() {
|
||||
let response = l4d2::query("74.91.124.246", None);
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
41
examples/master_querant.rs
Normal file
41
examples/master_querant.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
use std::env;
|
||||
use gamedig::{aliens, asrd, csgo, css, dods, gm, hl2dm, ins, inss, l4d, l4d2, tf2, ts};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() == 1 || args[1] == "help".to_string() {
|
||||
println!("Usage: <game> <ip> <port>");
|
||||
println!(" <game> - any game, example: tf2");
|
||||
println!(" <ip> - an ip, example: 192.168.0.0");
|
||||
println!(" <port> - an port, optional, example: 27015");
|
||||
return;
|
||||
} else if args.len() < 3 {
|
||||
println!("Minimum number of arguments: 3, try 'help' to see the details.");
|
||||
return;
|
||||
}
|
||||
|
||||
let ip = args[2].as_str();
|
||||
let port = match args.len() == 4 {
|
||||
false => None,
|
||||
true => Some(args[3].parse::<u16>().expect("Invalid port!"))
|
||||
};
|
||||
|
||||
match args[1].as_str() {
|
||||
"aliens" => println!("{:?}", aliens::query(ip, port)),
|
||||
"asrd" => println!("{:?}", asrd::query(ip, port)),
|
||||
"csgo" => println!("{:?}", csgo::query(ip, port)),
|
||||
"css" => println!("{:?}", css::query(ip, port)),
|
||||
"dods" => println!("{:?}", dods::query(ip, port)),
|
||||
"gm" => println!("{:?}", gm::query(ip, port)),
|
||||
"hl2dm" => println!("{:?}", hl2dm::query(ip, port)),
|
||||
"tf2" => println!("{:?}", tf2::query(ip, port)),
|
||||
"ins" => println!("{:?}", ins::query(ip, port)),
|
||||
"inss" => println!("{:?}", inss::query(ip, port)),
|
||||
"l4d" => println!("{:?}", l4d::query(ip, port)),
|
||||
"l4d2" => println!("{:?}", l4d2::query(ip, port)),
|
||||
"ts" => println!("{:?}", ts::query(ip, port)),
|
||||
_ => panic!("Undefined game: {}", args[1])
|
||||
};
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
use gamedig::games::tf2;
|
||||
|
||||
fn main() {
|
||||
let response = tf2::query("91.216.250.10", None); //or Some(27015), None is the default protocol port
|
||||
let response = tf2::query("cosminperram.com", None); //or Some(27015), None is the default protocol port (which is 27015)
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
use gamedig::games::ts;
|
||||
|
||||
fn main() {
|
||||
let response = ts::query("46.4.48.226", Some(27017));
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {error}"),
|
||||
Ok(r) => println!("{:?}", r)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::ALIENS, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::ASRD, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,10 +72,10 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::CSGO, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
}, Some(GatheringSettings {
|
||||
players: true,
|
||||
rules: false // cause csgo doesnt reply with rules anymore
|
||||
})?;
|
||||
}))?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::CSS, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::DODS, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::GM, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::HL2DM, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::INS, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::INSS, address, match port {
|
||||
None => 27131,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::L4D, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::L4D2, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, Server, ServerRule, ServerPlayer};
|
||||
use crate::valve::{ValveProtocol, App, Server, ServerRule, ServerPlayer};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -74,10 +74,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::TF2, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{GDResult, valve};
|
||||
use crate::valve::{ValveProtocol, App, GatheringSettings, ServerPlayer, Server, ServerRule};
|
||||
use crate::valve::{ValveProtocol, App, ServerPlayer, Server, ServerRule};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
|
|
@ -86,10 +86,7 @@ pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
|||
let valve_response = ValveProtocol::query(App::TS, address, match port {
|
||||
None => 27015,
|
||||
Some(port) => port
|
||||
}, GatheringSettings {
|
||||
players: true,
|
||||
rules: true
|
||||
})?;
|
||||
}, None)?;
|
||||
|
||||
Ok(Response::new_from_valve_response(valve_response))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -499,7 +499,8 @@ impl ValveProtocol {
|
|||
Ok(Some(rules))
|
||||
}
|
||||
|
||||
pub(crate) fn query(app: App, address: &str, port: u16, gather: GatheringSettings) -> Result<Response, GDError> {
|
||||
/// Query any app.
|
||||
pub fn query(app: App, address: &str, port: u16, gather_settings: Option<GatheringSettings>) -> Result<Response, GDError> {
|
||||
let client = ValveProtocol::new(address, port)?;
|
||||
|
||||
let info = client.get_server_info(&app)?;
|
||||
|
|
@ -509,13 +510,21 @@ impl ValveProtocol {
|
|||
return Err(GDError::BadGame(format!("Expected {}, found {} instead!", query_app_id, info.appid)));
|
||||
}
|
||||
|
||||
let (gather_players, gather_rules) = match gather_settings.is_some() {
|
||||
false => (true, true),
|
||||
true => {
|
||||
let settings = gather_settings.unwrap();
|
||||
(settings.players, settings.rules)
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Response {
|
||||
info,
|
||||
players: match gather.players {
|
||||
players: match gather_players {
|
||||
false => None,
|
||||
true => Some(client.get_server_players(&app)?)
|
||||
},
|
||||
rules: match gather.rules {
|
||||
rules: match gather_rules {
|
||||
false => None,
|
||||
true => client.get_server_rules(&app)?
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue