Add lockout mode, enable to prevent all players from connecting
This commit is contained in:
@@ -73,6 +73,10 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub messages: Messages,
|
||||
|
||||
/// Lockout feature.
|
||||
#[serde(default)]
|
||||
pub lockout: Lockout,
|
||||
|
||||
/// RCON configuration.
|
||||
#[serde(default)]
|
||||
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.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(default)]
|
||||
|
@@ -38,6 +38,13 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
|
||||
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
|
||||
tokio::spawn(service::monitor::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.
|
||||
#[inline]
|
||||
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)
|
||||
} else {
|
||||
route_status(inbound, config, server)
|
||||
|
@@ -104,6 +104,18 @@ pub async fn serve(
|
||||
.ok()
|
||||
.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
|
||||
Server::start(config.clone(), server.clone(), username).await;
|
||||
|
||||
|
Reference in New Issue
Block a user