Tnze / go-mc

Collection of Go libraries for Minecraft
https://go-mc.github.io/tutorial/
MIT License
858 stars 115 forks source link

Keepalive disconnect #251

Closed maxsupermanhd closed 1 year ago

maxsupermanhd commented 1 year ago

Describe the bug When server crashes or connection hangs bot never exits.

Additional context I am struggling to find where it is even processed (if at all)

Tnze commented 1 year ago

If the server is closed by stop command. Or the server kicks the player for some reason. It sends a ClientboundDisconnect packet and will be handled here. https://github.com/Tnze/go-mc/blob/b09ea0a3eb7fe4aefbedf3cbc1cf682572b5554e/bot/basic/events.go#L61-L63 and here https://github.com/Tnze/go-mc/blob/b09ea0a3eb7fe4aefbedf3cbc1cf682572b5554e/bot/basic/events.go#L81-L92


But I guess what you want to say is about the keepalive system. The vanilla clients will close the connection when server doesn't send keepalive packets any more. This feature is currently not available, but we can easily achieve it. Just set a timer and .Close() on the connection.