Add lockout mode, enable to prevent all players from connecting
This commit is contained in:
@@ -41,6 +41,7 @@ https://user-images.githubusercontent.com/856222/141378688-882082be-9efa-4cfe-81
|
|||||||
- Automatically manages `server.properties` (host, port and RCON settings)
|
- Automatically manages `server.properties` (host, port and RCON settings)
|
||||||
- Graceful server sleep/shutdown through RCON (with `SIGTERM` fallback on Linux/Unix)
|
- Graceful server sleep/shutdown through RCON (with `SIGTERM` fallback on Linux/Unix)
|
||||||
- Restart server on crash
|
- Restart server on crash
|
||||||
|
- Lockout mode
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
@@ -67,6 +67,13 @@ command = "java -Xmx1G -Xms1G -jar server.jar --nogui"
|
|||||||
#login_starting = "Server is starting... §c♥§r\n\nThis may take some time.\n\nPlease try to reconnect in a minute."
|
#login_starting = "Server is starting... §c♥§r\n\nThis may take some time.\n\nPlease try to reconnect in a minute."
|
||||||
#login_stopping = "Server is going to sleep... §7☠§r\n\nPlease try to reconnect in a minute to wake it again."
|
#login_stopping = "Server is going to sleep... §7☠§r\n\nPlease try to reconnect in a minute to wake it again."
|
||||||
|
|
||||||
|
[lockout]
|
||||||
|
# Enable to prevent everybody from connecting through lazymc. Instantly kicks player.
|
||||||
|
#enabled = false
|
||||||
|
|
||||||
|
# Kick players with following message.
|
||||||
|
#message = "Server is closed §7☠§r\n\nPlease try to reconnect in a minute."
|
||||||
|
|
||||||
[rcon]
|
[rcon]
|
||||||
# Enable sleeping server through RCON.
|
# Enable sleeping server through RCON.
|
||||||
# Must be enabled on Windows.
|
# Must be enabled on Windows.
|
||||||
|
@@ -73,6 +73,10 @@ pub struct Config {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub messages: Messages,
|
pub messages: Messages,
|
||||||
|
|
||||||
|
/// Lockout feature.
|
||||||
|
#[serde(default)]
|
||||||
|
pub lockout: Lockout,
|
||||||
|
|
||||||
/// RCON configuration.
|
/// RCON configuration.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub rcon: Rcon,
|
pub rcon: Rcon,
|
||||||
@@ -216,6 +220,26 @@ impl Default for Messages {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lockout configuration.
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct Lockout {
|
||||||
|
/// Enable to prevent everybody from connecting through lazymc. Instantly kicks player.
|
||||||
|
pub enabled: bool,
|
||||||
|
|
||||||
|
/// Kick players with following message.
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Lockout {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
enabled: false,
|
||||||
|
message: "Server is closed §7☠§r\n\nPlease come back another time.".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// RCON configuration.
|
/// RCON configuration.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
@@ -38,6 +38,13 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
|
|||||||
config.public.address, config.server.address,
|
config.public.address, config.server.address,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if config.lockout.enabled {
|
||||||
|
warn!(
|
||||||
|
target: "lazymc",
|
||||||
|
"Lockout mode is enabled, nobody will be able to connect through the proxy",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn server monitor and signal handler services
|
// Spawn server monitor and signal handler services
|
||||||
tokio::spawn(service::monitor::service(config.clone(), server.clone()));
|
tokio::spawn(service::monitor::service(config.clone(), server.clone()));
|
||||||
tokio::spawn(service::signal::service(config.clone(), server.clone()));
|
tokio::spawn(service::signal::service(config.clone(), server.clone()));
|
||||||
@@ -58,7 +65,8 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
|
|||||||
/// Route inbound TCP stream to correct service, spawning a new task.
|
/// Route inbound TCP stream to correct service, spawning a new task.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn route(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
|
fn route(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
|
||||||
if server.state() == server::State::Started {
|
let should_proxy = server.state() == server::State::Started && !config.lockout.enabled;
|
||||||
|
if should_proxy {
|
||||||
route_proxy(inbound, config)
|
route_proxy(inbound, config)
|
||||||
} else {
|
} else {
|
||||||
route_status(inbound, config, server)
|
route_status(inbound, config, server)
|
||||||
|
@@ -104,6 +104,18 @@ pub async fn serve(
|
|||||||
.ok()
|
.ok()
|
||||||
.map(|p| p.name);
|
.map(|p| p.name);
|
||||||
|
|
||||||
|
// Kick if lockout is enabled
|
||||||
|
if config.lockout.enabled {
|
||||||
|
match username {
|
||||||
|
Some(username) => {
|
||||||
|
info!(target: "lazymc", "Kicked '{}' because lockout is enabled", username)
|
||||||
|
}
|
||||||
|
None => info!(target: "lazymc", "Kicked player because lockout is enabled"),
|
||||||
|
}
|
||||||
|
kick(&config.lockout.message, &mut writer).await?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Start server if not starting yet
|
// Start server if not starting yet
|
||||||
Server::start(config.clone(), server.clone(), username).await;
|
Server::start(config.clone(), server.clone(), username).await;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user