timvisee / lazymc

💤 Put your Minecraft server to rest when idle.
GNU General Public License v3.0
600 stars 17 forks source link

Unable to connect #57

Closed stefanrybacki closed 8 months ago

stefanrybacki commented 1 year ago

Just found your project, thank you for that.

However, I am not able to get it to work correctly. I set up lazymc as stated in the documentation and the logs seem to indicate the setup is correct. But, when connecting I always run into the connection timeout even though the server is running.

Any ideas what could be the culprit here (it seems lazymc does not recognize the server to be ready loading, as it detects a too long start)?

Here are the logs from lazymc:

Rewritten server.properties file with updated values
Oct 31 08:18:32 minecraft lazymc[7100]:  INFO  lazymc > Proxying public 0.0.0.0:25565 to server 127.0.0.1:25566
Oct 31 08:18:32 minecraft lazymc[7100]:  INFO  lazymc > Starting server...
Oct 31 08:18:32 minecraft lazymc[7105]: Starting net.minecraft.server.Main
Oct 31 08:18:36 minecraft lazymc[7105]: [08:18:36] [ServerMain/INFO]: Environment: Environment[accountsHost=https://api.mojang.com, sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD]
Oct 31 08:18:37 minecraft lazymc[7105]: [08:18:37] [ServerMain/INFO]: Loaded 7 recipes
Oct 31 08:18:37 minecraft lazymc[7105]: [08:18:37] [ServerMain/INFO]: Loaded 1271 advancements
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Starting minecraft server version 1.20.2
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Loading properties
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Default game type: SURVIVAL
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Generating keypair
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Starting Minecraft server on 127.0.0.1:25566
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Using epoll channel type
Oct 31 08:18:38 minecraft lazymc[7105]: [08:18:38] [Server thread/INFO]: Preparing level "world"
Oct 31 08:18:41 minecraft lazymc[7105]: [08:18:41] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-2/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-1/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-1/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-2/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-1/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-2/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-1/INFO]: Preparing spawn area: 0%
Oct 31 08:18:44 minecraft lazymc[7105]: [08:18:44] [Worker-Main-1/INFO]: Preparing spawn area: 0%
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Worker-Main-1/INFO]: Preparing spawn area: 9%
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Worker-Main-2/INFO]: Preparing spawn area: 76%
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Server thread/INFO]: Time elapsed: 4762 ms
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Server thread/INFO]: Done (7.628s)! For help, type "help"
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Server thread/INFO]: Starting remote control listener
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Server thread/INFO]: Thread RCON Listener started
Oct 31 08:18:45 minecraft lazymc[7105]: [08:18:45] [Server thread/INFO]: RCON running on 127.0.0.1:25575
Oct 31 08:19:30 minecraft lazymc[7100]:  WARN  lazymc > Held client reached timeout of 28s
Oct 31 08:20:32 minecraft lazymc[7100]:  WARN  lazymc > Held client reached timeout of 28s
Oct 31 08:23:32 minecraft lazymc[7100]:  ERROR lazymc::monitor > Force killing server, took too long to start or stop
Oct 31 08:23:32 minecraft lazymc[7100]:  WARN  lazymc          > Server process stopped with error code (signal: 9 (SIGKILL))
Oct 31 08:23:34 minecraft lazymc[7100]:  ERROR lazymc::monitor > Force killing server, took too long to start or stop
Oct 31 08:23:34 minecraft lazymc[7100]:  WARN  lazymc          > Failed to force kill server
Oct 31 08:23:35 minecraft lazymc[7100]:  INFO  lazymc::monitor > Server is now sleeping
Oct 31 08:23:35 minecraft lazymc[7100]:  ERROR lazymc::probe   > Server stopped while trying to probe, skipping
Oct 31 08:23:35 minecraft lazymc[7100]:  WARN  lazymc::probe   > Couldn't probe server, failed to wait for server to come online
Oct 31 08:23:35 minecraft lazymc[7100]:  ERROR lazymc::probe   > Failed to probe server, this may limit lazymc features

Thanks in advance

Lahvuun commented 11 months ago

Hello OP and anyone else trying to figure out how to get this thing to work! I looked into it, and the reason this seems to be happening is that lazymc expects a different status response schema from the one it actually gets in 1.20.4 servers:

{"version":{"name":"1.19.4","protocol":762},"enforcesSecureChat":true,"description":{"text":"A Minecraft Server"},"players":{"max":20,"online":0}}
{"version":{"name":"1.20.4","protocol":765},"description":"A Minecraft Server","players":{"max":20,"online":0}}

As you can see, description in 1.19.4 is a JSON object (specifically, it's supposed to be the same type a chat message is, at least according to this third-party protocol documentation), but in 1.20.4 it is a plain string. This results in a silent decode failure at https://github.com/timvisee/lazymc/blob/37fdb9c12a1d56a07ce412252189b19428505788/src/monitor.rs#L187 Honestly, the error should've been bubbled all the way up, or at least logged properly, so nobody has to spend a couple hours tracking down what goes wrong, but whatever…

The decoding is done by a package called rust-minecraft-protocol. It seems that timvisee attempted to add some sort of multi-version support to it, but I'm too lazy to figure out how to make use of it in and whatnot, so here's the diff you have to apply to the crate (make sure you're on the lazymc-multiver branch):

diff --git a/protocol/src/data/server_status.rs b/protocol/src/data/server_status.rs
index 151eb55..17e1339 100644
--- a/protocol/src/data/server_status.rs
+++ b/protocol/src/data/server_status.rs
@@ -7,7 +7,7 @@ use uuid::Uuid;
 pub struct ServerStatus {
     pub version: ServerVersion,
     pub players: OnlinePlayers,
-    pub description: Message,
+    pub description: String,
     pub favicon: Option<String>,
 }

Then you need to patch lazymc itself:

diff --git a/src/status.rs b/src/status.rs
index 54bf985..453484d 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -232,11 +232,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 {
+            match server_state {
                 server::State::Stopped | server::State::Started => &config.motd.sleeping,
                 server::State::Starting => &config.motd.starting,
                 server::State::Stopping => &config.motd.stopping,
-            }))
+            }.to_string()
         }
     };

These changes will probably break lazymc for any server that's below 1.20.4, but at least it now works with the current version.

I'm thinking that lazymc's status handling probably needs a rewrite to account for multiple possible schemas, but I'm not the person to do it.

JherekC62 commented 11 months ago

hi, just wanted to say thanks for this, it works for me with versions 1.20.4+

sudhir-chandra commented 10 months ago

Thanks Lahvuun, that did it for me too! I'm attaching the binary I compiled in case anyone doesn't know how/can't be bothered to compile it themselves, as I often am. 😁 Download: binary.

bold-gman commented 10 months ago

Thank you @sudhir-chandra, that saved me from installing a rust environment in a VM and building a new version on my own :)

@Lahvuun's method throws a probing error when starting, but it's seems to work perfectly fine as quick and dirty workaround until a proper fix arrives,

derp90 commented 10 months ago

I ran into this issue as well,

@Lahvuun 's solution (I downloaded his BIN) fixed it for me

012456 commented 9 months ago

the provided binary didn't function on my alpine linux machine (perhaps because using musl instead of glibc? unsure). i applied Lahvuun's patches (thank you) to repo forks, which can be built with:

$ cargo install -f --git https://git.cozy.software/slime/lazymc --rev c3d1618ba8
luckspt commented 9 months ago

I also had this issue and unfortunately sudhir-chandra's bin did not solve it for me. For that, I looked up alternatives and found out about Minecraft Server Hibernation which worked for me on 1.20.4

timvisee commented 8 months ago

I've just released lazymc 0.2.11 which support Minecraft 1.20.3 and up.