mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 07:17:27 +00:00
eco: Add generic impls
This commit is contained in:
parent
723f2f5a06
commit
d7aee90c25
4 changed files with 37 additions and 1 deletions
|
|
@ -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)),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<Root> 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<bool> { Some(self.has_password) }
|
||||
|
||||
fn players(&self) -> Option<Vec<&dyn CommonPlayer>> { Some(self.players.iter().map(|p| p as _).collect()) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)?,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue