diff --git a/.github/labeler.yml b/.github/labeler.yml index 31043c5..76326b3 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -5,10 +5,13 @@ ci: - .pre-commit-config.yaml protocol: - - src/protocols/** + - crates/lib/src/protocols/** game: - - src/games/** + - crates/lib/src/games/** + +cli: + - crates/cli/** crate: - Cargo.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85ce36d..7e9192e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,9 +31,9 @@ jobs: shared-key: "cargo-deps" cache-targets: false - name: Run Build - run: cargo build --verbose --bins --lib --examples --all-features + run: cargo check --verbose --workspace --bins --lib --examples --all-features - name: Run Tests - run: cargo test --verbose --bins --lib --examples --all-features + run: cargo test --verbose --workspace --bins --lib --examples --all-features build: runs-on: ubuntu-latest needs: [ "build_first" ] @@ -61,9 +61,9 @@ jobs: shared-key: "cargo-deps" cache-targets: false - name: Run Build - run: cargo build --verbose --bins --lib ${{ matrix.build_type }} + run: cargo check --workspace --verbose --bins --lib ${{ matrix.build_type }} build_msrv: - name: "Build using MSRV" + name: "Build using MSRV (lib only)" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -74,7 +74,7 @@ jobs: toolchain: 1.65.0 override: true - name: Run MSRV - run: cargo build + run: cargo check -p gamedig formatting: name: "Check code formatting" runs-on: ubuntu-latest @@ -105,10 +105,10 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --bins --lib --examples --all-features + args: --workspace --bins --lib --examples --all-features if: ${{ !env.ACT }} # skip during local actions testing - name: Run clippy (local) - run: cargo clippy --verbose --bins --lib --examples --all-features + run: cargo clippy --workspace --verbose --bins --lib --examples --all-features if: ${{ env.ACT }} # only run during local actions testing doc: name: "Check rustdoc" @@ -121,6 +121,6 @@ jobs: shared-key: "cargo-deps" cache-targets: false - name: "Run cargo doc" - run: cargo doc + run: cargo doc --workspace env: RUSTDOCFLAGS: "-D warnings" diff --git a/.github/workflows/node-badge.yml b/.github/workflows/node-badge.yml index b6865ee..b0b33af 100644 --- a/.github/workflows/node-badge.yml +++ b/.github/workflows/node-badge.yml @@ -39,7 +39,7 @@ jobs: # Calculate how many of those games we have definitions for rust_games_count=0 for game in $node_games; do - if grep "\"$game\" *=>" ./src/games/definitions.rs; then + if grep "\"$game\" *=>" ./crates/lib/src/games/definitions.rs; then rust_games_count=$(( rust_games_count + 1 )) fi done diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7449aee..6e7adc3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,25 +8,25 @@ repos: language: system files: '[.]rs$' pass_filenames: false - entry: rustup run --install nightly-2023-07-09 cargo-clippy -- -- -D warnings + entry: rustup run --install nightly-2023-07-09 cargo-clippy -- --workspace --all-features -- -D warnings - id: build-no-features name: Check crate build with no features language: system files: '[.]rs$' pass_filenames: false - entry: cargo build --no-default-features + entry: cargo check --workspace --no-default-features - id: build-all-features name: Check crate builds with all features language: system files: '[.]rs$' pass_filenames: false - entry: cargo build --all-features --lib --bins --examples + entry: cargo check --workspace --all-features --lib --bins --examples - id: test name: Check tests pass language: system files: '[.]rs$' pass_filenames: false - entry: cargo test --bins --lib --examples --all-features + entry: cargo test --workspace --bins --lib --examples --all-features - id: format name: Check rustfmt language: system @@ -34,11 +34,11 @@ repos: pass_filenames: false entry: rustup run --install nightly-2023-07-09 cargo-fmt --check - id: msrv - name: Check MSRV compiles + name: Check MSRV compiles (lib only) language: system files: '[.]rs$' pass_filenames: false - entry: rustup run --install 1.65 cargo build + entry: rustup run --install 1.65 cargo check -p gamedig - id: docs name: Check rustdoc compiles language: system diff --git a/Cargo.toml b/Cargo.toml index 1d9d30a..4dd9c76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,35 +1,15 @@ -[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"] +[workspace] +name = "gamedig-workspace" +members = ["crates/cli", "crates/lib"] -[features] -default = ["games", "services", "game_defs"] -games = [] -services = [] -game_defs = ["dep:phf", "games"] -serde = ["dep:serde", "serde/derive"] +# Edition 2021, uses resolver = 2 +resolver = "2" -[dependencies] -byteorder = "1.5" -bzip2-rs = "0.1" -crc32fast = "1.3" -serde_json = "1.0" -encoding_rs = "0.8" +[profile.release] +opt-level = 3 +debug = false +rpath = true +lto = true -serde = { version = "1.0", optional = true } - -phf = { version = "0.11", optional = true, features = ["macros"] } +[profile.release.package."*"] +opt-level = 3 diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml new file mode 100644 index 0000000..b02867b --- /dev/null +++ b/crates/cli/Cargo.toml @@ -0,0 +1,16 @@ +[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" } +thiserror = "1.0.43" diff --git a/crates/cli/src/error.rs b/crates/cli/src/error.rs new file mode 100644 index 0000000..49b6813 --- /dev/null +++ b/crates/cli/src/error.rs @@ -0,0 +1,16 @@ +pub type Result = std::result::Result; + +#[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("Unknown Game: {0}")] + UnknownGame(String), +} diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs new file mode 100644 index 0000000..b21b0ae --- /dev/null +++ b/crates/cli/src/main.rs @@ -0,0 +1,34 @@ +use std::net::IpAddr; + +use clap::Parser; +use gamedig::games::*; + +mod error; + +use self::error::Result; + +#[derive(Parser)] +#[command(author, version, about)] +struct Cli { + #[arg(short, long)] + game: String, + + #[arg(short, long)] + ip: IpAddr, + + #[arg(short, long)] + port: Option, +} + +fn main() -> Result<()> { + let args = Cli::parse(); + + let game = match GAMES.get(&args.game) { + Some(game) => game, + None => return Err(error::Error::UnknownGame(args.game)), + }; + + println!("{:#?}", query(game, &args.ip, args.port)?.as_json()); + + Ok(()) +} diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml new file mode 100644 index 0000000..f3199b3 --- /dev/null +++ b/crates/lib/Cargo.toml @@ -0,0 +1,35 @@ +[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" +encoding_rs = "0.8" + +serde = { version = "1.0", optional = true } + +phf = { version = "0.11", optional = true, features = ["macros"] } \ No newline at end of file diff --git a/examples/generic.rs b/crates/lib/examples/generic.rs similarity index 100% rename from examples/generic.rs rename to crates/lib/examples/generic.rs diff --git a/examples/minecraft.rs b/crates/lib/examples/minecraft.rs similarity index 100% rename from examples/minecraft.rs rename to crates/lib/examples/minecraft.rs diff --git a/examples/teamfortress2.rs b/crates/lib/examples/teamfortress2.rs similarity index 100% rename from examples/teamfortress2.rs rename to crates/lib/examples/teamfortress2.rs diff --git a/examples/valve_master_server_query.rs b/crates/lib/examples/valve_master_server_query.rs similarity index 100% rename from examples/valve_master_server_query.rs rename to crates/lib/examples/valve_master_server_query.rs diff --git a/examples/valve_protocol_query.rs b/crates/lib/examples/valve_protocol_query.rs similarity index 100% rename from examples/valve_protocol_query.rs rename to crates/lib/examples/valve_protocol_query.rs diff --git a/src/buffer.rs b/crates/lib/src/buffer.rs similarity index 100% rename from src/buffer.rs rename to crates/lib/src/buffer.rs diff --git a/src/errors/error.rs b/crates/lib/src/errors/error.rs similarity index 100% rename from src/errors/error.rs rename to crates/lib/src/errors/error.rs diff --git a/src/errors/kind.rs b/crates/lib/src/errors/kind.rs similarity index 100% rename from src/errors/kind.rs rename to crates/lib/src/errors/kind.rs diff --git a/src/errors/mod.rs b/crates/lib/src/errors/mod.rs similarity index 100% rename from src/errors/mod.rs rename to crates/lib/src/errors/mod.rs diff --git a/src/errors/result.rs b/crates/lib/src/errors/result.rs similarity index 100% rename from src/errors/result.rs rename to crates/lib/src/errors/result.rs diff --git a/src/games/battalion1944.rs b/crates/lib/src/games/battalion1944.rs similarity index 100% rename from src/games/battalion1944.rs rename to crates/lib/src/games/battalion1944.rs diff --git a/src/games/definitions.rs b/crates/lib/src/games/definitions.rs similarity index 100% rename from src/games/definitions.rs rename to crates/lib/src/games/definitions.rs diff --git a/src/games/ffow.rs b/crates/lib/src/games/ffow.rs similarity index 100% rename from src/games/ffow.rs rename to crates/lib/src/games/ffow.rs diff --git a/src/games/gamespy.rs b/crates/lib/src/games/gamespy.rs similarity index 100% rename from src/games/gamespy.rs rename to crates/lib/src/games/gamespy.rs diff --git a/src/games/jc2m.rs b/crates/lib/src/games/jc2m.rs similarity index 100% rename from src/games/jc2m.rs rename to crates/lib/src/games/jc2m.rs diff --git a/src/games/minecraft.rs b/crates/lib/src/games/minecraft.rs similarity index 100% rename from src/games/minecraft.rs rename to crates/lib/src/games/minecraft.rs diff --git a/src/games/mod.rs b/crates/lib/src/games/mod.rs similarity index 100% rename from src/games/mod.rs rename to crates/lib/src/games/mod.rs diff --git a/src/games/quake.rs b/crates/lib/src/games/quake.rs similarity index 100% rename from src/games/quake.rs rename to crates/lib/src/games/quake.rs diff --git a/src/games/theship.rs b/crates/lib/src/games/theship.rs similarity index 100% rename from src/games/theship.rs rename to crates/lib/src/games/theship.rs diff --git a/src/games/unreal2.rs b/crates/lib/src/games/unreal2.rs similarity index 100% rename from src/games/unreal2.rs rename to crates/lib/src/games/unreal2.rs diff --git a/src/games/valve.rs b/crates/lib/src/games/valve.rs similarity index 100% rename from src/games/valve.rs rename to crates/lib/src/games/valve.rs diff --git a/src/lib.rs b/crates/lib/src/lib.rs similarity index 100% rename from src/lib.rs rename to crates/lib/src/lib.rs diff --git a/src/protocols/gamespy/common.rs b/crates/lib/src/protocols/gamespy/common.rs similarity index 100% rename from src/protocols/gamespy/common.rs rename to crates/lib/src/protocols/gamespy/common.rs diff --git a/src/protocols/gamespy/mod.rs b/crates/lib/src/protocols/gamespy/mod.rs similarity index 100% rename from src/protocols/gamespy/mod.rs rename to crates/lib/src/protocols/gamespy/mod.rs diff --git a/src/protocols/gamespy/protocols/mod.rs b/crates/lib/src/protocols/gamespy/protocols/mod.rs similarity index 100% rename from src/protocols/gamespy/protocols/mod.rs rename to crates/lib/src/protocols/gamespy/protocols/mod.rs diff --git a/src/protocols/gamespy/protocols/one/mod.rs b/crates/lib/src/protocols/gamespy/protocols/one/mod.rs similarity index 100% rename from src/protocols/gamespy/protocols/one/mod.rs rename to crates/lib/src/protocols/gamespy/protocols/one/mod.rs diff --git a/src/protocols/gamespy/protocols/one/protocol.rs b/crates/lib/src/protocols/gamespy/protocols/one/protocol.rs similarity index 100% rename from src/protocols/gamespy/protocols/one/protocol.rs rename to crates/lib/src/protocols/gamespy/protocols/one/protocol.rs diff --git a/src/protocols/gamespy/protocols/one/types.rs b/crates/lib/src/protocols/gamespy/protocols/one/types.rs similarity index 100% rename from src/protocols/gamespy/protocols/one/types.rs rename to crates/lib/src/protocols/gamespy/protocols/one/types.rs diff --git a/src/protocols/gamespy/protocols/three/mod.rs b/crates/lib/src/protocols/gamespy/protocols/three/mod.rs similarity index 100% rename from src/protocols/gamespy/protocols/three/mod.rs rename to crates/lib/src/protocols/gamespy/protocols/three/mod.rs diff --git a/src/protocols/gamespy/protocols/three/protocol.rs b/crates/lib/src/protocols/gamespy/protocols/three/protocol.rs similarity index 100% rename from src/protocols/gamespy/protocols/three/protocol.rs rename to crates/lib/src/protocols/gamespy/protocols/three/protocol.rs diff --git a/src/protocols/gamespy/protocols/three/types.rs b/crates/lib/src/protocols/gamespy/protocols/three/types.rs similarity index 100% rename from src/protocols/gamespy/protocols/three/types.rs rename to crates/lib/src/protocols/gamespy/protocols/three/types.rs diff --git a/src/protocols/gamespy/protocols/two/mod.rs b/crates/lib/src/protocols/gamespy/protocols/two/mod.rs similarity index 100% rename from src/protocols/gamespy/protocols/two/mod.rs rename to crates/lib/src/protocols/gamespy/protocols/two/mod.rs diff --git a/src/protocols/gamespy/protocols/two/protocol.rs b/crates/lib/src/protocols/gamespy/protocols/two/protocol.rs similarity index 100% rename from src/protocols/gamespy/protocols/two/protocol.rs rename to crates/lib/src/protocols/gamespy/protocols/two/protocol.rs diff --git a/src/protocols/gamespy/protocols/two/types.rs b/crates/lib/src/protocols/gamespy/protocols/two/types.rs similarity index 100% rename from src/protocols/gamespy/protocols/two/types.rs rename to crates/lib/src/protocols/gamespy/protocols/two/types.rs diff --git a/src/protocols/minecraft/mod.rs b/crates/lib/src/protocols/minecraft/mod.rs similarity index 100% rename from src/protocols/minecraft/mod.rs rename to crates/lib/src/protocols/minecraft/mod.rs diff --git a/src/protocols/minecraft/protocol/bedrock.rs b/crates/lib/src/protocols/minecraft/protocol/bedrock.rs similarity index 100% rename from src/protocols/minecraft/protocol/bedrock.rs rename to crates/lib/src/protocols/minecraft/protocol/bedrock.rs diff --git a/src/protocols/minecraft/protocol/java.rs b/crates/lib/src/protocols/minecraft/protocol/java.rs similarity index 100% rename from src/protocols/minecraft/protocol/java.rs rename to crates/lib/src/protocols/minecraft/protocol/java.rs diff --git a/src/protocols/minecraft/protocol/legacy_v1_3.rs b/crates/lib/src/protocols/minecraft/protocol/legacy_v1_3.rs similarity index 100% rename from src/protocols/minecraft/protocol/legacy_v1_3.rs rename to crates/lib/src/protocols/minecraft/protocol/legacy_v1_3.rs diff --git a/src/protocols/minecraft/protocol/legacy_v1_5.rs b/crates/lib/src/protocols/minecraft/protocol/legacy_v1_5.rs similarity index 100% rename from src/protocols/minecraft/protocol/legacy_v1_5.rs rename to crates/lib/src/protocols/minecraft/protocol/legacy_v1_5.rs diff --git a/src/protocols/minecraft/protocol/legacy_v1_6.rs b/crates/lib/src/protocols/minecraft/protocol/legacy_v1_6.rs similarity index 100% rename from src/protocols/minecraft/protocol/legacy_v1_6.rs rename to crates/lib/src/protocols/minecraft/protocol/legacy_v1_6.rs diff --git a/src/protocols/minecraft/protocol/mod.rs b/crates/lib/src/protocols/minecraft/protocol/mod.rs similarity index 100% rename from src/protocols/minecraft/protocol/mod.rs rename to crates/lib/src/protocols/minecraft/protocol/mod.rs diff --git a/src/protocols/minecraft/types.rs b/crates/lib/src/protocols/minecraft/types.rs similarity index 100% rename from src/protocols/minecraft/types.rs rename to crates/lib/src/protocols/minecraft/types.rs diff --git a/src/protocols/mod.rs b/crates/lib/src/protocols/mod.rs similarity index 100% rename from src/protocols/mod.rs rename to crates/lib/src/protocols/mod.rs diff --git a/src/protocols/quake/client.rs b/crates/lib/src/protocols/quake/client.rs similarity index 100% rename from src/protocols/quake/client.rs rename to crates/lib/src/protocols/quake/client.rs diff --git a/src/protocols/quake/mod.rs b/crates/lib/src/protocols/quake/mod.rs similarity index 100% rename from src/protocols/quake/mod.rs rename to crates/lib/src/protocols/quake/mod.rs diff --git a/src/protocols/quake/one.rs b/crates/lib/src/protocols/quake/one.rs similarity index 100% rename from src/protocols/quake/one.rs rename to crates/lib/src/protocols/quake/one.rs diff --git a/src/protocols/quake/three.rs b/crates/lib/src/protocols/quake/three.rs similarity index 100% rename from src/protocols/quake/three.rs rename to crates/lib/src/protocols/quake/three.rs diff --git a/src/protocols/quake/two.rs b/crates/lib/src/protocols/quake/two.rs similarity index 100% rename from src/protocols/quake/two.rs rename to crates/lib/src/protocols/quake/two.rs diff --git a/src/protocols/quake/types.rs b/crates/lib/src/protocols/quake/types.rs similarity index 100% rename from src/protocols/quake/types.rs rename to crates/lib/src/protocols/quake/types.rs diff --git a/src/protocols/types.rs b/crates/lib/src/protocols/types.rs similarity index 100% rename from src/protocols/types.rs rename to crates/lib/src/protocols/types.rs diff --git a/src/protocols/unreal2/mod.rs b/crates/lib/src/protocols/unreal2/mod.rs similarity index 100% rename from src/protocols/unreal2/mod.rs rename to crates/lib/src/protocols/unreal2/mod.rs diff --git a/src/protocols/unreal2/protocol.rs b/crates/lib/src/protocols/unreal2/protocol.rs similarity index 100% rename from src/protocols/unreal2/protocol.rs rename to crates/lib/src/protocols/unreal2/protocol.rs diff --git a/src/protocols/unreal2/types.rs b/crates/lib/src/protocols/unreal2/types.rs similarity index 100% rename from src/protocols/unreal2/types.rs rename to crates/lib/src/protocols/unreal2/types.rs diff --git a/src/protocols/valve/mod.rs b/crates/lib/src/protocols/valve/mod.rs similarity index 100% rename from src/protocols/valve/mod.rs rename to crates/lib/src/protocols/valve/mod.rs diff --git a/src/protocols/valve/protocol.rs b/crates/lib/src/protocols/valve/protocol.rs similarity index 100% rename from src/protocols/valve/protocol.rs rename to crates/lib/src/protocols/valve/protocol.rs diff --git a/src/protocols/valve/types.rs b/crates/lib/src/protocols/valve/types.rs similarity index 100% rename from src/protocols/valve/types.rs rename to crates/lib/src/protocols/valve/types.rs diff --git a/src/services/mod.rs b/crates/lib/src/services/mod.rs similarity index 100% rename from src/services/mod.rs rename to crates/lib/src/services/mod.rs diff --git a/src/services/valve_master_server/mod.rs b/crates/lib/src/services/valve_master_server/mod.rs similarity index 100% rename from src/services/valve_master_server/mod.rs rename to crates/lib/src/services/valve_master_server/mod.rs diff --git a/src/services/valve_master_server/service.rs b/crates/lib/src/services/valve_master_server/service.rs similarity index 100% rename from src/services/valve_master_server/service.rs rename to crates/lib/src/services/valve_master_server/service.rs diff --git a/src/services/valve_master_server/types.rs b/crates/lib/src/services/valve_master_server/types.rs similarity index 100% rename from src/services/valve_master_server/types.rs rename to crates/lib/src/services/valve_master_server/types.rs diff --git a/src/socket.rs b/crates/lib/src/socket.rs similarity index 100% rename from src/socket.rs rename to crates/lib/src/socket.rs diff --git a/src/utils.rs b/crates/lib/src/utils.rs similarity index 100% rename from src/utils.rs rename to crates/lib/src/utils.rs