Skip to content

Commit

Permalink
Merge branch 'main' into feat/protocol-unreal2
Browse files Browse the repository at this point in the history
  • Loading branch information
Douile committed Oct 28, 2023
2 parents 7dc6ea0 + e3dd7cd commit 2e17bc2
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 296 deletions.
2 changes: 1 addition & 1 deletion .github/badges/node.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ Who knows what the future holds...

# 0.X.Y - DD/MM/YYYY
### Changes:
Nothing yet.
- Added [Valheim](https://store.steampowered.com/app/892970/Valheim/) support.

### Breaking:
None, yaay!
Game:
- Changed identifications of the following games as they weren't properly expecting the naming rules:
- - Left 4 Dead: `left4dead` -> `l4d`.
- - 7 Days to Die: `7d2d` in definitions and `sd2d` in game declaration -> `sdtd`.
- - Quake 3 Arena: `quake3arena` -> `q3a`.

Protocols:
- Valve: Removed `SteamApp` due to it not being really useful at all, replaced all instances with `Engine`.

# 0.4.1 - 13/10/2023
### Changes:
Expand Down
29 changes: 17 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,23 @@ and 2017 would be `swb22017`).
(`Day of Defeat` -> `dod`), then the new name should ignore rule #2
(`Day of Dragons` -> `dayofdragons`).
5. Roman numbering will be converted to arabic numbering (`XIV` -> `14`).
6. Unless numbers are at the end of a name, they will be considered words,
but digits will always be used instead of the acronym (counter to #2) (`Left 4
Dead` -> `l4d`) unless they at the start position (`7 Days to Die` -> `sdtd`),
if they are at the end (such as sequel number or the year), always append them
(`Team Fortress 2` -> `teamfortress2`, `Unreal Tournament 2003` ->
`unrealtournament2003`).
7. If a game supports multiple protocols, multiple entries will be done for
said game where the edition/protocol name (first disposable in this order) will
be appended to the game name (Minecraft is divided by 2 editions, Java and Bedrock
which will be `minecraftjava` and `minecraftbedrock` respectively) and one more
entry can be added by the base name of the game which queries in a group said
supported protocols to make generic queries easier and disposable.
6. Unless numbers (years included) are at the end of a name, they will be considered
words. If a number is not in the first position, its entire numeric digits will be
used instead of the acronym of that number's digits (`Left 4 Dead` -> `l4d`). If the
number is in the first position the longhand (words: 5 -> five) representation of the
number will be used to create an acronym (`7 Days to Die` -> `sdtd`). Other examples:
`Team Fortress 2` -> `teamfortress2`, `Unreal Tournament 2003` ->
`unrealtournament2003`.
7. If a game supports multiple protocols, multiple entries will be done for said game
where the edition/protocol name (first disposable in this order) will be appended to
the base game id's: `<game_id><protocol_id>` (where the protocol id will follow all
rules except #2) (Minecraft is mainly divided by 2 editions, Java and Bedrock
which will be `minecraftjava` and `minecraftbedrock` respectively, but it also has
legacy versions, which use another protocol, an example would be the one for `1.6`,
so the name would be `Legacy 1.6` which its id will be `legacy16`, resulting in the
entry of `minecraftlegacy16`). One more entry can be added by the base name of the
game, which queries in a group said supported protocols to make generic queries
easier and disposable.
8. If its actually about a mod that adds the ability for queries to be performed,
process only the mod name.

Expand Down
1 change: 1 addition & 0 deletions GAMES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Beware of the `Notes` column, as it contains information about query port offset
| Creativerse | CREATIVERSE | Valve | Query Port offset: 1. |
| Garry's Mod | GARRYSMOD | Valve | |
| Barotrauma | BAROTRAUMA | Valve | Query Port offset: 1. |
| Valheim | VALHEIM | Valve | Query Port offset: 1. Does not respond to the A2S rules. |

## Planned to add support:
_
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ Curious about the history and what changed between versions? Everything is in th

## Contributing
If you want to see your favorite game/service being supported here, open an issue, and I'll prioritize it (or do a pull request if you want to implement it yourself)!

Before contributing please read [CONTRIBUTING](CONTRIBUTING.md).
32 changes: 19 additions & 13 deletions examples/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ use gamedig::{
protocols::types::{CommonResponse, ExtraRequestSettings, TimeoutSettings},
query_with_timeout_and_extra_settings,
GDResult,
Game,
GAMES,
};

use std::net::{IpAddr, SocketAddr, ToSocketAddrs};

/// Make a query given the name of a game
/// The `game` argument is taken from the [GAMES](gamedig::GAMES) map.
fn generic_query(
game_name: &str,
game: &Game,
addr: &IpAddr,
port: Option<u16>,
timeout_settings: Option<TimeoutSettings>,
extra_settings: Option<ExtraRequestSettings>,
) -> GDResult<Box<dyn CommonResponse>> {
let game = GAMES
.get(game_name)
.expect("Game doesn't exist, run without arguments to see a list of games");

println!("Querying {:#?} with game {:#?}.", addr, game);

let response = query_with_timeout_and_extra_settings(game, addr, port, timeout_settings, extra_settings)?;
Expand Down Expand Up @@ -51,14 +49,18 @@ fn main() {
)
.unwrap();

let extra_settings = ExtraRequestSettings::default()
let game = GAMES
.get(&game_name)
.expect("Game doesn't exist, run without arguments to see a list of games");

let extra_settings = game
.request_settings
.clone()
.set_hostname(hostname.to_string())
.set_gather_rules(true)
.set_gather_players(true)
.set_check_app_id(false);

generic_query(
&game_name,
game,
&addr.ip(),
port,
Some(timeout_settings),
Expand All @@ -67,8 +69,7 @@ fn main() {
.unwrap();
} else {
// Without arguments print a list of games

for (name, game) in gamedig::games::GAMES.entries() {
for (name, game) in GAMES.entries() {
println!("{}\t{}", name, game.name);
}
}
Expand All @@ -95,7 +96,12 @@ mod test {
)
.unwrap(),
);
assert!(generic_query(game_name, &ADDR, None, timeout_settings, None).is_err());

let game = GAMES
.get(game_name)
.expect("Game doesn't exist, run without arguments to see a list of games");

assert!(generic_query(game, &ADDR, None, timeout_settings, None).is_err());
}

#[test]
Expand All @@ -108,7 +114,7 @@ mod test {
fn teamfortress2() { test_game("teamfortress2"); }

#[test]
fn quake() { test_game("quake3"); }
fn quake2() { test_game("quake2"); }

#[test]
fn all_games() {
Expand Down
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
106 changes: 61 additions & 45 deletions src/games/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ use crate::protocols::{
gamespy::GameSpyVersion,
minecraft::{LegacyGroup, Server},
quake::QuakeVersion,
valve::SteamApp,
valve::Engine,
Protocol,
};
use crate::Game;

use crate::protocols::types::ProprietaryProtocol;
use crate::protocols::valve::GatheringSettings;
use phf::{phf_map, Map};

macro_rules! game {
($name: literal, $default_port: literal, $protocol: expr) => {
game!(
$name,
$default_port,
$protocol,
GatheringSettings::default().into_extra()
)
};

($name: literal, $default_port: literal, $protocol: expr, $extra_request_settings: expr) => {
Game {
name: $name,
default_port: $default_port,
protocol: $protocol,
request_settings: $extra_request_settings,
}
};
}
Expand All @@ -33,60 +44,65 @@ pub static GAMES: Map<&'static str, Game> = phf_map! {
"minecraftlegacy16" => game!("Minecraft (legacy v1.6)", 25565, Protocol::Minecraft(Some(Server::Legacy(LegacyGroup::V1_6)))),
"minecraftlegacy15" => game!("Minecraft (legacy v1.4-1.5)", 25565, Protocol::Minecraft(Some(Server::Legacy(LegacyGroup::V1_5)))),
"minecraftlegacy13" => game!("Minecraft (legacy vB1.8-1.3)", 25565, Protocol::Minecraft(Some(Server::Legacy(LegacyGroup::V1_3)))),
"alienswarm" => game!("Alien Swarm", 27015, Protocol::Valve(SteamApp::ALIENSWARM)),
"aoc" => game!("Age of Chivalry", 27015, Protocol::Valve(SteamApp::AOC)),
"a2oa" => game!("ARMA 2: Operation Arrowhead", 2304, Protocol::Valve(SteamApp::A2OA)),
"ase" => game!("ARK: Survival Evolved", 27015, Protocol::Valve(SteamApp::ASE)),
"asrd" => game!("Alien Swarm: Reactive Drop", 2304, Protocol::Valve(SteamApp::ASRD)),
"avorion" => game!("Avorion", 27020, Protocol::Valve(SteamApp::AVORION)),
"barotrauma" => game!("Barotrauma", 27016, Protocol::Valve(SteamApp::BAROTRAUMA)),
"battalion1944" => game!("Battalion 1944", 7780, Protocol::Valve(SteamApp::BATTALION1944)),
"brainbread2" => game!("BrainBread 2", 27015, Protocol::Valve(SteamApp::BRAINBREAD2)),
"alienswarm" => game!("Alien Swarm", 27015, Protocol::Valve(Engine::new(630))),
"aoc" => game!("Age of Chivalry", 27015, Protocol::Valve(Engine::new(17510))),
"a2oa" => game!("ARMA 2: Operation Arrowhead", 2304, Protocol::Valve(Engine::new(33930))),
"ase" => game!("ARK: Survival Evolved", 27015, Protocol::Valve(Engine::new(346_110))),
"asrd" => game!("Alien Swarm: Reactive Drop", 2304, Protocol::Valve(Engine::new(563_560))),
"avorion" => game!("Avorion", 27020, Protocol::Valve(Engine::new(445_220))),
"barotrauma" => game!("Barotrauma", 27016, Protocol::Valve(Engine::new(602_960))),
"battalion1944" => game!("Battalion 1944", 7780, Protocol::Valve(Engine::new(489_940))),
"brainbread2" => game!("BrainBread 2", 27015, Protocol::Valve(Engine::new(346_330))),
"battlefield1942" => game!("Battlefield 1942", 23000, Protocol::Gamespy(GameSpyVersion::One)),
"blackmesa" => game!("Black Mesa", 27015, Protocol::Valve(SteamApp::BLACKMESA)),
"ballisticoverkill" => game!("Ballistic Overkill", 27016, Protocol::Valve(SteamApp::BALLISTICOVERKILL)),
"codenamecure" => game!("Codename CURE", 27015, Protocol::Valve(SteamApp::CODENAMECURE)),
"colonysurvival" => game!("Colony Survival", 27004, Protocol::Valve(SteamApp::COLONYSURVIVAL)),
"counterstrike" => game!("Counter-Strike", 27015, Protocol::Valve(SteamApp::COUNTERSTRIKE)),
"cscz" => game!("Counter Strike: Condition Zero", 27015, Protocol::Valve(SteamApp::CSCZ)),
"csgo" => game!("Counter-Strike: Global Offensive", 27015, Protocol::Valve(SteamApp::CSGO)),
"css" => game!("Counter-Strike: Source", 27015, Protocol::Valve(SteamApp::CSS)),
"creativerse" => game!("Creativerse", 26901, Protocol::Valve(SteamApp::CREATIVERSE)),
"blackmesa" => game!("Black Mesa", 27015, Protocol::Valve(Engine::new(362_890))),
"ballisticoverkill" => game!("Ballistic Overkill", 27016, Protocol::Valve(Engine::new(296_300))),
"codenamecure" => game!("Codename CURE", 27015, Protocol::Valve(Engine::new(355_180))),
"colonysurvival" => game!("Colony Survival", 27004, Protocol::Valve(Engine::new(366_090))),
"counterstrike" => game!("Counter-Strike", 27015, Protocol::Valve(Engine::new_gold_src(false))),
"cscz" => game!("Counter Strike: Condition Zero", 27015, Protocol::Valve(Engine::new_gold_src(false))),
"csgo" => game!("Counter-Strike: Global Offensive", 27015, Protocol::Valve(Engine::new(730))),
"css" => game!("Counter-Strike: Source", 27015, Protocol::Valve(Engine::new(240))),
"creativerse" => game!("Creativerse", 26901, Protocol::Valve(Engine::new(280_790))),
"crysiswars" => game!("Crysis Wars", 64100, Protocol::Gamespy(GameSpyVersion::Three)),
"dod" => game!("Day of Defeat", 27015, Protocol::Valve(SteamApp::DOD)),
"dods" => game!("Day of Defeat: Source", 27015, Protocol::Valve(SteamApp::DODS)),
"doi" => game!("Day of Infamy", 27015, Protocol::Valve(SteamApp::DOI)),
"dst" => game!("Don't Starve Together", 27016, Protocol::Valve(SteamApp::DST)),
"dod" => game!("Day of Defeat", 27015, Protocol::Valve(Engine::new_gold_src(false))),
"dods" => game!("Day of Defeat: Source", 27015, Protocol::Valve(Engine::new(300))),
"doi" => game!("Day of Infamy", 27015, Protocol::Valve(Engine::new(447_820))),
"dst" => game!("Don't Starve Together", 27016, Protocol::Valve(Engine::new(322_320))),
"ffow" => game!("Frontlines: Fuel of War", 5478, Protocol::PROPRIETARY(ProprietaryProtocol::FFOW)),
"garrysmod" => game!("Garry's Mod", 27016, Protocol::Valve(SteamApp::GARRYSMOD)),
"hl2d" => game!("Half-Life 2 Deathmatch", 27015, Protocol::Valve(SteamApp::HL2D)),
"garrysmod" => game!("Garry's Mod", 27016, Protocol::Valve(Engine::new(4000))),
"hl2d" => game!("Half-Life 2 Deathmatch", 27015, Protocol::Valve(Engine::new(320))),
"hce" => game!("Halo: Combat Evolved", 2302, Protocol::Gamespy(GameSpyVersion::Two)),
"hlds" => game!("Half-Life Deathmatch: Source", 27015, Protocol::Valve(SteamApp::HLDS)),
"hll" => game!("Hell Let Loose", 26420, Protocol::Valve(SteamApp::HLL)),
"insurgency" => game!("Insurgency", 27015, Protocol::Valve(SteamApp::INSURGENCY)),
"imic" => game!("Insurgency: Modern Infantry Combat", 27015, Protocol::Valve(SteamApp::IMIC)),
"insurgencysandstorm" => game!("Insurgency: Sandstorm", 27131, Protocol::Valve(SteamApp::INSURGENCYSANDSTORM)),
"left4dead" => game!("Left 4 Dead", 27015, Protocol::Valve(SteamApp::LEFT4DEAD)),
"left4dead2" => game!("Left 4 Dead 2", 27015, Protocol::Valve(SteamApp::LEFT4DEAD2)),
"ohd" => game!("Operation: Harsh Doorstop", 27005, Protocol::Valve(SteamApp::OHD)),
"onset" => game!("Onset", 7776, Protocol::Valve(SteamApp::ONSET)),
"projectzomboid" => game!("Project Zomboid", 16261, Protocol::Valve(SteamApp::PROJECTZOMBOID)),
"hlds" => game!("Half-Life Deathmatch: Source", 27015, Protocol::Valve(Engine::new(360))),
"hll" => game!("Hell Let Loose", 26420, Protocol::Valve(Engine::new(686_810))),
"insurgency" => game!("Insurgency", 27015, Protocol::Valve(Engine::new(222_880))),
"imic" => game!("Insurgency: Modern Infantry Combat", 27015, Protocol::Valve(Engine::new(17700))),
"insurgencysandstorm" => game!("Insurgency: Sandstorm", 27131, Protocol::Valve(Engine::new(581_320))),
"l4d" => game!("Left 4 Dead", 27015, Protocol::Valve(Engine::new(500))),
"l4d2" => game!("Left 4 Dead 2", 27015, Protocol::Valve(Engine::new(550))),
"ohd" => game!("Operation: Harsh Doorstop", 27005, Protocol::Valve(Engine::new_with_dedicated(736_590, 950_900))),
"onset" => game!("Onset", 7776, Protocol::Valve(Engine::new(1_105_810))),
"projectzomboid" => game!("Project Zomboid", 16261, Protocol::Valve(Engine::new(108_600))),
"quake1" => game!("Quake 1", 27500, Protocol::Quake(QuakeVersion::One)),
"quake2" => game!("Quake 2", 27910, Protocol::Quake(QuakeVersion::Two)),
"quake3" => game!("Quake 3: Arena", 27960, Protocol::Quake(QuakeVersion::Three)),
"ror2" => game!("Risk of Rain 2", 27016, Protocol::Valve(SteamApp::ROR2)),
"rust" => game!("Rust", 27015, Protocol::Valve(SteamApp::RUST)),
"sco" => game!("Sven Co-op", 27015, Protocol::Valve(SteamApp::SCO)),
"7d2d" => game!("7 Days To Die", 26900, Protocol::Valve(SteamApp::SD2D)),
"q3a" => game!("Quake 3 Arena", 27960, Protocol::Quake(QuakeVersion::Three)),
"ror2" => game!("Risk of Rain 2", 27016, Protocol::Valve(Engine::new(632_360))),
"rust" => game!("Rust", 27015, Protocol::Valve(Engine::new(252_490))),
"sco" => game!("Sven Co-op", 27015, Protocol::Valve(Engine::new_gold_src(false))),
"sdtd" => game!("7 Days to Die", 26900, Protocol::Valve(Engine::new(251_570))),
"sof2" => game!("Soldier of Fortune 2", 20100, Protocol::Quake(QuakeVersion::Three)),
"serioussam" => game!("Serious Sam", 25601, Protocol::Gamespy(GameSpyVersion::One)),
"theforest" => game!("The Forest", 27016, Protocol::Valve(SteamApp::THEFOREST)),
"teamfortress2" => game!("Team Fortress 2", 27015, Protocol::Valve(SteamApp::TEAMFORTRESS2)),
"tfc" => game!("Team Fortress Classic", 27015, Protocol::Valve(SteamApp::TFC)),
"theforest" => game!("The Forest", 27016, Protocol::Valve(Engine::new(556_450))),
"teamfortress2" => game!("Team Fortress 2", 27015, Protocol::Valve(Engine::new(440))),
"tfc" => game!("Team Fortress Classic", 27015, Protocol::Valve(Engine::new_gold_src(false))),
"theship" => game!("The Ship", 27015, Protocol::PROPRIETARY(ProprietaryProtocol::TheShip)),
"unturned" => game!("Unturned", 27015, Protocol::Valve(SteamApp::UNTURNED)),
"unturned" => game!("Unturned", 27015, Protocol::Valve(Engine::new(304_930))),
"unrealtournament" => game!("Unreal Tournament", 7778, Protocol::Gamespy(GameSpyVersion::One)),
"vrising" => game!("V Rising", 27016, Protocol::Valve(SteamApp::VRISING)),
"valheim" => game!("Valheim", 2457, Protocol::Valve(Engine::new(892_970)), GatheringSettings {
players: true,
rules: false,
check_app_id: true,
}.into_extra()),
"vrising" => game!("V Rising", 27016, Protocol::Valve(Engine::new(1_604_030))),
"jc2m" => game!("Just Cause 2: Multiplayer", 7777, Protocol::PROPRIETARY(ProprietaryProtocol::JC2M)),
"warsow" => game!("Warsow", 44400, Protocol::Quake(QuakeVersion::Three)),
"darkesthour" => game!("Darkest Hour: Europe '44-'45 (2008)", 7758, Protocol::Unreal2),
Expand Down
10 changes: 7 additions & 3 deletions src/games/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct Game {
pub default_port: u16,
/// The protocol the game's query uses
pub protocol: Protocol,
/// Request settings.
pub request_settings: ExtraRequestSettings,
}

#[cfg(feature = "game_defs")]
Expand Down Expand Up @@ -76,11 +78,13 @@ pub fn query_with_timeout_and_extra_settings(
) -> GDResult<Box<dyn CommonResponse>> {
let socket_addr = SocketAddr::new(*address, port.unwrap_or(game.default_port));
Ok(match &game.protocol {
Protocol::Valve(steam_app) => {
Protocol::Valve(engine) => {
protocols::valve::query(
&socket_addr,
steam_app.as_engine(),
extra_settings.map(ExtraRequestSettings::into),
*engine,
extra_settings
.or(Option::from(game.request_settings.clone()))
.map(ExtraRequestSettings::into),
timeout_settings,
)
.map(Box::new)?
Expand Down
2 changes: 1 addition & 1 deletion src/games/quake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use crate::protocols::quake::game_query_mod;

game_query_mod!(quake1, "Quake 1", one, 27500);
game_query_mod!(quake2, "Quake 2", two, 27910);
game_query_mod!(quake3, "Quake 3: Arena", three, 27960);
game_query_mod!(q3a, "Quake 3 Arena", three, 27960);
game_query_mod!(sof2, "Soldier of Fortune 2", three, 20100);
game_query_mod!(warsow, "Warsow", three, 44400);
Loading

0 comments on commit 2e17bc2

Please sign in to comment.