diff --git a/crates/lib/src/games/definitions.rs b/crates/lib/src/games/definitions.rs index 4ac3e8e..a1104c5 100644 --- a/crates/lib/src/games/definitions.rs +++ b/crates/lib/src/games/definitions.rs @@ -120,4 +120,5 @@ pub static GAMES: Map<&'static str, Game> = phf_map! { "redorchestra" => game!("Red Orchestra", 7759, Protocol::Unreal2), "unrealtournament2003" => game!("Unreal Tournament 2003", 7758, Protocol::Unreal2), "unrealtournament2004" => game!("Unreal Tournament 2004", 7778, Protocol::Unreal2), + "eco" => game!("Eco", 3000, Protocol::PROPRIETARY(ProprietaryProtocol::Eco)), }; diff --git a/crates/lib/src/games/eco/types.rs b/crates/lib/src/games/eco/types.rs index 043c382..04f7fbe 100644 --- a/crates/lib/src/games/eco/types.rs +++ b/crates/lib/src/games/eco/types.rs @@ -2,6 +2,9 @@ use serde_derive::Deserialize; use serde_derive::Serialize; use std::collections::HashMap; +use crate::protocols::types::CommonPlayer; +use crate::protocols::types::CommonResponse; + #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Root { @@ -94,6 +97,14 @@ pub struct Player { pub name: String, } +impl CommonPlayer for Player { + fn as_original(&self) -> crate::protocols::types::GenericPlayer { + crate::protocols::types::GenericPlayer::Eco(self) + } + + fn name(&self) -> &str { &self.name } +} + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, PartialEq)] pub struct Response { @@ -188,3 +199,19 @@ impl From for Response { } } } + +impl CommonResponse for Response { + fn as_original(&self) -> crate::protocols::GenericResponse { crate::protocols::GenericResponse::Eco(self) } + + fn players_online(&self) -> u32 { self.players_online } + + fn players_maximum(&self) -> u32 { self.players_maximum } + + fn description(&self) -> Option<&str> { Some(&self.description) } + + fn game_version(&self) -> Option<&str> { Some(&self.game_version) } + + fn has_password(&self) -> Option { Some(self.has_password) } + + fn players(&self) -> Option> { Some(self.players.iter().map(|p| p as _).collect()) } +} diff --git a/crates/lib/src/games/query.rs b/crates/lib/src/games/query.rs index d37cdd8..15fad33 100644 --- a/crates/lib/src/games/query.rs +++ b/crates/lib/src/games/query.rs @@ -4,11 +4,11 @@ use std::net::{IpAddr, SocketAddr}; use crate::games::types::Game; use crate::games::{ffow, jc2m, minecraft, savage2, theship}; -use crate::protocols; use crate::protocols::gamespy::GameSpyVersion; use crate::protocols::quake::QuakeVersion; use crate::protocols::types::{CommonResponse, ExtraRequestSettings, ProprietaryProtocol, Protocol, TimeoutSettings}; use crate::GDResult; +use crate::{eco, protocols}; /// Make a query given a game definition #[inline] @@ -111,6 +111,8 @@ pub fn query_with_timeout_and_extra_settings( } } } + #[cfg(feature = "serde")] + ProprietaryProtocol::Eco => eco::query_with_timeout(address, port, &timeout_settings).map(Box::new)?, } } }) diff --git a/crates/lib/src/protocols/types.rs b/crates/lib/src/protocols/types.rs index 182d594..fa09c73 100644 --- a/crates/lib/src/protocols/types.rs +++ b/crates/lib/src/protocols/types.rs @@ -19,6 +19,8 @@ pub enum ProprietaryProtocol { FFOW, JC2M, Savage2, + #[cfg(feature = "serde")] + Eco, } /// Enumeration of all valid protocol types @@ -51,6 +53,8 @@ pub enum GenericResponse<'a> { JC2M(&'a crate::games::jc2m::Response), #[cfg(feature = "games")] Savage2(&'a crate::games::savage2::Response), + #[cfg(all(feature = "games", feature = "serde"))] + Eco(&'a crate::games::eco::Response), } /// All player types @@ -68,6 +72,8 @@ pub enum GenericPlayer<'a> { TheShip(&'a crate::games::theship::TheShipPlayer), #[cfg(feature = "games")] JCMP2(&'a crate::games::jc2m::Player), + #[cfg(all(feature = "games", feature = "serde"))] + Eco(&'a crate::games::eco::Player), } pub trait CommonResponse {