mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Make AutoRelog more reliable
Makes AutoRelog more hands on with the relogging rather than have the general relogging handler handle it. Fallback to the general handler only when the AutoRelog module is disabled.
This commit is contained in:
parent
c78245c056
commit
a72a8cf833
2 changed files with 42 additions and 20 deletions
|
|
@ -153,6 +153,7 @@ namespace MinecraftClient
|
|||
|
||||
private static IMinecraftComHandler? instance;
|
||||
public static IMinecraftComHandler? Instance => instance;
|
||||
|
||||
/// <summary>
|
||||
/// Starts the main chat client, wich will login to the server using the MinecraftCom class.
|
||||
/// </summary>
|
||||
|
|
@ -245,28 +246,48 @@ namespace MinecraftClient
|
|||
|
||||
return;
|
||||
|
||||
Retry:
|
||||
Retry:
|
||||
if (timeoutdetector != null)
|
||||
{
|
||||
timeoutdetector.Item2.Cancel();
|
||||
timeoutdetector = null;
|
||||
}
|
||||
if (ReconnectionAttemptsLeft > 0)
|
||||
{
|
||||
Log.Info(string.Format(Translations.mcc_reconnect, ReconnectionAttemptsLeft));
|
||||
Thread.Sleep(5000);
|
||||
ReconnectionAttemptsLeft--;
|
||||
Program.Restart();
|
||||
}
|
||||
else if (InternalConfig.InteractiveMode)
|
||||
{
|
||||
ConsoleInteractive.ConsoleReader.StopReadThread();
|
||||
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
|
||||
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
||||
Program.HandleFailure();
|
||||
}
|
||||
|
||||
throw new Exception("Initialization failed.");
|
||||
if (!Config.ChatBot.AutoRelog.Enabled)
|
||||
{
|
||||
if (ReconnectionAttemptsLeft > 0)
|
||||
{
|
||||
Log.Info(string.Format(Translations.mcc_reconnect, ReconnectionAttemptsLeft));
|
||||
Thread.Sleep(5000);
|
||||
ReconnectionAttemptsLeft--;
|
||||
Program.Restart();
|
||||
}
|
||||
else if (InternalConfig.InteractiveMode)
|
||||
{
|
||||
ConsoleInteractive.ConsoleReader.StopReadThread();
|
||||
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
|
||||
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
||||
Program.HandleFailure();
|
||||
}
|
||||
|
||||
throw new Exception("Initialization failed.");
|
||||
}
|
||||
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.
|
||||
|
||||
if (ReconnectionAttemptsLeft == 0)
|
||||
{
|
||||
if (InternalConfig.InteractiveMode)
|
||||
{
|
||||
ConsoleInteractive.ConsoleReader.StopReadThread();
|
||||
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
|
||||
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
||||
Program.HandleFailure();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -572,7 +593,7 @@ namespace MinecraftClient
|
|||
ConsoleInteractive.ConsoleReader.StopReadThread();
|
||||
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
|
||||
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
||||
Program.HandleFailure();
|
||||
Program.HandleFailure(message, false, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue