Minecraft rework and some docs

This commit is contained in:
CosminPerRam 2022-11-28 22:08:28 +02:00
parent d671bb0310
commit 7828bb9433
4 changed files with 37 additions and 14 deletions

View file

@ -17,7 +17,8 @@ Who knows what the future holds...
Successfully tested `Alien Swarm` and `Insurgency: Modern Infantry Combat`.
Restored rules response for `Counter-Strike: Global Offensive` (note: for a full player list response, the cvar `host_players_show` must be set to `2`).
Increased Valve Protocol `PACKET_SIZE` from 1400 to 6144 (because some games send larger packets than the specified protocol size).
Removed DNS resolving as it was not needed.
Removed DNS resolving as it was not needed.
Valve Protocol minor optimizations.
# 0.0.5 - 15/11/2022
Added `SocketBind` error, regarding failing to bind a socket.

View file

@ -1,6 +1,6 @@
use std::env;
use gamedig::{aliens, arma2oa, ase, asrd, cs, cscz, csgo, css, dod, dods, doi, GDResult, gm, hl2dm, hldms, ins, insmic, inss, l4d, l4d2, mc, rust, sc, sdtd, tf, tf2, tfc, ts, unturned};
use gamedig::{aliens, arma2oa, ase, asrd, cs, cscz, csgo, css, dod, dods, doi, GDResult, gm, hl2dm, hldms, ins, insmic, inss, l4d, l4d2, mc, protocols, rust, sc, sdtd, tf, tf2, tfc, ts, unturned};
use gamedig::protocols::minecraft::{LegacyGroup, Server};
use gamedig::protocols::valve;
use gamedig::protocols::valve::App;
@ -48,11 +48,15 @@ fn main() -> GDResult<()> {
"ts" => println!("{:#?}", ts::query(ip, port)?),
"cscz" => println!("{:#?}", cscz::query(ip, port)?),
"dod" => println!("{:#?}", dod::query(ip, port)?),
"_src" => println!("{:#?}", valve::query(ip, port.unwrap(), App::Source(None), None, None)?),
"_gld" => println!("{:#?}", valve::query(ip, port.unwrap(), App::GoldSrc(false), None, None)?),
"_gld_f" => println!("{:#?}", valve::query(ip, port.unwrap(), App::GoldSrc(true), None, None)?),
"mc" => println!("{:#?}", mc::query(ip, port)?),
"mc_java" => println!("{:#?}", mc::query_specific(Server::Java, ip, port)?),
"mc_legacy_vb1_8" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::VB1_8), ip, port)?),
"mc_legacy_v1_4" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::V1_4), ip, port)?),
"mc_legacy_v1_6" => println!("{:#?}", mc::query_specific(Server::Legacy(LegacyGroup::V1_6), ip, port)?),
"mc_java" => println!("{:#?}", mc::query_java(ip, port)?),
"mc_legacy" => println!("{:#?}", mc::query_legacy(ip, port)?),
"_mc_legacy_vb1_8" => println!("{:#?}", protocols::minecraft::query_specific(Server::Legacy(LegacyGroup::VB1_8), ip, port.unwrap(), None)?),
"_mc_legacy_v1_4" => println!("{:#?}", protocols::minecraft::query_specific(Server::Legacy(LegacyGroup::V1_4), ip, port.unwrap(), None)?),
"_mc_legacy_v1_6" => println!("{:#?}", protocols::minecraft::query_specific(Server::Legacy(LegacyGroup::V1_6), ip, port.unwrap(), None)?),
"7dtd" => println!("{:#?}", sdtd::query(ip, port)?),
"ase" => println!("{:#?}", ase::query(ip, port)?),
"unturned" => println!("{:#?}", unturned::query(ip, port)?),
@ -64,9 +68,6 @@ fn main() -> GDResult<()> {
"arma2oa" => println!("{:#?}", arma2oa::query(ip, port)?),
"doi" => println!("{:#?}", doi::query(ip, port)?),
"hldms" => println!("{:#?}", hldms::query(ip, port)?),
"_src" => println!("{:#?}", valve::query(ip, port.unwrap(), App::Source(None), None, None)?),
"_gld" => println!("{:#?}", valve::query(ip, port.unwrap(), App::GoldSrc(false), None, None)?),
"_gld_f" => println!("{:#?}", valve::query(ip, port.unwrap(), App::GoldSrc(true), None, None)?),
_ => panic!("Undefined game: {}", args[1])
};

View file

@ -1,13 +1,34 @@
use crate::GDResult;
use crate::{GDError, GDResult};
use crate::protocols::minecraft;
use crate::protocols::minecraft::{Server, Response};
use crate::protocols::minecraft::{Server, Response, LegacyGroup};
/// Query with all the protocol variants one by one (Java -> Legacy (1.6 -> 1.4 -> Beta 1.8)).
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
minecraft::query(address, port_or_default(port), None)
}
pub fn query_specific(mc_type: Server, address: &str, port: Option<u16>) -> GDResult<Response> {
minecraft::query_specific(mc_type, address, port_or_default(port), None)
/// Query a Java Server.
pub fn query_java(address: &str, port: Option<u16>) -> GDResult<Response> {
minecraft::query_specific(Server::Java, address, port_or_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<Response> {
let unwrapped_port = port_or_default(port);
if let Ok(response) = minecraft::query_specific(Server::Legacy(LegacyGroup::V1_6), address, unwrapped_port, None) {
return Ok(response);
}
if let Ok(response) = minecraft::query_specific(Server::Legacy(LegacyGroup::V1_4), address, unwrapped_port, None) {
return Ok(response);
}
if let Ok(response) = minecraft::query_specific(Server::Legacy(LegacyGroup::VB1_8), address, unwrapped_port, None) {
return Ok(response);
}
Err(GDError::AutoQuery)
}
fn port_or_default(port: Option<u16>) -> u16 {

View file

@ -11,7 +11,7 @@ mod legacy_v1_4;
mod legacy_v1_6;
mod legacy_bv1_8;
/// Queries a Minecraft server.
/// Queries a Minecraft server with all the protocol variants one by one (Java -> Legacy (1.6 -> 1.4 -> Beta 1.8)).
pub fn query(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
if let Ok(response) = query_specific(Server::Java, address, port, timeout_settings.clone()) {
return Ok(response);