mirror of
https://github.com/timvisee/lazymc.git
synced 2025-08-07 07:31:59 -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.
|
/// Try to start the server.
|
||||||
///
|
///
|
||||||
/// Does nothing if currently not in stopped state.
|
/// 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
|
// Must set state from stopped to starting
|
||||||
if !server.update_state_from(Some(State::Stopped), State::Starting, &config) {
|
if !server.update_state_from(Some(State::Stopped), State::Starting, &config) {
|
||||||
return false;
|
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
|
// Invoke server command in separate task
|
||||||
tokio::spawn(invoke_server_cmd(config, server).map(|_| ()));
|
tokio::spawn(invoke_server_cmd(config, server).map(|_| ()));
|
||||||
true
|
true
|
||||||
@@ -254,7 +260,6 @@ pub async fn invoke_server_cmd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn process
|
// Spawn process
|
||||||
info!(target: "lazymc", "Starting server...");
|
|
||||||
let mut child = match cmd.spawn() {
|
let mut child = match cmd.spawn() {
|
||||||
Ok(child) => child,
|
Ok(child) => child,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@@ -39,7 +39,7 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
|
|||||||
|
|
||||||
// Initiate server start
|
// Initiate server start
|
||||||
if config.server.wake_on_start {
|
if config.server.wake_on_start {
|
||||||
Server::start(config.clone(), server.clone());
|
Server::start(config.clone(), server.clone(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy all incomming connections
|
// Proxy all incomming connections
|
||||||
|
@@ -6,7 +6,7 @@ use minecraft_protocol::data::server_status::*;
|
|||||||
use minecraft_protocol::decoder::Decoder;
|
use minecraft_protocol::decoder::Decoder;
|
||||||
use minecraft_protocol::encoder::Encoder;
|
use minecraft_protocol::encoder::Encoder;
|
||||||
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
|
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 minecraft_protocol::version::v1_14_4::status::StatusResponse;
|
||||||
use tokio::io;
|
use tokio::io;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
@@ -42,6 +42,11 @@ pub async fn serve(
|
|||||||
|
|
||||||
// Hijack login start
|
// Hijack login start
|
||||||
if client.state() == ClientState::Login && packet.id == proto::LOGIN_PACKET_ID_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
|
// Select message
|
||||||
let msg = match server.state() {
|
let msg = match server.state() {
|
||||||
server::State::Starting | server::State::Stopped | server::State::Started => {
|
server::State::Starting | server::State::Stopped | server::State::Started => {
|
||||||
@@ -61,7 +66,7 @@ pub async fn serve(
|
|||||||
writer.write_all(&response).await.map_err(|_| ())?;
|
writer.write_all(&response).await.map_err(|_| ())?;
|
||||||
|
|
||||||
// Start server if not starting yet
|
// Start server if not starting yet
|
||||||
Server::start(config, server);
|
Server::start(config, server, username);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user