mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
AutoRelog: Add debug messages (#740)
This commit is contained in:
parent
5b28179444
commit
9372d81738
2 changed files with 27 additions and 4 deletions
|
|
@ -8,7 +8,6 @@ namespace MinecraftClient.ChatBots
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This bot automatically re-join the server if kick message contains predefined string (Server is restarting ...)
|
/// This bot automatically re-join the server if kick message contains predefined string (Server is restarting ...)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public class AutoRelog : ChatBot
|
public class AutoRelog : ChatBot
|
||||||
{
|
{
|
||||||
private string[] dictionary = new string[0];
|
private string[] dictionary = new string[0];
|
||||||
|
|
@ -20,7 +19,6 @@ namespace MinecraftClient.ChatBots
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="DelayBeforeRelog">Delay before re-joining the server (in seconds)</param>
|
/// <param name="DelayBeforeRelog">Delay before re-joining the server (in seconds)</param>
|
||||||
/// <param name="retries">Number of retries if connection fails (-1 = infinite)</param>
|
/// <param name="retries">Number of retries if connection fails (-1 = infinite)</param>
|
||||||
|
|
||||||
public AutoRelog(int DelayBeforeRelog, int retries)
|
public AutoRelog(int DelayBeforeRelog, int retries)
|
||||||
{
|
{
|
||||||
attempts = retries;
|
attempts = retries;
|
||||||
|
|
@ -28,6 +26,8 @@ namespace MinecraftClient.ChatBots
|
||||||
McTcpClient.ReconnectionAttemptsLeft = attempts;
|
McTcpClient.ReconnectionAttemptsLeft = attempts;
|
||||||
delay = DelayBeforeRelog;
|
delay = DelayBeforeRelog;
|
||||||
if (delay < 1) { delay = 1; }
|
if (delay < 1) { delay = 1; }
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Launching with " + attempts + " reconnection attempts");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
|
|
@ -35,24 +35,41 @@ namespace MinecraftClient.ChatBots
|
||||||
McTcpClient.ReconnectionAttemptsLeft = attempts;
|
McTcpClient.ReconnectionAttemptsLeft = attempts;
|
||||||
if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile))
|
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);
|
dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile);
|
||||||
|
|
||||||
for (int i = 0; i < dictionary.Length; i++)
|
for (int i = 0; i < dictionary.Length; i++)
|
||||||
{
|
{
|
||||||
|
LogToConsole(" Loaded message: " + dictionary[i]);
|
||||||
dictionary[i] = dictionary[i].ToLower();
|
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)
|
public override bool OnDisconnect(DisconnectReason reason, string message)
|
||||||
{
|
{
|
||||||
message = GetVerbatim(message);
|
message = GetVerbatim(message);
|
||||||
string comp = message.ToLower();
|
string comp = message.ToLower();
|
||||||
|
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Got disconnected with message: " + message);
|
||||||
|
|
||||||
foreach (string msg in dictionary)
|
foreach (string msg in dictionary)
|
||||||
{
|
{
|
||||||
if (comp.Contains(msg))
|
if (comp.Contains(msg))
|
||||||
{
|
{
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Message contains '" + msg + "'. Reconnecting.");
|
||||||
|
|
||||||
LogToConsole("Waiting " + delay + " seconds before reconnecting...");
|
LogToConsole("Waiting " + delay + " seconds before reconnecting...");
|
||||||
System.Threading.Thread.Sleep(delay * 1000);
|
System.Threading.Thread.Sleep(delay * 1000);
|
||||||
McTcpClient.ReconnectionAttemptsLeft = attempts;
|
McTcpClient.ReconnectionAttemptsLeft = attempts;
|
||||||
|
|
@ -60,6 +77,10 @@ namespace MinecraftClient.ChatBots
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Message not containing any defined keywords. Ignoring.");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,9 @@ namespace MinecraftClient
|
||||||
if (ReconnectionAttemptsLeft > 0)
|
if (ReconnectionAttemptsLeft > 0)
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLogLine("Waiting 5 seconds (" + ReconnectionAttemptsLeft + " attempts left)...");
|
ConsoleIO.WriteLogLine("Waiting 5 seconds (" + ReconnectionAttemptsLeft + " attempts left)...");
|
||||||
Thread.Sleep(5000); ReconnectionAttemptsLeft--; Program.Restart();
|
Thread.Sleep(5000);
|
||||||
|
ReconnectionAttemptsLeft--;
|
||||||
|
Program.Restart();
|
||||||
}
|
}
|
||||||
else if (!singlecommand && Settings.interactiveMode)
|
else if (!singlecommand && Settings.interactiveMode)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue