Skip to content

Commit

Permalink
Further removal
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminPerRam committed Oct 20, 2023
1 parent ed78ab8 commit 534c3b5
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 65 deletions.
5 changes: 3 additions & 2 deletions src/games/battalion1944.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::protocols::valve::Engine;
use crate::{
protocols::valve::{self, game, SteamApp},
protocols::valve::{self, game},
GDErrorKind::TypeParse,
GDResult,
};
Expand All @@ -8,7 +9,7 @@ use std::net::{IpAddr, SocketAddr};
pub fn query(address: &IpAddr, port: Option<u16>) -> GDResult<game::Response> {
let mut valve_response = valve::query(
&SocketAddr::new(*address, port.unwrap_or(7780)),
SteamApp::BATTALION1944.as_engine(),
Engine::new(489_940),
None,
None,
)?;
Expand Down
2 changes: 1 addition & 1 deletion src/games/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::protocols::{
gamespy::GameSpyVersion,
minecraft::{LegacyGroup, Server},
quake::QuakeVersion,
valve::SteamApp,
valve::Engine,
Protocol,
};
use crate::Game;
Expand Down
5 changes: 3 additions & 2 deletions src/games/theship.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
protocols::{
types::{CommonPlayer, CommonResponse, GenericPlayer, TimeoutSettings},
valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
valve::{self, get_optional_extracted_data, Server, ServerPlayer},
GenericResponse,
},
GDErrorKind::PacketBad,
Expand All @@ -11,6 +11,7 @@ use std::net::{IpAddr, SocketAddr};

use std::collections::HashMap;

use crate::protocols::valve::Engine;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -136,7 +137,7 @@ pub fn query_with_timeout(
) -> GDResult<Response> {
let valve_response = valve::query(
&SocketAddr::new(*address, port.unwrap_or(27015)),
SteamApp::THESHIP.as_engine(),
Engine::new(2400),
None,
timeout_settings,
)?;
Expand Down
141 changes: 98 additions & 43 deletions src/games/valve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,121 @@
use crate::protocols::valve::game_query_mod;

game_query_mod!(a2oa, "ARMA 2: Operation Arrowhead", A2OA, 2304);
game_query_mod!(alienswarm, "Alien Swarm", ALIENSWARM, 27015);
game_query_mod!(aoc, "Age of Chivalry", AOC, 27015);
game_query_mod!(ase, "ARK: Survival Evolved", ASE, 27015);
game_query_mod!(asrd, "Alien Swarm: Reactive Drop", ASRD, 2304);
game_query_mod!(avorion, "Avorion", AVORION, 27020);
game_query_mod!(
a2oa,
"ARMA 2: Operation Arrowhead",
Engine::new(33930),
2304
);
game_query_mod!(alienswarm, "Alien Swarm", Engine::new(630), 27015);
game_query_mod!(aoc, "Age of Chivalry", Engine::new(17510), 27015);
game_query_mod!(ase, "ARK: Survival Evolved", Engine::new(346_110), 27015);
game_query_mod!(
asrd,
"Alien Swarm: Reactive Drop",
Engine::new(563_560),
2304
);
game_query_mod!(avorion, "Avorion", Engine::new(445_220), 27020);
game_query_mod!(
ballisticoverkill,
"Ballistic Overkill",
BALLISTICOVERKILL,
Engine::new(296_300),
27016
);
game_query_mod!(barotrauma, "Barotrauma", BAROTRAUMA, 27016);
game_query_mod!(blackmesa, "Black Mesa", BLACKMESA, 27015);
game_query_mod!(brainbread2, "BrainBread 2", BRAINBREAD2, 27015);
game_query_mod!(codenamecure, "Codename CURE", CODENAMECURE, 27015);
game_query_mod!(colonysurvival, "Colony Survival", COLONYSURVIVAL, 27004);
game_query_mod!(counterstrike, "Counter-Strike", COUNTERSTRIKE, 27015);
game_query_mod!(creativerse, "Creativerse", CREATIVERSE, 26901);
game_query_mod!(cscz, "Counter Strike: Condition Zero", CSCZ, 27015);
game_query_mod!(csgo, "Counter-Strike: Global Offensive", CSGO, 27015);
game_query_mod!(css, "Counter-Strike: Source", CSS, 27015);
game_query_mod!(dod, "Day of Defeat", DOD, 27015);
game_query_mod!(dods, "Day of Defeat: Source", DODS, 27015);
game_query_mod!(doi, "Day of Infamy", DOI, 27015);
game_query_mod!(dst, "Don't Starve Together", DST, 27016);
game_query_mod!(garrysmod, "Garry's Mod", GARRYSMOD, 27016);
game_query_mod!(hl2d, "Half-Life 2 Deathmatch", HL2D, 27015);
game_query_mod!(hlds, "Half-Life Deathmatch: Source", HLDS, 27015);
game_query_mod!(hll, "Hell Let Loose", HLL, 26420);
game_query_mod!(imic, "Insurgency: Modern Infantry Combat", IMIC, 27015);
game_query_mod!(insurgency, "Insurgency", INSURGENCY, 27015);
game_query_mod!(barotrauma, "Barotrauma", Engine::new(602_960), 27016);
game_query_mod!(blackmesa, "Black Mesa", Engine::new(362_890), 27015);
game_query_mod!(brainbread2, "BrainBread 2", Engine::new(346_330), 27015);
game_query_mod!(codenamecure, "Codename CURE", Engine::new(355_180), 27015);
game_query_mod!(
colonysurvival,
"Colony Survival",
Engine::new(366_090),
27004
);
game_query_mod!(
counterstrike,
"Counter-Strike",
Engine::new_goldSrc(false),
27015
);
game_query_mod!(creativerse, "Creativerse", Engine::new(280_790), 26901);
game_query_mod!(
cscz,
"Counter Strike: Condition Zero",
Engine::new_goldSrc(false),
27015
);
game_query_mod!(
csgo,
"Counter-Strike: Global Offensive",
Engine::new(730),
27015
);
game_query_mod!(css, "Counter-Strike: Source", Engine::new(240), 27015);
game_query_mod!(dod, "Day of Defeat", Engine::new_goldSrc(false), 27015);
game_query_mod!(dods, "Day of Defeat: Source", Engine::new(300), 27015);
game_query_mod!(doi, "Day of Infamy", Engine::new(447_820), 27015);
game_query_mod!(dst, "Don't Starve Together", Engine::new(322_320), 27016);
game_query_mod!(garrysmod, "Garry's Mod", Engine::new(4000), 27016);
game_query_mod!(hl2d, "Half-Life 2 Deathmatch", Engine::new(320), 27015);
game_query_mod!(
hlds,
"Half-Life Deathmatch: Source",
Engine::new(360),
27015
);
game_query_mod!(hll, "Hell Let Loose", Engine::new(686_810), 26420);
game_query_mod!(
imic,
"Insurgency: Modern Infantry Combat",
Engine::new(17700),
27015
);
game_query_mod!(insurgency, "Insurgency", Engine::new(222_880), 27015);
game_query_mod!(
insurgencysandstorm,
"Insurgency: Sandstorm",
INSURGENCYSANDSTORM,
Engine::new(581_320),
27131
);
game_query_mod!(left4dead, "Left 4 Dead", LEFT4DEAD, 27015);
game_query_mod!(left4dead2, "Left 4 Dead 2", LEFT4DEAD2, 27015);
game_query_mod!(ohd, "Operation: Harsh Doorstop", OHD, 27005);
game_query_mod!(onset, "Onset", ONSET, 7776);
game_query_mod!(projectzomboid, "Project Zomboid", PROJECTZOMBOID, 16261);
game_query_mod!(ror2, "Risk of Rain 2", ROR2, 27016);
game_query_mod!(rust, "Rust", RUST, 27015);
game_query_mod!(sco, "Sven Co-op", SCO, 27015);
game_query_mod!(sd2d, "7 Days To Die", SD2D, 26900);
game_query_mod!(teamfortress2, "Team Fortress 2", TEAMFORTRESS2, 27015);
game_query_mod!(tfc, "Team Fortress Classic", TFC, 27015);
game_query_mod!(theforest, "The Forest", THEFOREST, 27016);
game_query_mod!(unturned, "Unturned", UNTURNED, 27015);
game_query_mod!(left4dead, "Left 4 Dead", Engine::new(500), 27015);
game_query_mod!(left4dead2, "Left 4 Dead 2", Engine::new(550), 27015);
game_query_mod!(
ohd,
"Operation: Harsh Doorstop",
Engine::new_with_dedicated(736_590, 950_900),
27005
);
game_query_mod!(onset, "Onset", Engine::new(1_105_810), 7776);
game_query_mod!(
projectzomboid,
"Project Zomboid",
Engine::new(108_600),
16261
);
game_query_mod!(ror2, "Risk of Rain 2", Engine::new(632_360), 27016);
game_query_mod!(rust, "Rust", Engine::new(252_490), 27015);
game_query_mod!(sco, "Sven Co-op", Engine::new_goldSrc(false), 27015);
game_query_mod!(sd2d, "7 Days To Die", Engine::new(251_570), 26900);
game_query_mod!(teamfortress2, "Team Fortress 2", Engine::new(440), 27015);
game_query_mod!(
tfc,
"Team Fortress Classic",
Engine::new_goldSrc(false),
27015
);
game_query_mod!(theforest, "The Forest", Engine::new(556_450), 27016);
game_query_mod!(unturned, "Unturned", Engine::new(304_930), 27015);
game_query_mod!(
valheim,
"Valheim",
VALHEIM,
Engine::new(892_970),
2457,
GatheringSettings {
players: true,
rules: false,
check_app_id: true,
}
);
game_query_mod!(vrising, "V Rising", VRISING, 27016);
game_query_mod!(vrising, "V Rising", Engine::new(1_604_030), 27016);
2 changes: 1 addition & 1 deletion src/protocols/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Protocol {
Gamespy(gamespy::GameSpyVersion),
Minecraft(Option<minecraft::types::Server>),
Quake(quake::QuakeVersion),
Valve(valve::SteamApp),
Valve(valve::Engine),
#[cfg(feature = "games")]
PROPRIETARY(ProprietaryProtocol),
}
Expand Down
20 changes: 10 additions & 10 deletions src/protocols/valve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ pub use types::*;
/// documentation for the created module.
/// * `steam_app`, `default_port` - Passed through to [game_query_fn].
macro_rules! game_query_mod {
($mod_name: ident, $pretty_name: expr, $steam_app: ident, $default_port: literal) => {
($mod_name: ident, $pretty_name: expr, $engine: expr, $default_port: literal) => {
crate::protocols::valve::game_query_mod!(
$mod_name,
$pretty_name,
$steam_app,
$engine,
$default_port,
GatheringSettings::default()
);
};

($mod_name: ident, $pretty_name: expr, $steam_app: ident, $default_port: literal, $gathering_settings: expr) => {
($mod_name: ident, $pretty_name: expr, $engine: expr, $default_port: literal, $gathering_settings: expr) => {
#[doc = $pretty_name]
pub mod $mod_name {
use crate::protocols::valve::GatheringSettings;
use crate::protocols::valve::{Engine, GatheringSettings};

crate::protocols::valve::game_query_fn!($steam_app, $default_port, $gathering_settings);
crate::protocols::valve::game_query_fn!($pretty_name, $engine, $default_port, $gathering_settings);
}
};
}
Expand All @@ -48,19 +48,19 @@ pub(crate) use game_query_mod;
/// game_query_fn!(TEAMFORTRESS2, 27015);
/// ```
macro_rules! game_query_fn {
($steam_app: ident, $default_port: literal, $gathering_settings: expr) => {
($pretty_name: expr, $engine: expr, $default_port: literal, $gathering_settings: expr) => {
// TODO: By using $gathering_settings, also add to doc if a game doesnt respond to certain gathering settings
crate::protocols::valve::game_query_fn!{@gen $steam_app, $default_port, concat!(
"Make a valve query for ", stringify!($steam_app), " with default timeout settings and default extra request settings.\n\n",
crate::protocols::valve::game_query_fn!{@gen $engine, $default_port, concat!(
"Make a valve query for ", $pretty_name, " with default timeout settings and default extra request settings.\n\n",
"If port is `None`, then the default port (", stringify!($default_port), ") will be used."), $gathering_settings}
};

(@gen $steam_app: ident, $default_port: literal, $doc: expr, $gathering_settings: expr) => {
(@gen $engine: expr, $default_port: literal, $doc: expr, $gathering_settings: expr) => {
#[doc = $doc]
pub fn query(address: &std::net::IpAddr, port: Option<u16>) -> crate::GDResult<crate::protocols::valve::game::Response> {
let valve_response = crate::protocols::valve::query(
&std::net::SocketAddr::new(*address, port.unwrap_or($default_port)),
crate::protocols::valve::SteamApp::$steam_app.as_engine(),
$engine,
Some($gathering_settings),
None,
)?;
Expand Down
13 changes: 7 additions & 6 deletions src/protocols/valve/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl SplitPacket {
Engine::Source(_) => {
let total = buffer.read()?;
let number = buffer.read()?;
let size = match protocol == 7 && (*engine == SteamApp::CSS.as_engine()) {
// certain apps with protocol = 7 dont have this field
let size = match protocol == 7 && (*engine == Engine::new(240)) {
// certain apps with protocol = 7 dont have this field, such as CSS
false => buffer.read()?,
true => 1248,
};
Expand Down Expand Up @@ -303,7 +303,7 @@ impl ValveProtocol {
let environment_type = Environment::from_gldsrc(buffer.read()?)?;
let has_password = buffer.read::<u8>()? == 1;
let vac_secured = buffer.read::<u8>()? == 1;
let the_ship = match *engine == SteamApp::THESHIP.as_engine() {
let the_ship = match *engine == Engine::new(2400) {
false => None,
true => {
Some(TheShip {
Expand Down Expand Up @@ -388,11 +388,11 @@ impl ValveProtocol {
name: buffer.read_string::<Utf8Decoder>(None)?,
score: buffer.read()?,
duration: buffer.read()?,
deaths: match *engine == SteamApp::THESHIP.as_engine() {
deaths: match *engine == Engine::new(2400) {
false => None,
true => Some(buffer.read()?),
},
money: match *engine == SteamApp::THESHIP.as_engine() {
money: match *engine == Engine::new(2400) {
false => None,
true => Some(buffer.read()?),
},
Expand All @@ -417,7 +417,8 @@ impl ValveProtocol {
rules.insert(name, value);
}

if *engine == SteamApp::ROR2.as_engine() {
if *engine == Engine::new(632_360) {
// ROR2
rules.remove("Test");
}

Expand Down

0 comments on commit 534c3b5

Please sign in to comment.