AutoRelog: Add debug messages (#740)

This commit is contained in:
ORelio 2019-05-30 11:45:43 +02:00
parent 5b28179444
commit 9372d81738
2 changed files with 27 additions and 4 deletions

View file

@ -8,7 +8,6 @@ namespace MinecraftClient.ChatBots
/// <summary>
/// This bot automatically re-join the server if kick message contains predefined string (Server is restarting ...)
/// </summary>
public class AutoRelog : ChatBot
{
private string[] dictionary = new string[0];
@ -20,7 +19,6 @@ namespace MinecraftClient.ChatBots
/// </summary>
/// <param name="DelayBeforeRelog">Delay before re-joining the server (in seconds)</param>
/// <param name="retries">Number of retries if connection fails (-1 = infinite)</param>
public AutoRelog(int DelayBeforeRelog, int retries)
{
attempts = retries;
@ -28,6 +26,8 @@ namespace MinecraftClient.ChatBots
McTcpClient.ReconnectionAttemptsLeft = attempts;
delay = DelayBeforeRelog;
if (delay < 1) { delay = 1; }
if (Settings.DebugMessages)
LogToConsole("Launching with " + attempts + " reconnection attempts");
}
public override void Initialize()
@ -35,24 +35,41 @@ namespace MinecraftClient.ChatBots
McTcpClient.ReconnectionAttemptsLeft = attempts;
if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile))
{
if (Settings.DebugMessages)
LogToConsole("Loading messages from file: " + Settings.AutoRelog_KickMessagesFile);
dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile);
for (int i = 0; i < dictionary.Length; i++)
{
LogToConsole(" Loaded message: " + dictionary[i]);
dictionary[i] = dictionary[i].ToLower();
}
}
else LogToConsole("File not found: " + Settings.AutoRelog_KickMessagesFile);
else
{
LogToConsole("File not found: " + Settings.AutoRelog_KickMessagesFile);
if (Settings.DebugMessages)
LogToConsole(" Current directory was: " + System.IO.Directory.GetCurrentDirectory());
}
}
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 (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;
@ -60,6 +77,10 @@ namespace MinecraftClient.ChatBots
return true;
}
}
if (Settings.DebugMessages)
LogToConsole("Message not containing any defined keywords. Ignoring.");
return false;
}