[Games] Add timeout settings for proprietary games (#67)

Adding query functions with timeout settings to proprietary games allows
the generic query with timeout function to pass the timeout settings
through.

This does change how the pre-existing FFOW query_with_timeout function
worked: it accepted a non-optional timeout settings, this was changed to
optional to be consistent with other query_with_timeout functions and to
move deciding what to do if the user doesn't provide timeout settings to
a more central location.

Closes #64
This commit is contained in:
Tom 2023-07-10 13:17:49 +00:00 committed by GitHub
parent f3a792e325
commit e207e8dc95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 15 deletions

View file

@ -1,7 +1,7 @@
use crate::bufferer::{Bufferer, Endianess};
use crate::protocols::gamespy::common::has_password;
use crate::protocols::gamespy::three::{data_to_map, GameSpy3};
use crate::protocols::types::{CommonPlayer, CommonResponse, GenericPlayer};
use crate::protocols::types::{CommonPlayer, CommonResponse, GenericPlayer, TimeoutSettings};
use crate::protocols::GenericResponse;
use crate::{GDError, GDResult};
#[cfg(feature = "serde")]
@ -75,10 +75,16 @@ fn parse_players_and_teams(packet: Vec<u8>) -> GDResult<Vec<Player>> {
Ok(players)
}
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> {
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<Response> { query_with_timeout(address, port, None) }
pub fn query_with_timeout(
address: &IpAddr,
port: Option<u16>,
timeout_settings: Option<TimeoutSettings>,
) -> GDResult<Response> {
let mut client = GameSpy3::new_custom(
&SocketAddr::new(*address, port.unwrap_or(7777)),
None,
timeout_settings,
[0xFF, 0xFF, 0xFF, 0x02],
true,
)?;