From bdcf64facf7b3f976ff9beb7a91024b18c28bac4 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Tue, 19 Dec 2023 20:58:15 +0100 Subject: [PATCH] chore: extract the ship into multiple files (#172) * chore: extract the ship into multiple files * fix: actual the ship reference link * fix: revert last commit and replace in ts --- crates/lib/src/games/theship/mod.rs | 8 +++++ crates/lib/src/games/theship/protocol.rs | 23 +++++++++++++ .../games/{theship.rs => theship/types.rs} | 34 +++---------------- 3 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 crates/lib/src/games/theship/mod.rs create mode 100644 crates/lib/src/games/theship/protocol.rs rename crates/lib/src/games/{theship.rs => theship/types.rs} (82%) diff --git a/crates/lib/src/games/theship/mod.rs b/crates/lib/src/games/theship/mod.rs new file mode 100644 index 0000000..b37a291 --- /dev/null +++ b/crates/lib/src/games/theship/mod.rs @@ -0,0 +1,8 @@ +/// The implementation. +/// Reference: [server queries](https://developer.valvesoftware.com/wiki/Server_queries) +pub mod protocol; +/// All types used by the implementation. +pub mod types; + +pub use protocol::*; +pub use types::*; diff --git a/crates/lib/src/games/theship/protocol.rs b/crates/lib/src/games/theship/protocol.rs new file mode 100644 index 0000000..c041ceb --- /dev/null +++ b/crates/lib/src/games/theship/protocol.rs @@ -0,0 +1,23 @@ +use crate::games::theship::types::Response; +use crate::protocols::types::TimeoutSettings; +use crate::protocols::valve; +use crate::protocols::valve::Engine; +use crate::GDResult; +use std::net::{IpAddr, SocketAddr}; + +pub fn query(address: &IpAddr, port: Option) -> GDResult { query_with_timeout(address, port, None) } + +pub fn query_with_timeout( + address: &IpAddr, + port: Option, + timeout_settings: Option, +) -> GDResult { + let valve_response = valve::query( + &SocketAddr::new(*address, port.unwrap_or(27015)), + Engine::new(2400), + None, + timeout_settings, + )?; + + Response::new_from_valve_response(valve_response) +} diff --git a/crates/lib/src/games/theship.rs b/crates/lib/src/games/theship/types.rs similarity index 82% rename from crates/lib/src/games/theship.rs rename to crates/lib/src/games/theship/types.rs index 5084200..9df679c 100644 --- a/crates/lib/src/games/theship.rs +++ b/crates/lib/src/games/theship/types.rs @@ -1,17 +1,10 @@ -use crate::{ - protocols::{ - types::{CommonPlayer, CommonResponse, GenericPlayer, TimeoutSettings}, - valve::{self, get_optional_extracted_data, Server, ServerPlayer}, - GenericResponse, - }, - GDErrorKind::PacketBad, - GDResult, -}; -use std::net::{IpAddr, SocketAddr}; - +use crate::protocols::types::{CommonPlayer, CommonResponse, GenericPlayer}; +use crate::protocols::valve::{get_optional_extracted_data, Server, ServerPlayer}; +use crate::protocols::{valve, GenericResponse}; +use crate::GDErrorKind::PacketBad; +use crate::GDResult; use std::collections::HashMap; -use crate::protocols::valve::Engine; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -127,20 +120,3 @@ impl Response { }) } } - -pub fn query(address: &IpAddr, port: Option) -> GDResult { query_with_timeout(address, port, None) } - -pub fn query_with_timeout( - address: &IpAddr, - port: Option, - timeout_settings: Option, -) -> GDResult { - let valve_response = valve::query( - &SocketAddr::new(*address, port.unwrap_or(27015)), - Engine::new(2400), - None, - timeout_settings, - )?; - - Response::new_from_valve_response(valve_response) -}