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

@ -349,12 +349,12 @@ namespace MinecraftClient
}
/// <summary>
/// Disconnect the client from the server
/// Disconnect the client from the server (initiated from MCC)
/// </summary>
public void Disconnect()
{
foreach (ChatBot bot in bots.ToArray())
bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Disconnected");
bot.OnDisconnect(ChatBot.DisconnectReason.UserLogout, "");
botsOnHold.Clear();
botsOnHold.AddRange(bots);
@ -721,7 +721,7 @@ namespace MinecraftClient
}
/// <summary>
/// When connection has been lost
/// When connection has been lost, login was denied or played was kicked from the server
/// </summary>
public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
{
@ -751,6 +751,9 @@ namespace MinecraftClient
ConsoleIO.WriteLine("Login failed :");
ConsoleIO.WriteLineFormatted(message);
break;
case ChatBot.DisconnectReason.UserLogout:
throw new InvalidOperationException("User-initiated logout should be done by calling Disconnect()");
}
foreach (ChatBot bot in bots.ToArray())