Fix AutoRelog running twice on disconnection

Bug introduced in commit aaf1e8311b
Implement User-Initiated logout reason to ignore the second logout event
See #817
This commit is contained in:
ORelio 2019-12-08 22:24:20 +01:00
parent 94e96b11dd
commit 52d98538b3
3 changed files with 35 additions and 24 deletions

View file

@ -58,29 +58,37 @@ namespace MinecraftClient.ChatBots
public override bool OnDisconnect(DisconnectReason reason, string message)
{
message = GetVerbatim(message);
string comp = message.ToLower();
if (Settings.DebugMessages)
LogToConsole("Got disconnected with message: " + message);
foreach (string msg in dictionary)
if (reason == DisconnectReason.UserLogout)
{
if (comp.Contains(msg))
{
if (Settings.DebugMessages)
LogToConsole("Message contains '" + msg + "'. Reconnecting.");
LogToConsole("Waiting " + delay + " seconds before reconnecting...");
System.Threading.Thread.Sleep(delay * 1000);
McTcpClient.ReconnectionAttemptsLeft = attempts;
ReconnectToTheServer();
return true;
}
if (Settings.DebugMessages)
LogToConsole("Ignoring disconnection initiated by User or MCC bot");
}
else
{
message = GetVerbatim(message);
string comp = message.ToLower();
if (Settings.DebugMessages)
LogToConsole("Message not containing any defined keywords. Ignoring.");
if (Settings.DebugMessages)
LogToConsole("Got disconnected with message: " + message);
foreach (string msg in dictionary)
{
if (comp.Contains(msg))
{
if (Settings.DebugMessages)
LogToConsole("Message contains '" + msg + "'. Reconnecting.");
LogToConsole("Waiting " + delay + " seconds before reconnecting...");
System.Threading.Thread.Sleep(delay * 1000);
McTcpClient.ReconnectionAttemptsLeft = attempts;
ReconnectToTheServer();
return true;
}
}
if (Settings.DebugMessages)
LogToConsole("Message not containing any defined keywords. Ignoring.");
}
return false;
}