[Protocol] Add PROPRIETARY to protocol enumeration (#59)

* [Protocol] Add CUSTOM to protocol enumeration

* [Protocol] Rename CUSTOM to PROPRIETARY

* [Protocol] Rename struct to ProprietaryProtocol and do the same thing to generic response

* [Protocol] Revert proprietary change on generic response
This commit is contained in:
CosminPerRam 2023-06-26 23:52:40 +03:00 committed by GitHub
parent b368877031
commit c55254aaf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View file

@ -9,6 +9,7 @@ use crate::protocols::{
}; };
use crate::Game; use crate::Game;
use crate::protocols::types::ProprietaryProtocol;
use phf::{phf_map, Map}; use phf::{phf_map, Map};
macro_rules! game { macro_rules! game {
@ -51,7 +52,7 @@ pub static GAMES: Map<&'static str, Game> = phf_map! {
"dods" => game!("Day of Defeat: Source", 27015, Protocol::Valve(SteamApp::DODS)), "dods" => game!("Day of Defeat: Source", 27015, Protocol::Valve(SteamApp::DODS)),
"doi" => game!("Day of Infamy", 27015, Protocol::Valve(SteamApp::DOI)), "doi" => game!("Day of Infamy", 27015, Protocol::Valve(SteamApp::DOI)),
"dst" => game!("Don't Starve Together", 27016, Protocol::Valve(SteamApp::DST)), "dst" => game!("Don't Starve Together", 27016, Protocol::Valve(SteamApp::DST)),
"ffow" => game!("Frontlines: Fuel of War", 5478, Protocol::FFOW), "ffow" => game!("Frontlines: Fuel of War", 5478, Protocol::PROPRIETARY(ProprietaryProtocol::FFOW)),
"gm" => game!("Garry's Mod", 27016, Protocol::Valve(SteamApp::GM)), "gm" => game!("Garry's Mod", 27016, Protocol::Valve(SteamApp::GM)),
"hl2dm" => game!("Half-Life 2 Deathmatch", 27015, Protocol::Valve(SteamApp::HL2DM)), "hl2dm" => game!("Half-Life 2 Deathmatch", 27015, Protocol::Valve(SteamApp::HL2DM)),
"haloce" => game!("Halo: Combat Evolved", 2302, Protocol::Gamespy(GameSpyVersion::Two)), "haloce" => game!("Halo: Combat Evolved", 2302, Protocol::Gamespy(GameSpyVersion::Two)),
@ -77,9 +78,9 @@ pub static GAMES: Map<&'static str, Game> = phf_map! {
"tf" => game!("The Forest", 27016, Protocol::Valve(SteamApp::TF)), "tf" => game!("The Forest", 27016, Protocol::Valve(SteamApp::TF)),
"tf2" => game!("Team Fortress 2", 27015, Protocol::Valve(SteamApp::TF2)), "tf2" => game!("Team Fortress 2", 27015, Protocol::Valve(SteamApp::TF2)),
"tfc" => game!("Team Fortress Classic", 27015, Protocol::Valve(SteamApp::TFC)), "tfc" => game!("Team Fortress Classic", 27015, Protocol::Valve(SteamApp::TFC)),
"ts" => game!("The Ship", 27015, Protocol::TheShip), "ts" => game!("The Ship", 27015, Protocol::PROPRIETARY(ProprietaryProtocol::TheShip)),
"unturned" => game!("Unturned", 27015, Protocol::Valve(SteamApp::UNTURNED)), "unturned" => game!("Unturned", 27015, Protocol::Valve(SteamApp::UNTURNED)),
"ut" => game!("Unreal Tournament", 7778, Protocol::Gamespy(GameSpyVersion::One)), "ut" => game!("Unreal Tournament", 7778, Protocol::Gamespy(GameSpyVersion::One)),
"vr" => game!("V Rising", 27016, Protocol::Valve(SteamApp::VR)), "vr" => game!("V Rising", 27016, Protocol::Valve(SteamApp::VR)),
"jc2mp" => game!("Just Cause 2: Multiplayer", 7777, Protocol::JC2MP), "jc2mp" => game!("Just Cause 2: Multiplayer", 7777, Protocol::PROPRIETARY(ProprietaryProtocol::JC2MP)),
}; };

View file

@ -114,7 +114,7 @@ pub mod vr;
use crate::protocols::gamespy::GameSpyVersion; use crate::protocols::gamespy::GameSpyVersion;
use crate::protocols::quake::QuakeVersion; use crate::protocols::quake::QuakeVersion;
use crate::protocols::types::CommonResponse; use crate::protocols::types::{CommonResponse, ProprietaryProtocol};
use crate::protocols::{self, Protocol}; use crate::protocols::{self, Protocol};
use crate::GDResult; use crate::GDResult;
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
@ -172,8 +172,12 @@ pub fn query(game: &Game, address: &IpAddr, port: Option<u16>) -> GDResult<Box<d
QuakeVersion::Three => protocols::quake::three::query(&socket_addr, None).map(Box::new)?, QuakeVersion::Three => protocols::quake::three::query(&socket_addr, None).map(Box::new)?,
} }
} }
Protocol::TheShip => ts::query(address, port).map(Box::new)?, Protocol::PROPRIETARY(protocol) => {
Protocol::FFOW => ffow::query(address, port).map(Box::new)?, match protocol {
Protocol::JC2MP => jc2mp::query(address, port).map(Box::new)?, ProprietaryProtocol::TheShip => ts::query(address, port).map(Box::new)?,
ProprietaryProtocol::FFOW => ffow::query(address, port).map(Box::new)?,
ProprietaryProtocol::JC2MP => jc2mp::query(address, port).map(Box::new)?,
}
}
}) })
} }

View file

@ -6,6 +6,15 @@ use std::time::Duration;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Enumeration of all custom protocols
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub enum ProprietaryProtocol {
TheShip,
FFOW,
JC2MP,
}
/// Enumeration of all valid protocol types /// Enumeration of all valid protocol types
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -15,10 +24,7 @@ pub enum Protocol {
Quake(quake::QuakeVersion), Quake(quake::QuakeVersion),
Valve(valve::SteamApp), Valve(valve::SteamApp),
#[cfg(not(feature = "no_games"))] #[cfg(not(feature = "no_games"))]
TheShip, PROPRIETARY(ProprietaryProtocol),
#[cfg(not(feature = "no_games"))]
FFOW,
JC2MP,
} }
/// All response types /// All response types