diff --git a/crates/lib/src/games/ffow/mod.rs b/crates/lib/src/games/ffow/mod.rs new file mode 100644 index 0000000..db37a19 --- /dev/null +++ b/crates/lib/src/games/ffow/mod.rs @@ -0,0 +1,8 @@ +/// The implementation. +/// Reference: [Node-GameGig](https://github.com/gamedig/node-gamedig/blob/master/protocols/ffow.js) +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/ffow.rs b/crates/lib/src/games/ffow/protocol.rs similarity index 50% rename from crates/lib/src/games/ffow.rs rename to crates/lib/src/games/ffow/protocol.rs index 9cbbdfc..9eb7423 100644 --- a/crates/lib/src/games/ffow.rs +++ b/crates/lib/src/games/ffow/protocol.rs @@ -1,64 +1,11 @@ use crate::buffer::{Buffer, Utf8Decoder}; -use crate::protocols::types::{CommonResponse, TimeoutSettings}; +use crate::games::ffow::types::Response; +use crate::protocols::types::TimeoutSettings; use crate::protocols::valve::{Engine, Environment, Server, ValveProtocol}; -use crate::protocols::GenericResponse; use crate::GDResult; use byteorder::LittleEndian; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use std::net::{IpAddr, SocketAddr}; -/// The query response. -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct Response { - /// Protocol used by the server. - pub protocol_version: u8, - /// Name of the server. - pub name: String, - /// Map name. - pub active_mod: String, - /// Running game mode. - pub game_mode: String, - /// The version that the server is running on. - pub game_version: String, - /// Description of the server. - pub description: String, - /// Current map. - pub map: String, - /// Number of players on the server. - pub players_online: u8, - /// Maximum number of players the server reports it can hold. - pub players_maximum: u8, - /// Dedicated, NonDedicated or SourceTV - pub server_type: Server, - /// The Operating System that the server is on. - pub environment_type: Environment, - /// Indicates whether the server requires a password. - pub has_password: bool, - /// Indicates whether the server uses VAC. - pub vac_secured: bool, - /// Current round index. - pub round: u8, - /// Maximum amount of rounds. - pub rounds_maximum: u8, - /// Time left for the current round in seconds. - pub time_left: u16, -} - -impl CommonResponse for Response { - fn as_original(&self) -> GenericResponse { GenericResponse::FFOW(self) } - - fn name(&self) -> Option<&str> { Some(&self.name) } - fn game_mode(&self) -> Option<&str> { Some(&self.game_mode) } - fn description(&self) -> Option<&str> { Some(&self.description) } - fn game_version(&self) -> Option<&str> { Some(&self.game_version) } - fn map(&self) -> Option<&str> { Some(&self.map) } - fn has_password(&self) -> Option { Some(self.has_password) } - fn players_maximum(&self) -> u32 { self.players_maximum.into() } - fn players_online(&self) -> u32 { self.players_online.into() } -} - pub fn query(address: &IpAddr, port: Option) -> GDResult { query_with_timeout(address, port, None) } pub fn query_with_timeout( diff --git a/crates/lib/src/games/ffow/types.rs b/crates/lib/src/games/ffow/types.rs new file mode 100644 index 0000000..4a8d852 --- /dev/null +++ b/crates/lib/src/games/ffow/types.rs @@ -0,0 +1,56 @@ +use crate::protocols::types::CommonResponse; +use crate::protocols::valve::{Environment, Server}; +use crate::protocols::GenericResponse; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +/// The query response. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct Response { + /// Protocol used by the server. + pub protocol_version: u8, + /// Name of the server. + pub name: String, + /// Map name. + pub active_mod: String, + /// Running game mode. + pub game_mode: String, + /// The version that the server is running on. + pub game_version: String, + /// Description of the server. + pub description: String, + /// Current map. + pub map: String, + /// Number of players on the server. + pub players_online: u8, + /// Maximum number of players the server reports it can hold. + pub players_maximum: u8, + /// Dedicated, NonDedicated or SourceTV + pub server_type: Server, + /// The Operating System that the server is on. + pub environment_type: Environment, + /// Indicates whether the server requires a password. + pub has_password: bool, + /// Indicates whether the server uses VAC. + pub vac_secured: bool, + /// Current round index. + pub round: u8, + /// Maximum amount of rounds. + pub rounds_maximum: u8, + /// Time left for the current round in seconds. + pub time_left: u16, +} + +impl CommonResponse for Response { + fn as_original(&self) -> GenericResponse { GenericResponse::FFOW(self) } + + fn name(&self) -> Option<&str> { Some(&self.name) } + fn game_mode(&self) -> Option<&str> { Some(&self.game_mode) } + fn description(&self) -> Option<&str> { Some(&self.description) } + fn game_version(&self) -> Option<&str> { Some(&self.game_version) } + fn map(&self) -> Option<&str> { Some(&self.map) } + fn has_password(&self) -> Option { Some(self.has_password) } + fn players_maximum(&self) -> u32 { self.players_maximum.into() } + fn players_online(&self) -> u32 { self.players_online.into() } +}