refator: copy cli into mono

This commit is contained in:
Cain 2023-10-16 23:20:47 +01:00
parent 66ae3c296e
commit 80f6b87991
63 changed files with 244 additions and 34 deletions

View file

@ -1,34 +1,6 @@
[package]
name = "gamedig"
version = "0.4.1"
edition = "2021"
authors = [
"rust-GameDig contributors [https://github.com/gamedig/rust-gamedig/contributors]",
"node-GameDig contributors [https://github.com/gamedig/node-gamedig/contributors]",
]
license = "MIT"
description = "Query game servers and not only."
homepage = "https://github.com/gamedig/rust-gamedig"
documentation = "https://docs.rs/gamedig/latest/gamedig/"
repository = "https://github.com/gamedig/rust-gamedig"
readme = "README.md"
keywords = ["server", "query", "game", "check", "status"]
rust-version = "1.65.0"
categories = ["parser-implementations", "parsing", "network-programming", "encoding"]
[features]
default = ["games", "services", "game_defs"]
games = []
services = []
game_defs = ["dep:phf", "games"]
serde = ["dep:serde", "serde/derive"]
[dependencies]
byteorder = "1.5"
bzip2-rs = "0.1"
crc32fast = "1.3"
serde_json = "1.0"
serde = { version = "1.0", optional = true }
phf = { version = "0.11", optional = true, features = ["macros"] }
[workspace]
name = "gamedig-workspace"
members = [
"crates/cli",
"crates/lib",
]

22
crates/cli/Cargo.toml Normal file
View file

@ -0,0 +1,22 @@
[package]
name = "gamedig-cli"
authors = ["rust-GameDig contributors [https://github.com/gamedig/rust-gamedig/contributors]"]
description = "A command line interface for gamedig"
license = "MIT"
version = "0.4.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.1.11", features = ["derive"] }
gamedig = { version = "*", path = "../lib" }
strum = "0.25.0"
strum_macros = "0.24.3"
thiserror = "1.0.43"
[profile.release]
opt-level = 3
debug = false
rpath = true
lto = true

16
crates/cli/src/error.rs Normal file
View file

@ -0,0 +1,16 @@
pub type Result<T> = std::result::Result<T, Error>;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("IO Error: {0}")]
Io(#[from] std::io::Error),
#[error("Clap Error: {0}")]
Clap(#[from] clap::Error),
#[error("Gamedig Error: {0}")]
Gamedig(#[from] gamedig::errors::GDError),
#[error("Strum Error: {0}")]
Strum(#[from] strum::ParseError),
}

93
crates/cli/src/key.rs Normal file
View file

@ -0,0 +1,93 @@
use strum_macros::{Display, EnumString};
#[derive(EnumString, Display, Debug, Clone)]
pub enum Game {
#[strum(serialize = "aliens")]
AlienSwarm,
#[strum(serialize = "aoc")]
AgeOfChivalry,
#[strum(serialize = "arma2oa")]
ARMA2OperationArrowhead,
#[strum(serialize = "ase")]
ARKSurvivalEvolved,
#[strum(serialize = "asrd")]
AlienSwarmReactiveDrop,
#[strum(serialize = "avorion")]
Avorion,
#[strum(serialize = "bat1944")]
Battalion1944,
#[strum(serialize = "bb2")]
BrainBread2,
#[strum(serialize = "bf1942")]
Battlefield1942,
#[strum(serialize = "bm")]
BlackMesa,
#[strum(serialize = "bo")]
BallisticOverkill,
#[strum(serialize = "ccure")]
CodenameCURE,
#[strum(serialize = "cosu")]
ColonySurvival,
#[strum(serialize = "cs")]
CounterStrike,
#[strum(serialize = "cscz")]
CounterStrikeConditionZero,
#[strum(serialize = "csgo")]
CounterStrikeGlobalOffensive,
#[strum(serialize = "css")]
CounterStrikeSource,
#[strum(serialize = "dod")]
DayOfDefeat,
#[strum(serialize = "dods")]
DayOfDefeatSource,
#[strum(serialize = "doi")]
DayOfInfamy,
#[strum(serialize = "dst")]
DontStarveTogether,
#[strum(serialize = "gm")]
GarrysMod,
#[strum(serialize = "hl2dm")]
HalfLife2Deathmatch,
#[strum(serialize = "hldms")]
HalfLifeDeathmatchSource,
#[strum(serialize = "ins")]
Insurgency,
#[strum(serialize = "insmic")]
InsurgencyModernInfantryCombat,
#[strum(serialize = "inss")]
InsurgencySandstorm,
#[strum(serialize = "l4d")]
Left4Dead,
#[strum(serialize = "l4d2")]
Left4Dead2,
#[strum(serialize = "mc")]
Minecraft,
#[strum(serialize = "ohd")]
OperationHarshDoorstop,
#[strum(serialize = "onset")]
Onset,
#[strum(serialize = "pz")]
ProjectZomboid,
#[strum(serialize = "ror2")]
RiskOfRain2,
#[strum(serialize = "rust")]
Rust,
#[strum(serialize = "sc")]
SvenCoOp,
#[strum(serialize = "sdtd")]
SevenDaysToDie,
#[strum(serialize = "tf")]
TeamFortress,
#[strum(serialize = "tf2")]
TeamFortress2,
#[strum(serialize = "tfc")]
TeamFortressClassic,
#[strum(serialize = "ts")]
TheShip,
#[strum(serialize = "unturned")]
Unturned,
#[strum(serialize = "ut")]
UnrealTournament,
#[strum(serialize = "vr")]
VRising,
}

73
crates/cli/src/main.rs Normal file
View file

@ -0,0 +1,73 @@
mod error;
mod key;
use self::{error::Result, key::Game};
use clap::Parser;
use gamedig::games::*;
#[derive(Parser)]
#[command(author, version, about)]
struct Cli {
#[arg(short, long)]
game: Game,
#[arg(short, long)]
ip: String,
#[arg(short, long)]
port: u16,
}
#[rustfmt::skip]
fn main() -> Result<()> {
let args = Cli::parse();
match args.game {
Game::AlienSwarm => Ok(println!("{:#?}", aliens::query(&args.ip, Some(args.port))?)),
Game::AgeOfChivalry => Ok(println!("{:#?}", aoc::query(&args.ip, Some(args.port))?)),
Game::ARMA2OperationArrowhead => Ok(println!("{:#?}", arma2oa::query(&args.ip, Some(args.port))?)),
Game::ARKSurvivalEvolved => Ok(println!("{:#?}", ase::query(&args.ip, Some(args.port))?)),
Game::AlienSwarmReactiveDrop => Ok(println!("{:#?}", asrd::query(&args.ip, Some(args.port))?)),
Game::Avorion => Ok(println!("{:#?}", avorion::query(&args.ip, Some(args.port))?)),
Game::Battalion1944 => Ok(println!("{:#?}", bat1944::query(&args.ip, Some(args.port))?)),
Game::BrainBread2 => Ok(println!("{:#?}", bb2::query(&args.ip, Some(args.port))?)),
Game::Battlefield1942 => Ok(println!("{:#?}", bf1942::query(&args.ip, Some(args.port))?)),
Game::BlackMesa => Ok(println!("{:#?}", bm::query(&args.ip, Some(args.port))?)),
Game::BallisticOverkill => Ok(println!("{:#?}", bo::query(&args.ip, Some(args.port))?)),
Game::CodenameCURE => Ok(println!("{:#?}", ccure::query(&args.ip, Some(args.port))?)),
Game::ColonySurvival => Ok(println!("{:#?}", cosu::query(&args.ip, Some(args.port))?)),
Game::CounterStrike => Ok(println!("{:#?}", cs::query(&args.ip, Some(args.port))?)),
Game::CounterStrikeConditionZero => Ok(println!("{:#?}", cscz::query(&args.ip, Some(args.port))?)),
Game::CounterStrikeGlobalOffensive => Ok(println!("{:#?}", csgo::query(&args.ip, Some(args.port))?)),
Game::CounterStrikeSource => Ok(println!("{:#?}", css::query(&args.ip, Some(args.port))?)),
Game::DayOfDefeat => Ok(println!("{:#?}", dod::query(&args.ip, Some(args.port))?)),
Game::DayOfDefeatSource => Ok(println!("{:#?}", dods::query(&args.ip, Some(args.port))?)),
Game::DayOfInfamy => Ok(println!("{:#?}", doi::query(&args.ip, Some(args.port))?)),
Game::DontStarveTogether => Ok(println!("{:#?}", dst::query(&args.ip, Some(args.port))?)),
Game::GarrysMod => Ok(println!("{:#?}", gm::query(&args.ip, Some(args.port))?)),
Game::HalfLife2Deathmatch => Ok(println!("{:#?}", hl2dm::query(&args.ip, Some(args.port))?)),
Game::HalfLifeDeathmatchSource => Ok(println!("{:#?}", hldms::query(&args.ip, Some(args.port))?)),
Game::Insurgency => Ok(println!("{:#?}", ins::query(&args.ip, Some(args.port))?)),
Game::InsurgencyModernInfantryCombat => Ok(println!("{:#?}", insmic::query(&args.ip, Some(args.port))?)),
Game::InsurgencySandstorm => Ok(println!("{:#?}", inss::query(&args.ip, Some(args.port))?)),
Game::Left4Dead => Ok(println!("{:#?}", l4d::query(&args.ip, Some(args.port))?)),
Game::Left4Dead2 => Ok(println!("{:#?}", l4d2::query(&args.ip, Some(args.port))?)),
Game::Minecraft => Ok(println!("{:#?}", mc::query(&args.ip, Some(args.port))?)),
Game::OperationHarshDoorstop => Ok(println!("{:#?}", ohd::query(&args.ip, Some(args.port))?)),
Game::Onset => Ok(println!("{:#?}", onset::query(&args.ip, Some(args.port))?)),
Game::ProjectZomboid => Ok(println!("{:#?}", pz::query(&args.ip, Some(args.port))?)),
Game::RiskOfRain2 => Ok(println!("{:#?}", ror2::query(&args.ip, Some(args.port))?)),
Game::Rust => Ok(println!("{:#?}", rust::query(&args.ip, Some(args.port))?)),
Game::SvenCoOp => Ok(println!("{:#?}", sc::query(&args.ip, Some(args.port))?)),
Game::SevenDaysToDie => Ok(println!("{:#?}", sdtd::query(&args.ip, Some(args.port))?)),
Game::TeamFortress => Ok(println!("{:#?}", tf::query(&args.ip, Some(args.port))?)),
Game::TeamFortress2 => Ok(println!("{:#?}", tf2::query(&args.ip, Some(args.port))?)),
Game::TeamFortressClassic => Ok(println!("{:#?}", tfc::query(&args.ip, Some(args.port))?)),
Game::TheShip => Ok(println!("{:#?}", ts::query(&args.ip, Some(args.port))?)),
Game::Unturned => Ok(println!("{:#?}", unturned::query(&args.ip, Some(args.port))?)),
Game::UnrealTournament => Ok(println!("{:#?}", ut::query(&args.ip, Some(args.port))?)),
Game::VRising => Ok(println!("{:#?}", vr::query(&args.ip, Some(args.port))?)),
}
}

34
crates/lib/Cargo.toml Normal file
View file

@ -0,0 +1,34 @@
[package]
name = "gamedig"
version = "0.4.1"
edition = "2021"
authors = [
"rust-GameDig contributors [https://github.com/gamedig/rust-gamedig/contributors]",
"node-GameDig contributors [https://github.com/gamedig/node-gamedig/contributors]",
]
license = "MIT"
description = "Query game servers and not only."
homepage = "https://github.com/gamedig/rust-gamedig"
documentation = "https://docs.rs/gamedig/latest/gamedig/"
repository = "https://github.com/gamedig/rust-gamedig"
readme = "README.md"
keywords = ["server", "query", "game", "check", "status"]
rust-version = "1.65.0"
categories = ["parser-implementations", "parsing", "network-programming", "encoding"]
[features]
default = ["games", "services", "game_defs"]
games = []
services = []
game_defs = ["dep:phf", "games"]
serde = ["dep:serde", "serde/derive"]
[dependencies]
byteorder = "1.5"
bzip2-rs = "0.1"
crc32fast = "1.3"
serde_json = "1.0"
serde = { version = "1.0", optional = true }
phf = { version = "0.11", optional = true, features = ["macros"] }