mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
feat: Add the unreal2 protocol (#124)
* WIP: Add unreal2 protocol * Add/Update badge * protocols/unreal2: Update doc comments and TODOs * protocols/unreal2: Don't pre-allocate as many bot players * protocols/unreal2: Use "encoding-rs" for decoding unreal2 strings * Add/Update badge * protocols/unreal2: Add constants for player pre-allocation. Also improve some doc comments and update PACKET_SIZE. * protocols/unreal2: Early break when enough players have been parsed Add a fast-path to avoid waiting for packet timeout when we have parsed as many players as specified in the server info packet. * protocols/unreal2: Use HashSet to store mutators * protocols/unreal2: Handle server sending multiple values for a rule * protocols/unreal2: Add GatheringSettings to control what to query GatheringSettings allows skipping querying rules and/or players which can make the query return much faster. This also required moving each individual query into its own helper. * protocols/unreal2: Add more derives to types * protocols/unreal2: Simplify ServerInfo::parse() Co-Authored-By: CosminPerRam <cosmin.p@live.com> * Docs: Add unreal2 protocol documentation I used a website to generate the markdown RESPONSES table, the save file from this website is included to make updating the table easier in the future. https://www.tablesgenerator.com/markdown_tables * Add/Update badge * protocols/unreal2: Use the correct encoding for UCS2 strings * Docs: Remove unnecessary TGN file --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: CosminPerRam <cosmin.p@live.com>
This commit is contained in:
parent
5c1568251a
commit
529abe9d76
14 changed files with 708 additions and 52 deletions
54
src/protocols/unreal2/mod.rs
Normal file
54
src/protocols/unreal2/mod.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/// The implementation.
|
||||
pub mod protocol;
|
||||
/// All types used by the implementation.
|
||||
pub mod types;
|
||||
|
||||
pub use protocol::*;
|
||||
pub use types::*;
|
||||
|
||||
/// Generate a module containing a query function for a valve game.
|
||||
///
|
||||
/// * `mod_name` - The name to be given to the game module (see ID naming
|
||||
/// conventions in CONTRIBUTING.md).
|
||||
/// * `pretty_name` - The full name of the game, will be used as the
|
||||
/// documentation for the created module.
|
||||
/// * `default_port` - Passed through to [game_query_fn].
|
||||
macro_rules! game_query_mod {
|
||||
($mod_name: ident, $pretty_name: expr, $default_port: literal) => {
|
||||
#[doc = $pretty_name]
|
||||
pub mod $mod_name {
|
||||
crate::protocols::unreal2::game_query_fn!($default_port);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use game_query_mod;
|
||||
|
||||
// Allow generating doc comments:
|
||||
// https://users.rust-lang.org/t/macros-filling-text-in-comments/20473
|
||||
/// Generate a query function for a valve game.
|
||||
///
|
||||
/// * `default_port` - The default port the game uses.
|
||||
macro_rules! game_query_fn {
|
||||
($default_port: literal) => {
|
||||
crate::protocols::unreal2::game_query_fn! {@gen $default_port, concat!(
|
||||
"Make a Unreal2 query for with default timeout settings and default extra request settings.\n\n",
|
||||
"If port is `None`, then the default port (", stringify!($default_port), ") will be used.")}
|
||||
};
|
||||
|
||||
(@gen $default_port: literal, $doc: expr) => {
|
||||
#[doc = $doc]
|
||||
pub fn query(
|
||||
address: &std::net::IpAddr,
|
||||
port: Option<u16>,
|
||||
) -> crate::GDResult<crate::protocols::unreal2::Response> {
|
||||
crate::protocols::unreal2::query(
|
||||
&std::net::SocketAddr::new(*address, port.unwrap_or($default_port)),
|
||||
&crate::protocols::unreal2::GatheringSettings::default(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use game_query_fn;
|
||||
Loading…
Add table
Add a link
Reference in a new issue