Set config defaults, comment out defaults in base config file

This commit is contained in:
timvisee 2021-11-09 15:13:28 +01:00
parent bbecb43639
commit e7741f4ece
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
2 changed files with 92 additions and 22 deletions

View File

@ -4,6 +4,7 @@
# - server.directory # - server.directory
# - server.command # - server.command
# #
# All defaults are commented out, change it if you desire.
# You can probably leave the rest as-is. # You can probably leave the rest as-is.
# #
# You may generate a new configuration with: lazymc config generate # You may generate a new configuration with: lazymc config generate
@ -12,18 +13,18 @@
[public] [public]
# Public address. IP and port users connect to. # Public address. IP and port users connect to.
# Shows sleeping status, starts server on connect, and proxies to server. # Shows sleeping status, starts server on connect, and proxies to server.
address = "0.0.0.0:25565" #address = "0.0.0.0:25565"
# Server version & protocol hint. # Server version & protocol hint.
# Sent to clients until actual server version is known. # Sent to clients until actual server version is known.
# See: https://is.gd/FTQKTP # See: https://is.gd/FTQKTP
version = "1.17.1" #version = "1.17.1"
protocol = 756 #protocol = 756
[server] [server]
# Server address. Internal IP and port of server started by lazymc to proxy to. # Server address. Internal IP and port of server started by lazymc to proxy to.
# Port must be different from public port. # Port must be different from public port.
address = "127.0.0.1:25566" #address = "127.0.0.1:25566"
# Server directory, defaults to current directory. # Server directory, defaults to current directory.
directory = "." directory = "."
@ -33,38 +34,38 @@ directory = "."
command = "java -Xmx1G -Xms1G -jar server.jar --nogui" command = "java -Xmx1G -Xms1G -jar server.jar --nogui"
# Immediately wake server when starting lazymc. # Immediately wake server when starting lazymc.
wake_on_start = false #wake_on_start = false
[time] [time]
# Sleep after number of seconds. # Sleep after number of seconds.
sleep_after = 60 #sleep_after = 60
# Minimum time in seconds to stay online when server is started. # Minimum time in seconds to stay online when server is started.
minimum_online_time = 60 #minimum_online_time = 60
[messages] [messages]
# MOTDs, shown in server browser. # MOTDs, shown in server browser.
motd_sleeping = "☠ Server is sleeping\n§2☻ Join to start it up" #motd_sleeping = "☠ Server is sleeping\n§2☻ Join to start it up"
motd_starting = "§2☻ Server is starting...\n§7⌛ Please wait..." #motd_starting = "§2☻ Server is starting...\n§7⌛ Please wait..."
motd_stopping = "☠ Server going to sleep...\n⌛ Please wait..." #motd_stopping = "☠ Server going to sleep...\n⌛ Please wait..."
# Login messages, when user tries to connect. # 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_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."
[rcon] [rcon]
# Enable sleeping server through RCON. # Enable sleeping server through RCON.
# Must be enabled on Windows. # Must be enabled on Windows.
enabled = true #enabled = true
# Server RCON port. Must differ from public and server port. # Server RCON port. Must differ from public and server port.
port = 25575 #port = 25575
# Server RCON password. # Server RCON password.
# Or whether to randomize password each start (recommended). # Or whether to randomize password each start (recommended).
password = "" #password = ""
randomize_password = true #randomize_password = true
[advanced] [advanced]
# Automatically update values in Minecraft server.properties file as required. # Automatically update values in Minecraft server.properties file as required.
rewrite_server_properties = true #rewrite_server_properties = true

View File

@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
use clap::ArgMatches; use clap::ArgMatches;
use serde::Deserialize; use serde::Deserialize;
use crate::proto;
use crate::util::error::{quit_error, quit_error_msg, ErrorHintsBuilder}; use crate::util::error::{quit_error, quit_error_msg, ErrorHintsBuilder};
/// Default configuration file location. /// Default configuration file location.
@ -58,21 +59,26 @@ pub fn load(matches: &ArgMatches) -> Config {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Config { pub struct Config {
/// Public configuration. /// Public configuration.
#[serde(default)]
pub public: Public, pub public: Public,
/// Server configuration. /// Server configuration.
pub server: Server, pub server: Server,
/// Time configuration. /// Time configuration.
#[serde(default)]
pub time: Time, pub time: Time,
/// Messages, shown to the user. /// Messages, shown to the user.
#[serde(default)]
pub messages: Messages, pub messages: Messages,
/// RCON configuration. /// RCON configuration.
#[serde(default)]
pub rcon: Rcon, pub rcon: Rcon,
/// Advanced configuration. /// Advanced configuration.
#[serde(default)]
pub advanced: Advanced, pub advanced: Advanced,
} }
@ -87,9 +93,9 @@ impl Config {
/// Public configuration. /// Public configuration.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Public { pub struct Public {
/// Egress address. /// Public address.
#[serde(alias = "address_egress")]
pub address: SocketAddr, pub address: SocketAddr,
/// Minecraft protocol version name hint. /// Minecraft protocol version name hint.
@ -99,17 +105,28 @@ pub struct Public {
pub protocol: u32, pub protocol: u32,
} }
impl Default for Public {
fn default() -> Self {
Self {
address: "0.0.0.0:25565".parse().unwrap(),
version: proto::PROTO_DEFAULT_VERSION.to_string(),
protocol: proto::PROTO_DEFAULT_PROTOCOL,
}
}
}
/// Server configuration. /// Server configuration.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Server { pub struct Server {
/// Server directory. /// Server directory.
#[serde(default = "option_pathbuf_dot")]
pub directory: Option<PathBuf>, pub directory: Option<PathBuf>,
/// Start command. /// Start command.
pub command: String, pub command: String,
/// Ingress address. /// Server address.
#[serde(alias = "address_ingress")] #[serde(default = "server_address_default")]
pub address: SocketAddr, pub address: SocketAddr,
/// Immediately wake server when starting lazymc. /// Immediately wake server when starting lazymc.
@ -119,6 +136,7 @@ pub struct Server {
/// Time configuration. /// Time configuration.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Time { pub struct Time {
/// Sleep after number of seconds. /// Sleep after number of seconds.
pub sleep_after: u32, pub sleep_after: u32,
@ -128,8 +146,18 @@ pub struct Time {
pub min_online_time: u32, pub min_online_time: u32,
} }
impl Default for Time {
fn default() -> Self {
Self {
sleep_after: 60,
min_online_time: 60,
}
}
}
/// Message configuration. /// Message configuration.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Messages { pub struct Messages {
/// MOTD when server is sleeping. /// MOTD when server is sleeping.
pub motd_sleeping: String, pub motd_sleeping: String,
@ -147,8 +175,21 @@ pub struct Messages {
pub login_stopping: String, pub login_stopping: String,
} }
impl Default for Messages {
fn default() -> Self {
Self {
motd_sleeping: "☠ Server is sleeping\n§2☻ Join to start it up".into(),
motd_starting: "§2☻ Server is starting...\n§7⌛ Please wait...".into(),
motd_stopping: "☠ Server going to sleep...\n⌛ Please wait...".into(),
login_starting: "Server is starting... §c♥§r\n\nThis may take some time.\n\nPlease try to reconnect in a minute.".into(),
login_stopping: "Server is going to sleep... §7☠§r\n\nPlease try to reconnect in a minute to wake it again.".into(),
}
}
}
/// RCON configuration. /// RCON configuration.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Rcon { pub struct Rcon {
/// Enable sleeping server through RCON. /// Enable sleeping server through RCON.
pub enabled: bool, pub enabled: bool,
@ -159,13 +200,41 @@ pub struct Rcon {
/// Server RCON password. /// Server RCON password.
pub password: String, pub password: String,
/// Randomize ingress server RCON password on each start. /// Randomize server RCON password on each start.
pub randomize_password: bool, pub randomize_password: bool,
} }
impl Default for Rcon {
fn default() -> Self {
Self {
enabled: true,
port: 25575,
password: "".into(),
randomize_password: true,
}
}
}
/// Advanced configuration. /// Advanced configuration.
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Advanced { pub struct Advanced {
/// Rewrite server.properties. /// Rewrite server.properties.
pub rewrite_server_properties: bool, pub rewrite_server_properties: bool,
} }
impl Default for Advanced {
fn default() -> Self {
Self {
rewrite_server_properties: true,
}
}
}
fn option_pathbuf_dot() -> Option<PathBuf> {
Some(".".into())
}
fn server_address_default() -> SocketAddr {
"127.0.0.1:25566".parse().unwrap()
}