Kick user with proper ban message, tweak IP file change debounce time

This commit is contained in:
timvisee 2021-11-17 20:21:22 +01:00
parent 9cc1958bbd
commit 75f7b62b16
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
3 changed files with 15 additions and 5 deletions

View File

@ -43,6 +43,7 @@ https://user-images.githubusercontent.com/856222/141378688-882082be-9efa-4cfe-81
- _Lobby: keep client in emulated server with lobby world, teleport to real server when ready ([experimental*](./docs/join-method-lobby.md))_ - _Lobby: keep client in emulated server with lobby world, teleport to real server when ready ([experimental*](./docs/join-method-lobby.md))_
- Customizable MOTD and login messages - Customizable MOTD and login messages
- Automatically manages `server.properties` (host, port and RCON settings) - Automatically manages `server.properties` (host, port and RCON settings)
- Automatically handle banned IPs from server within `lazymc`
- 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 - Lockout mode

View File

@ -11,7 +11,7 @@ use crate::mc::ban;
use crate::server::Server; use crate::server::Server;
/// File debounce time. /// File debounce time.
const WATCH_DEBOUNCE: Duration = Duration::from_secs(1); const WATCH_DEBOUNCE: Duration = Duration::from_secs(2);
/// Service to reload banned IPs when its file changes. /// Service to reload banned IPs when its file changes.
pub fn service(config: Arc<Config>, server: Arc<Server>) { pub fn service(config: Arc<Config>, server: Arc<Server>) {

View File

@ -19,6 +19,9 @@ use crate::proto::packet::{self, RawPacket};
use crate::proto::packets; use crate::proto::packets;
use crate::server::{self, Server}; use crate::server::{self, Server};
/// The ban message prefix.
const BAN_MESSAGE_PREFIX: &str = "Your IP address is banned from this server.\nReason: ";
/// Default ban reason if unknown. /// Default ban reason if unknown.
const DEFAULT_BAN_REASON: &str = "Banned by an operator."; const DEFAULT_BAN_REASON: &str = "Banned by an operator.";
@ -133,13 +136,19 @@ pub async fn serve(
// Kick if client is banned // Kick if client is banned
if let Some(ban) = server.ban_entry(&client.peer.ip()).await { if let Some(ban) = server.ban_entry(&client.peer.ip()).await {
if ban.is_banned() { if ban.is_banned() {
if let Some(reason) = ban.reason { let msg = if let Some(reason) = ban.reason {
info!(target: "lazymc", "Login from banned IP {} ({}), disconnecting", client.peer.ip(), &reason); info!(target: "lazymc", "Login from banned IP {} ({}), disconnecting", client.peer.ip(), &reason);
action::kick(&client, &reason, &mut writer).await?; reason.to_string()
} else { } else {
info!(target: "lazymc", "Login from banned IP {}, disconnecting", client.peer.ip()); info!(target: "lazymc", "Login from banned IP {}, disconnecting", client.peer.ip());
action::kick(&client, DEFAULT_BAN_REASON, &mut writer).await?; DEFAULT_BAN_REASON.to_string()
} };
action::kick(
&client,
&format!("{}{}", BAN_MESSAGE_PREFIX, msg),
&mut writer,
)
.await?;
break; break;
} }
} }