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 --no-default-features --verbose
- cargo check --no-default-features --features rcon --verbose
- cargo check --no-default-features --features lobby --verbose
check:
<<: *check-base
check-macos:
@ -68,6 +69,7 @@ check-windows:
script:
- cargo check --locked --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-x86_64-linux-gnu:
@ -231,6 +233,7 @@ test-cargo-x86_64-linux-gnu:
- cargo test --locked --verbose
- cargo test --locked --no-default-features --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
test-cargo-x86_64-windows:
@ -244,6 +247,7 @@ test-cargo-x86_64-windows:
script:
- cargo test --locked --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-gitlab-generic-package:

View File

@ -19,9 +19,17 @@ exclude = [
edition = "2021"
[features]
default = ["rcon"]
default = ["rcon", "lobby"]
# RCON support
# Allow use of RCON to manage (stop) server.
# Required on Windows.
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]
anyhow = "1.0"
bytes = "1.1"
@ -46,9 +54,9 @@ version-compare = "0.1"
rust_rcon = { package = "rcon", version = "0.5", optional = true }
# Feature: lobby
named-binary-tag = "0.6"
quartz_nbt = "0.2"
uuid = { version = "0.7", features = ["v3"] }
named-binary-tag = { version = "0.6", optional = true }
quartz_nbt = { version = "0.2", optional = true }
uuid = { version = "0.7", optional = true, features = ["v3"] }
[target.'cfg(unix)'.dependencies]
libc = "0.2"

View File

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

View File

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

View File

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

View File

@ -16,6 +16,7 @@ use tokio::net::TcpStream;
use tokio::time;
use crate::config::*;
#[cfg(feature = "lobby")]
use crate::lobby;
use crate::proto::{self, Client, ClientInfo, ClientState, RawPacket};
use crate::server::{self, Server, State};
@ -198,6 +199,7 @@ pub async fn serve(
}
// Lobby method, keep client in lobby while server starts
#[cfg(feature = "lobby")]
Method::Lobby => {
trace!(target: "lazymc", "Using lobby method to occupy joining client");
@ -209,9 +211,14 @@ pub async fn serve(
// Start lobby
lobby::serve(client, client_info, inbound, config, server, queue).await?;
return Ok(());
// 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");
}
}
}