mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
[Games] Generic query add support for GS2 protocol and Halo:CE game
This commit is contained in:
parent
e44a680a59
commit
a377b76a55
4 changed files with 41 additions and 2 deletions
|
|
@ -54,6 +54,7 @@ pub static GAMES: Map<&'static str, Game> = phf_map! {
|
|||
"ffow" => game!("Frontlines: Fuel of War", 5478, Protocol::FFOW),
|
||||
"gm" => game!("Garry's Mod", 27016, Protocol::Valve(SteamApp::GM)),
|
||||
"hl2dm" => game!("Half-Life 2 Deathmatch", 27015, Protocol::Valve(SteamApp::HL2DM)),
|
||||
"haloce" => game!("Halo: Combat Evolved", 2302, Protocol::Gamespy(GameSpyVersion::Two)),
|
||||
"hldms" => game!("Half-Life Deathmatch: Source", 27015, Protocol::Valve(SteamApp::HLDMS)),
|
||||
"hll" => game!("Hell Let Loose", 26420, Protocol::Valve(SteamApp::HLL)),
|
||||
"ins" => game!("Insurgency", 27015, Protocol::Valve(SteamApp::INS)),
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ pub fn query(game: &Game, address: &IpAddr, port: Option<u16>) -> GDResult<proto
|
|||
Protocol::Gamespy(version) => {
|
||||
match version {
|
||||
GameSpyVersion::One => protocols::gamespy::one::query(&socket_addr, None).map(|r| r.into())?,
|
||||
GameSpyVersion::Two => protocols::gamespy::two::query(&socket_addr, None).map(|r| r.into())?,
|
||||
GameSpyVersion::Three => protocols::gamespy::three::query(&socket_addr, None).map(|r| r.into())?,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,14 @@ pub use protocols::*;
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum GameSpyVersion {
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum VersionedExtraResponse {
|
||||
One(protocols::one::ExtraResponse),
|
||||
Three(protocols::three::ExtraResponse),
|
||||
One(one::ExtraResponse),
|
||||
Two(two::ExtraResponse),
|
||||
Three(three::ExtraResponse),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::protocols::gamespy::VersionedExtraResponse;
|
||||
use crate::protocols::types::SpecificResponse;
|
||||
use crate::protocols::GenericResponse;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -32,3 +35,35 @@ pub struct Response {
|
|||
pub players: Vec<Player>,
|
||||
pub unused_entries: HashMap<String, String>,
|
||||
}
|
||||
|
||||
/// Non-generic query response
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ExtraResponse {
|
||||
pub teams: Vec<Team>,
|
||||
pub players_minimum: Option<u8>,
|
||||
pub unused_entries: HashMap<String, String>,
|
||||
pub players: Vec<Player>,
|
||||
}
|
||||
|
||||
impl From<Response> for GenericResponse {
|
||||
fn from(r: Response) -> Self {
|
||||
Self {
|
||||
name: Some(r.name),
|
||||
description: None,
|
||||
game: None,
|
||||
game_version: None,
|
||||
map: Some(r.map),
|
||||
players_maximum: r.players_maximum.try_into().unwrap(), // FIXME: usize to u64 may fail
|
||||
players_online: r.players_online.try_into().unwrap(),
|
||||
players_bots: None,
|
||||
has_password: Some(r.has_password),
|
||||
inner: SpecificResponse::Gamespy(VersionedExtraResponse::Two(ExtraResponse {
|
||||
teams: r.teams,
|
||||
players_minimum: r.players_minimum,
|
||||
unused_entries: r.unused_entries,
|
||||
players: r.players,
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue