diff --git a/res/lazymc.toml b/res/lazymc.toml index 39a848e..51d670f 100644 --- a/res/lazymc.toml +++ b/res/lazymc.toml @@ -1,21 +1,37 @@ # lazymc configuration +# +# You must configure your server directory and start command, see: +# - server.directory +# - server.command +# +# You can probably leave the rest as-is. +# +# You may generate a new configuration with: lazymc config generate +# Or find the latest at: https://is.gd/WWBIQu [public] # Public address. IP and port users connect to. # Shows sleeping status, starts server on connect, and proxies to server. address = "0.0.0.0:25565" +# Server version & protocol hint. +# Sent to clients until actual server version is known. +# See: https://is.gd/FTQKTP +version = "1.17.1" +protocol = 756 + [server] -# Server directory. +# Server address. Internal IP and port of server started by lazymc to proxy to. +# Port must be different from public port. +address = "127.0.0.1:25566" + +# Server directory, defaults to current directory. directory = "." # Command to start the server. -# Warning: if using a bash script read: https://github.com/timvisee/lazymc/blob/master/docs/command_bash.md +# Warning: if using a bash script read: https://is.gd/k8SQYv command = "java -Xmx1G -Xms1G -jar server.jar --nogui" -# Server address. Internal IP and port of server started by lazymc to proxy to. -address = "127.0.0.1:25566" - # Immediately wake server when starting lazymc. wake_on_start = false @@ -27,19 +43,13 @@ sleep_after = 60 minimum_online_time = 60 [messages] -# MOTD when server is sleeping. +# MOTDs, shown in server browser. motd_sleeping = "☠ Server is sleeping\n§2☻ Join to start it up" - -# MOTD when server is starting. motd_starting = "§2☻ Server is starting...\n§7⌛ Please wait..." - -# MOTD when server is stopping. motd_stopping = "☠ Server going to sleep...\n⌛ Please wait..." -# Login (kick) message when server is starting. +# Login messages, when user tries to connect. login_starting = "Server is starting... §c♥§r\n\nThis may take some time.\n\nPlease try to reconnect in a minute." - -# Login (kick) message when server is stopping. login_stopping = "Server is going to sleep... §7☠§r\n\nPlease try to reconnect in a minute to wake it again." [rcon] @@ -47,13 +57,12 @@ login_stopping = "Server is going to sleep... §7☠§r\n\nPlease try to reconne # Must be enabled on Windows. enabled = true -# Server RCON port. Must differ from Minecraft server port. +# Server RCON port. Must differ from public and server port. port = 25575 # Server RCON password. +# Or whether to randomize password each start (recommended). password = "" - -# Randomize ingress server RCON password on each start. randomize_password = true [advanced] diff --git a/src/config.rs b/src/config.rs index a29aa84..ab2764b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -91,6 +91,12 @@ pub struct Public { /// Egress address. #[serde(alias = "address_egress")] pub address: SocketAddr, + + /// Minecraft protocol version name hint. + pub version: String, + + /// Minecraft protocol version hint. + pub protocol: u32, } /// Server configuration. diff --git a/src/monitor.rs b/src/monitor.rs index 59ce21f..b076e67 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -14,7 +14,7 @@ use tokio::io::AsyncWriteExt; use tokio::net::TcpStream; use crate::config::Config; -use crate::proto::{self, ClientState, RawPacket, PROTO_DEFAULT_PROTOCOL}; +use crate::proto::{self, ClientState, RawPacket}; use crate::server::Server; /// Monitor ping inverval in seconds. @@ -31,7 +31,7 @@ pub async fn monitor_server(config: Arc, state: Arc) { loop { // Poll server state and update internal status trace!(target: "lazymc::monitor", "Fetching status for {} ... ", addr); - let status = poll_server(addr).await; + let status = poll_server(&config, addr).await; state.update_status(&config, status); // Sleep server when it's bedtime @@ -50,23 +50,27 @@ pub async fn monitor_server(config: Arc, state: Arc) { /// Poll server state. /// /// Returns server status if connection succeeded. -pub async fn poll_server(addr: SocketAddr) -> Option { - fetch_status(addr).await.ok() +pub async fn poll_server(config: &Config, addr: SocketAddr) -> Option { + fetch_status(config, addr).await.ok() } /// Attemp to fetch status from server. -async fn fetch_status(addr: SocketAddr) -> Result { +async fn fetch_status(config: &Config, addr: SocketAddr) -> Result { let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?; - send_handshake(&mut stream, addr).await?; + send_handshake(&mut stream, &config, addr).await?; request_status(&mut stream).await?; wait_for_status_timeout(&mut stream).await } /// Send handshake. -async fn send_handshake(stream: &mut TcpStream, addr: SocketAddr) -> Result<(), ()> { +async fn send_handshake( + stream: &mut TcpStream, + config: &Config, + addr: SocketAddr, +) -> Result<(), ()> { let handshake = Handshake { - protocol_version: PROTO_DEFAULT_PROTOCOL as i32, + protocol_version: config.public.protocol as i32, server_addr: addr.ip().to_string(), server_port: addr.port(), next_state: ClientState::Status.to_id(), diff --git a/src/proto.rs b/src/proto.rs index 8bc3263..bfab27d 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -10,13 +10,13 @@ use crate::types; /// Default minecraft protocol version name. /// /// Send to clients when the server is sleeping when the real server version is not known yet. -pub const PROTO_DEFAULT_VERSION: &str = "1.16.5"; +pub const PROTO_DEFAULT_VERSION: &str = "1.17.1"; /// Default minecraft protocol version. /// /// Send to clients when the server is sleeping when the real server version is not known yet, and /// with server status polling requests. -pub const PROTO_DEFAULT_PROTOCOL: u32 = 754; +pub const PROTO_DEFAULT_PROTOCOL: u32 = 756; /// Handshake state, handshake packet ID. pub const HANDSHAKE_PACKET_ID_HANDSHAKE: i32 = 0; diff --git a/src/status.rs b/src/status.rs index 1fb1b47..fd69483 100644 --- a/src/status.rs +++ b/src/status.rs @@ -13,9 +13,7 @@ use tokio::io::AsyncWriteExt; use tokio::net::TcpStream; use crate::config::*; -use crate::proto::{ - self, Client, ClientState, RawPacket, PROTO_DEFAULT_PROTOCOL, PROTO_DEFAULT_VERSION, -}; +use crate::proto::{self, Client, ClientState, RawPacket}; use crate::server::{self, Server}; /// Proxy the given inbound stream to a target address. @@ -88,8 +86,8 @@ pub async fn serve( Some(status) => (status.version, status.players.max), None => ( ServerVersion { - name: String::from(PROTO_DEFAULT_VERSION), - protocol: PROTO_DEFAULT_PROTOCOL, + name: config.public.version.clone(), + protocol: config.public.protocol, }, 0, ),