Fix AutoRelog not triggering when initial TCP connection fails (server offline)

When AutoRelog was enabled and the server was offline (SocketException during
initial connection), AutoRelog's reconnection logic was never invoked. The
Retry block's else branch either called HandleFailure() without a disconnect
reason (so AutoRelog.OnDisconnectStatic was skipped) or did nothing at all.

Now the else branch directly calls AutoRelog.OnDisconnectStatic with the
standard "Connection has been lost" message (matching the default
Kick_Messages), ensuring reconnection is properly triggered.

Fixes MCCTeam/Minecraft-Console-Client#2781

Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/30698499-fdeb-44ce-9552-a64c4c5fb62b
This commit is contained in:
copilot-swe-agent[bot] 2026-03-25 10:43:50 +00:00
parent 33d050583a
commit 5c9319c10d

View file

@ -313,19 +313,23 @@ namespace MinecraftClient
}
else
{
// The AutoRelog ChatBot will handle reconnection at this point.
// This is important, or else we'll have multiple instances of the client running at the same time.
// AutoRelog is enabled - invoke its static handler to trigger reconnection.
// Use the same "Connection has been lost" message that OnConnectionLost uses
// for ConnectionLost, so it matches the default Kick_Messages.
if (AutoRelog.OnDisconnectStatic(ChatBot.DisconnectReason.ConnectionLost, Translations.mcc_disconnect_lost))
return; // AutoRelog is triggering a restart
if (ReconnectionAttemptsLeft == 0)
// AutoRelog chose not to reconnect (e.g., message didn't match
// kick messages and Ignore_Kick_Message is false, or retry limit reached)
if (InternalConfig.InteractiveMode)
{
if (InternalConfig.InteractiveMode)
{
ConsoleInteractive.ConsoleReader.StopReadThread();
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
Program.HandleFailure();
}
ConsoleInteractive.ConsoleReader.StopReadThread();
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
Program.HandleFailure();
}
throw new Exception("Initialization failed.");
}
}