Add lobby compiler feature flag

This commit is contained in:
timvisee 2021-11-15 20:29:45 +01:00
parent d213612225
commit 1da8c60323
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
6 changed files with 28 additions and 5 deletions

View File

@ -45,6 +45,7 @@ before_script:
- cargo check --verbose - cargo check --verbose
- cargo check --no-default-features --verbose - cargo check --no-default-features --verbose
- cargo check --no-default-features --features rcon --verbose - cargo check --no-default-features --features rcon --verbose
- cargo check --no-default-features --features lobby --verbose
check: check:
<<: *check-base <<: *check-base
check-macos: check-macos:
@ -68,6 +69,7 @@ check-windows:
script: script:
- cargo check --locked --verbose - cargo check --locked --verbose
- cargo check --locked --no-default-features --features rcon --verbose - cargo check --locked --no-default-features --features rcon --verbose
- cargo check --locked --no-default-features --features lobby --verbose
# Build using Rust stable on Linux # Build using Rust stable on Linux
build-x86_64-linux-gnu: build-x86_64-linux-gnu:
@ -231,6 +233,7 @@ test-cargo-x86_64-linux-gnu:
- cargo test --locked --verbose - cargo test --locked --verbose
- cargo test --locked --no-default-features --verbose - cargo test --locked --no-default-features --verbose
- cargo test --locked --no-default-features --features rcon --verbose - cargo test --locked --no-default-features --features rcon --verbose
- cargo test --locked --no-default-features --features lobby --verbose
# Run the unit tests through Cargo on Windows # Run the unit tests through Cargo on Windows
test-cargo-x86_64-windows: test-cargo-x86_64-windows:
@ -244,6 +247,7 @@ test-cargo-x86_64-windows:
script: script:
- cargo test --locked --verbose - cargo test --locked --verbose
- cargo test --locked --no-default-features --features rcon --verbose - cargo test --locked --no-default-features --features rcon --verbose
- cargo test --locked --no-default-features --features lobby --verbose
# Release binaries on GitLab as generic package # Release binaries on GitLab as generic package
release-gitlab-generic-package: release-gitlab-generic-package:

View File

@ -19,9 +19,17 @@ exclude = [
edition = "2021" edition = "2021"
[features] [features]
default = ["rcon"] default = ["rcon", "lobby"]
# RCON support
# Allow use of RCON to manage (stop) server.
# Required on Windows.
rcon = ["rust_rcon"] rcon = ["rust_rcon"]
# Lobby support
# Add lobby join method, keeps client in fake lobby world until server is ready.
lobby = ["named-binary-tag", "quartz_nbt", "uuid"]
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
bytes = "1.1" bytes = "1.1"
@ -46,9 +54,9 @@ version-compare = "0.1"
rust_rcon = { package = "rcon", version = "0.5", optional = true } rust_rcon = { package = "rcon", version = "0.5", optional = true }
# Feature: lobby # Feature: lobby
named-binary-tag = "0.6" named-binary-tag = { version = "0.6", optional = true }
quartz_nbt = "0.2" quartz_nbt = { version = "0.2", optional = true }
uuid = { version = "0.7", features = ["v3"] } uuid = { version = "0.7", optional = true, features = ["v3"] }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
libc = "0.2" libc = "0.2"

View File

@ -10,6 +10,7 @@ extern crate log;
pub(crate) mod action; pub(crate) mod action;
pub(crate) mod cli; pub(crate) mod cli;
pub(crate) mod config; pub(crate) mod config;
#[cfg(feature = "lobby")]
pub(crate) mod lobby; pub(crate) mod lobby;
pub(crate) mod mc; pub(crate) mod mc;
pub(crate) mod monitor; pub(crate) mod monitor;

View File

@ -3,4 +3,5 @@ pub mod rcon;
pub mod server_properties; pub mod server_properties;
/// Minecraft ticks per second. /// Minecraft ticks per second.
#[allow(unused)]
pub const TICKS_PER_SECOND: u32 = 20; pub const TICKS_PER_SECOND: u32 = 20;

View File

@ -113,6 +113,7 @@ impl Client {
} }
/// Set compression value. /// Set compression value.
#[allow(unused)]
pub fn set_compression(&self, threshold: i32) { pub fn set_compression(&self, threshold: i32) {
trace!(target: "lazymc", "Client now uses compression threshold of {}", threshold); trace!(target: "lazymc", "Client now uses compression threshold of {}", threshold);
self.compression.store(threshold, Ordering::Relaxed); self.compression.store(threshold, Ordering::Relaxed);
@ -144,6 +145,7 @@ pub enum ClientState {
Login, Login,
/// State to play on the server. /// State to play on the server.
#[allow(unused)]
Play, Play,
} }

View File

@ -16,6 +16,7 @@ use tokio::net::TcpStream;
use tokio::time; use tokio::time;
use crate::config::*; use crate::config::*;
#[cfg(feature = "lobby")]
use crate::lobby; use crate::lobby;
use crate::proto::{self, Client, ClientInfo, ClientState, RawPacket}; use crate::proto::{self, Client, ClientInfo, ClientState, RawPacket};
use crate::server::{self, Server, State}; use crate::server::{self, Server, State};
@ -198,6 +199,7 @@ pub async fn serve(
} }
// Lobby method, keep client in lobby while server starts // Lobby method, keep client in lobby while server starts
#[cfg(feature = "lobby")]
Method::Lobby => { Method::Lobby => {
trace!(target: "lazymc", "Using lobby method to occupy joining client"); trace!(target: "lazymc", "Using lobby method to occupy joining client");
@ -209,9 +211,14 @@ pub async fn serve(
// Start lobby // Start lobby
lobby::serve(client, client_info, inbound, config, server, queue).await?; lobby::serve(client, client_info, inbound, config, server, queue).await?;
return Ok(()); return Ok(());
// TODO: do not consume client here, allow other join method on fail // TODO: do not consume client here, allow other join method on fail
} }
// Lobby method, keep client in lobby while server starts
#[cfg(not(feature = "lobby"))]
Method::Lobby => {
error!(target: "lazymc", "Lobby join method not supported in this lazymc build");
}
} }
} }