mirror of
https://github.com/timvisee/lazymc.git
synced 2025-07-28 02:32:00 -07:00
Log what user woke up the server
This commit is contained in:
@@ -127,12 +127,18 @@ impl Server {
|
||||
/// Try to start the server.
|
||||
///
|
||||
/// Does nothing if currently not in stopped state.
|
||||
pub fn start(config: Arc<Config>, server: Arc<Server>) -> bool {
|
||||
pub fn start(config: Arc<Config>, server: Arc<Server>, username: Option<String>) -> bool {
|
||||
// Must set state from stopped to starting
|
||||
if !server.update_state_from(Some(State::Stopped), State::Starting, &config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log starting message
|
||||
match username {
|
||||
Some(username) => info!(target: "lazymc", "Starting server for '{}'...", username),
|
||||
None => info!(target: "lazymc", "Starting server..."),
|
||||
}
|
||||
|
||||
// Invoke server command in separate task
|
||||
tokio::spawn(invoke_server_cmd(config, server).map(|_| ()));
|
||||
true
|
||||
@@ -254,7 +260,6 @@ pub async fn invoke_server_cmd(
|
||||
}
|
||||
|
||||
// Spawn process
|
||||
info!(target: "lazymc", "Starting server...");
|
||||
let mut child = match cmd.spawn() {
|
||||
Ok(child) => child,
|
||||
Err(err) => {
|
||||
|
@@ -39,7 +39,7 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
|
||||
|
||||
// Initiate server start
|
||||
if config.server.wake_on_start {
|
||||
Server::start(config.clone(), server.clone());
|
||||
Server::start(config.clone(), server.clone(), None);
|
||||
}
|
||||
|
||||
// Proxy all incomming connections
|
||||
|
@@ -6,7 +6,7 @@ use minecraft_protocol::data::server_status::*;
|
||||
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::LoginDisconnect;
|
||||
use minecraft_protocol::version::v1_14_4::login::{LoginDisconnect, LoginStart};
|
||||
use minecraft_protocol::version::v1_14_4::status::StatusResponse;
|
||||
use tokio::io;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
@@ -42,6 +42,11 @@ pub async fn serve(
|
||||
|
||||
// Hijack login start
|
||||
if client.state() == ClientState::Login && packet.id == proto::LOGIN_PACKET_ID_LOGIN_START {
|
||||
// Try to get login username
|
||||
let username = LoginStart::decode(&mut packet.data.as_slice())
|
||||
.ok()
|
||||
.map(|p| p.name);
|
||||
|
||||
// Select message
|
||||
let msg = match server.state() {
|
||||
server::State::Starting | server::State::Stopped | server::State::Started => {
|
||||
@@ -61,7 +66,7 @@ pub async fn serve(
|
||||
writer.write_all(&response).await.map_err(|_| ())?;
|
||||
|
||||
// Start server if not starting yet
|
||||
Server::start(config, server);
|
||||
Server::start(config, server, username);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user