Compare commits

..

16 Commits

Author SHA1 Message Date
timvisee
d058164aa6
Bump version to 0.2.11 2024-03-16 18:08:26 +01:00
timvisee
8ed68b1ddf
Bump MSRV to 1.74.0 2024-03-16 18:05:04 +01:00
timvisee
0eec1e0b55
Use 1.20.3 protocol version 2024-03-16 18:01:03 +01:00
timvisee
485941cf81
Update uuid dependency 2024-03-16 13:45:26 +01:00
timvisee
a1008ad2a7
Update nix dependency 2024-03-16 13:31:42 +01:00
timvisee
b22d32b951
Upgrade toml dependency 2024-03-16 13:31:38 +01:00
timvisee
18f26b00cb
Update dependencies around rcon 2024-03-16 13:31:35 +01:00
timvisee
86428f4501
Update dependencies 2024-03-16 12:54:48 +01:00
timvisee
c311313ecb
Improve error handling when reading server favicon 2024-03-16 12:50:32 +01:00
timvisee
6e6d098cf1
Resolve clippy warnings 2024-03-16 12:50:25 +01:00
timvisee
efb047114e
Update Cargo.lock 2024-03-16 12:43:03 +01:00
Tim Visée
37fdb9c12a
Merge pull request #54 from Spongecade/patch-1
Update Minecraft wiki links to new domain
2023-10-13 18:53:23 +02:00
Spongecade
e7a3db19aa
Update Minecraft wiki links to new domain 2023-10-05 15:26:24 -05:00
timvisee
ca4753673d
Run CI on shared GitLab runners 2023-08-20 17:33:32 +02:00
timvisee
0124aa723d
Merge branch 'Xeyler-master' into master
Refs: https://github.com/timvisee/lazymc/pull/50
2023-05-30 22:41:04 +02:00
Xeyler
afbc54758c
Update monitor.rs 2023-05-27 23:14:48 -06:00
16 changed files with 619 additions and 982 deletions

View File

@ -7,11 +7,6 @@ stages:
- pre-release
- release
default:
tags:
- linux
- timvisee-linux
# Variable defaults
variables:
RUST_VERSION: stable
@ -57,7 +52,7 @@ check-stable:
check-msrv:
<<: *check-base
variables:
RUST_VERSION: 1.64.0
RUST_VERSION: 1.74.0
only:
- master

View File

@ -1,5 +1,12 @@
# Changelog
## 0.2.11 (2024-03-16)
- Add support for Minecraft 1.20.3 and 1.20.4
- Improve error handling of parsing server favicon
- Fix typo in log message
- Update dependencies
## 0.2.10 (2023-02-20)
- Do not report an error when server exits with status code 143

1471
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package]
name = "lazymc"
version = "0.2.10"
version = "0.2.11"
authors = ["Tim Visee <3a4fb3964f@sinenomine.email>"]
license = "GPL-3.0"
readme = "README.md"
@ -11,6 +11,7 @@ keywords = ["minecraft", "server", "idle", "cli"]
categories = ["command-line-interface", "games"]
exclude = ["/.github", "/contrib"]
edition = "2021"
rust-version = "1.74.0"
[profile.release]
codegen-units = 1
@ -23,7 +24,7 @@ default = ["rcon", "lobby"]
# RCON support
# Allow use of RCON to manage (stop) server.
# Required on Windows.
rcon = ["rust_rcon", "async-std"]
rcon = ["rust_rcon"]
# Lobby support
# Add lobby join method, keeps client in fake lobby world until server is ready.
@ -31,7 +32,7 @@ lobby = ["md-5", "uuid"]
[dependencies]
anyhow = "1.0"
base64 = "0.21"
base64 = "0.22"
bytes = "1.1"
chrono = "0.4"
clap = { version = "4.0.32", default-features = false, features = [
@ -45,16 +46,16 @@ clap = { version = "4.0.32", default-features = false, features = [
"unicode",
] }
colored = "2.0"
derive_builder = "0.12"
derive_builder = "0.20"
dotenv = "0.15"
flate2 = { version = "1.0", default-features = false, features = ["default"] }
futures = { version = "0.3", default-features = false, features = ["executor"] }
log = "0.4"
minecraft-protocol = { git = "https://github.com/timvisee/rust-minecraft-protocol", rev = "edfdf87" }
minecraft-protocol = { git = "https://github.com/timvisee/rust-minecraft-protocol", rev = "4f93bb3" }
named-binary-tag = "0.6"
nix = "0.26"
nix = { version = "0.28", features = ["process", "signal"] }
notify = "4.0"
pretty_env_logger = "0.4"
pretty_env_logger = "0.5"
proxy-protocol = "0.5"
quartz_nbt = "0.2"
rand = "0.8"
@ -73,16 +74,15 @@ tokio = { version = "1", default-features = false, features = [
"sync",
"fs",
] }
toml = "0.5"
version-compare = "0.1"
toml = "0.8"
version-compare = "0.2"
# Feature: rcon
rust_rcon = { package = "rcon", version = "0.5.2", optional = true }
async-std = { version = "1.9.0", default-features = false, optional = true }
rust_rcon = { package = "rcon", version = "0.6", default-features = false, features = ["rt-tokio"], optional = true }
# Feature: lobby
md-5 = { version = "0.10", optional = true }
uuid = { version = "0.7", optional = true, features = ["v3"] }
uuid = { version = "1.7", optional = true, features = ["v3"] }
[target.'cfg(unix)'.dependencies]
libc = "0.2"

View File

@ -35,7 +35,7 @@ https://user-images.githubusercontent.com/856222/141378688-882082be-9efa-4cfe-81
## Features
- Very efficient, lightweight & low-profile (~3KB RAM)
- Supports Minecraft Java Edition 1.7.2+, supports modded (e.g. Forge, FTB)
- Supports Minecraft Java Edition 1.20.3+
- Configure joining client occupation methods:
- Hold: hold clients when server starts, relay when ready, without them noticing
- Kick: kick clients when server starts, with a starting message
@ -57,7 +57,7 @@ https://user-images.githubusercontent.com/856222/141378688-882082be-9efa-4cfe-81
Build requirements:
- Rust 1.64 (MSRV)
- Rust 1.74 (MSRV)
_Note: You must have access to the system to run the `lazymc` binary. If you're
using a Minecraft shared hosting provider with a custom dashboard, you likely

View File

@ -18,8 +18,8 @@
# Server version & protocol hint.
# Sent to clients until actual server version is known.
# See: https://git.io/J1Fvx
#version = "1.19.3"
#protocol = 761
#version = "1.20.3"
#protocol = 765
[server]
# Server address. Internal IP and port of server started by lazymc to proxy to.
@ -187,4 +187,4 @@ command = "java -Xmx1G -Xms1G -jar server.jar --nogui"
[config]
# lazymc version this configuration is for.
# Don't change unless you know what you're doing.
version = "0.2.10"
version = "0.2.11"

View File

@ -108,8 +108,8 @@ pub struct Config {
impl Config {
/// Load configuration from file.
pub fn load(path: PathBuf) -> Result<Self, io::Error> {
let data = fs::read(&path)?;
let mut config: Config = toml::from_slice(&data)?;
let data = fs::read_to_string(&path)?;
let mut config: Config = toml::from_str(&data).map_err(io::Error::other)?;
// Show warning if config version is problematic
match &config.config.version {

View File

@ -652,7 +652,7 @@ async fn drain_stream(reader: &mut ReadHalf<'_>) -> Result<(), ()> {
let mut drain_buf = [0; 8 * 1024];
loop {
match reader.try_read(&mut drain_buf) {
Ok(read) if read == 0 => return Ok(()),
Ok(0) => return Ok(()),
Err(err) if err.kind() == ErrorKind::WouldBlock => return Ok(()),
Ok(_) => continue,
Err(err) => {

View File

@ -1,8 +1,8 @@
use std::time::Duration;
use async_std::net::TcpStream;
use async_std::prelude::*;
use rust_rcon::{Connection, Error as RconError};
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
use tokio::time;
use crate::config::Config;
@ -17,7 +17,7 @@ const QUIRK_RCON_GRACE_TIME: Duration = Duration::from_millis(200);
/// An RCON client.
pub struct Rcon {
con: Connection,
con: Connection<TcpStream>,
}
impl Rcon {
@ -39,7 +39,7 @@ impl Rcon {
// Start connection
let con = Connection::builder()
.enable_minecraft_quirks(true)
.connect_stream(stream, pass)
.handshake(stream, pass)
.await?;
Ok(Self { con })

View File

@ -3,11 +3,10 @@ use std::sync::Arc;
use std::time::Duration;
use bytes::BytesMut;
use minecraft_protocol::data::server_status::ServerStatus;
use minecraft_protocol::decoder::Decoder;
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
use minecraft_protocol::version::v1_14_4::status::{
PingRequest, PingResponse, StatusRequest, StatusResponse,
use minecraft_protocol::version::v1_20_3::status::{
PingRequest, PingResponse, ServerStatus, StatusRequest, StatusResponse,
};
use rand::Rng;
use tokio::io::AsyncWriteExt;
@ -57,13 +56,13 @@ pub async fn monitor_server(config: Arc<Config>, server: Arc<Server>) {
// Sleep server when it's bedtime
if server.should_sleep(&config).await {
info!(target: "lazymc::montior", "Server has been idle, sleeping...");
info!(target: "lazymc::monitor", "Server has been idle, sleeping...");
server.stop(&config).await;
}
// Check whether we should force kill server
if server.should_kill().await {
error!(target: "lazymc::montior", "Force killing server, took too long to start or stop");
error!(target: "lazymc::monitor", "Force killing server, took too long to start or stop");
if !server.force_kill().await {
warn!(target: "lazymc", "Failed to force kill server");
}

View File

@ -2,7 +2,10 @@
pub mod windows;
#[cfg(unix)]
use nix::{sys::signal, unistd::Pid};
use nix::{
sys::signal::{self, Signal},
unistd::Pid,
};
/// Force kill process.
///
@ -10,7 +13,7 @@ use nix::{sys::signal, unistd::Pid};
#[allow(unreachable_code)]
pub fn force_kill(pid: u32) -> bool {
#[cfg(unix)]
return unix_signal(pid, signal::SIGKILL);
return unix_signal(pid, Signal::SIGKILL);
#[cfg(windows)]
unsafe {
@ -28,7 +31,7 @@ pub fn force_kill(pid: u32) -> bool {
#[allow(unreachable_code, dead_code, unused_variables)]
pub fn kill_gracefully(pid: u32) -> bool {
#[cfg(unix)]
return unix_signal(pid, signal::SIGTERM);
return unix_signal(pid, Signal::SIGTERM);
unimplemented!(
"gracefully killing Minecraft server process not implemented on non-Unix platforms"
@ -43,7 +46,7 @@ pub fn kill_gracefully(pid: u32) -> bool {
#[allow(unreachable_code)]
pub fn freeze(pid: u32) -> bool {
#[cfg(unix)]
return unix_signal(pid, signal::SIGSTOP);
return unix_signal(pid, Signal::SIGSTOP);
unimplemented!(
"freezing the Minecraft server process is not implemented on non-Unix platforms"
@ -58,7 +61,7 @@ pub fn freeze(pid: u32) -> bool {
#[allow(unreachable_code)]
pub fn unfreeze(pid: u32) -> bool {
#[cfg(unix)]
return unix_signal(pid, signal::SIGCONT);
return unix_signal(pid, Signal::SIGCONT);
unimplemented!(
"unfreezing the Minecraft server process is not implemented on non-Unix platforms"
@ -66,12 +69,12 @@ pub fn unfreeze(pid: u32) -> bool {
}
#[cfg(unix)]
pub fn unix_signal(pid: u32, signal: signal::Signal) -> bool {
return match signal::kill(Pid::from_raw(pid as i32), signal) {
pub fn unix_signal(pid: u32, signal: Signal) -> bool {
match signal::kill(Pid::from_raw(pid as i32), signal) {
Ok(()) => true,
Err(err) => {
warn!(target: "lazymc", "Sending {signal} signal to server failed: {err}");
false
}
};
}
}

View File

@ -9,7 +9,7 @@ pub mod packets;
/// in the configuration.
///
/// Should be kept up-to-date with latest supported Minecraft version by lazymc.
pub const PROTO_DEFAULT_VERSION: &str = "1.19.3";
pub const PROTO_DEFAULT_VERSION: &str = "1.20.3";
/// Default minecraft protocol version.
///
@ -17,7 +17,7 @@ pub const PROTO_DEFAULT_VERSION: &str = "1.19.3";
/// in the configuration.
///
/// Should be kept up-to-date with latest supported Minecraft version by lazymc.
pub const PROTO_DEFAULT_PROTOCOL: u32 = 761;
pub const PROTO_DEFAULT_PROTOCOL: u32 = 765;
/// Compression threshold to use.
// TODO: read this from server.properties instead

View File

@ -70,7 +70,7 @@ async fn send_v1_16_3(
packet::write_packet(
Title {
action: if title.is_empty() && subtitle.is_empty() {
// Defaults: https://minecraft.fandom.com/wiki/Commands/title#Detail
// Defaults: https://minecraft.wiki/w/Commands/title#Detail
TitleAction::SetTimesAndDisplay {
fade_in: 10,
stay: 70,
@ -121,7 +121,7 @@ async fn send_v1_17(
// Set title times
packet::write_packet(
if title.is_empty() && subtitle.is_empty() {
// Defaults: https://minecraft.fandom.com/wiki/Commands/title#Detail
// Defaults: https://minecraft.wiki/w/Commands/title#Detail
SetTitleTimes {
fade_in: 10,
stay: 70,

View File

@ -4,7 +4,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use futures::FutureExt;
use minecraft_protocol::data::server_status::ServerStatus;
use minecraft_protocol::version::v1_20_3::status::ServerStatus;
use tokio::process::Command;
use tokio::sync::watch;
#[cfg(feature = "rcon")]

View File

@ -25,7 +25,7 @@ pub fn service(config: Arc<Config>, server: Arc<Server>) {
};
// Keep watching
#[allow(clippy::blocks_in_if_conditions)]
#[allow(clippy::blocks_in_conditions)]
while {
// Update all files once
reload_bans(&config, &server, &dir.join(ban::FILE));

View File

@ -1,13 +1,12 @@
use std::sync::Arc;
use bytes::BytesMut;
use minecraft_protocol::data::chat::{Message, Payload};
use minecraft_protocol::data::server_status::*;
use minecraft_protocol::data::server_status::{OnlinePlayers, ServerVersion};
use minecraft_protocol::decoder::Decoder;
use minecraft_protocol::encoder::Encoder;
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
use minecraft_protocol::version::v1_14_4::login::LoginStart;
use minecraft_protocol::version::v1_14_4::status::StatusResponse;
use minecraft_protocol::version::v1_20_3::status::{ServerStatus, StatusResponse};
use tokio::fs;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
@ -232,11 +231,11 @@ async fn server_status(client_info: &ClientInfo, config: &Config, server: &Serve
if config.motd.from_server && status.is_some() {
status.as_ref().unwrap().description.clone()
} else {
Message::new(Payload::text(match server_state {
server::State::Stopped | server::State::Started => &config.motd.sleeping,
server::State::Starting => &config.motd.starting,
server::State::Stopping => &config.motd.stopping,
}))
match server_state {
server::State::Stopped | server::State::Started => config.motd.sleeping.clone(),
server::State::Starting => config.motd.starting.clone(),
server::State::Stopping => config.motd.stopping.clone(),
}
}
};
@ -281,15 +280,10 @@ async fn server_favicon(config: &Config) -> String {
}
// Read icon data
let data = match fs::read(path).await.map_err(|err| {
error!(target: "lazymc", "Failed to read favicon from {}: {}", SERVER_ICON_FILE, err);
}) {
Ok(data) => data,
Err(err) => {
error!(target: "lazymc::status", "Failed to load server icon from disk, using default: {:?}", err);
return favicon::default_favicon();
}
};
let data = fs::read(path).await.unwrap_or_else(|err| {
error!(target: "lazymc::status", "Failed to read favicon from {}, using default: {err}", SERVER_ICON_FILE);
favicon::default_favicon().into_bytes()
});
favicon::encode_favicon(&data)
}