AutoRelog: Allow any kick message

Set ignorekickmessage=true in config
See issues #880 #921
This commit is contained in:
ORelio 2020-04-02 18:19:37 +02:00
parent dbe02c063c
commit c5b0f447c9
5 changed files with 41 additions and 15 deletions

View file

@ -572,6 +572,8 @@ namespace MinecraftClient
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
protected void ReconnectToTheServer(int ExtraAttempts = 3, int delaySeconds = 0)
{
if (Settings.DebugMessages)
ConsoleIO.WriteLogLine(String.Format("[{0}] Disconnecting and Reconnecting to the Server", this.GetType().Name));
McTcpClient.ReconnectionAttemptsLeft = ExtraAttempts;
Program.Restart(delaySeconds);
}

View file

@ -33,6 +33,13 @@ namespace MinecraftClient.ChatBots
public override void Initialize()
{
McTcpClient.ReconnectionAttemptsLeft = attempts;
if (Settings.AutoRelog_IgnoreKickMessage)
{
if (Settings.DebugMessages)
LogToConsole("Initializing without a kick message file");
}
else
{
if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile))
{
if (Settings.DebugMessages)
@ -55,13 +62,14 @@ namespace MinecraftClient.ChatBots
LogToConsole(" Current directory was: " + System.IO.Directory.GetCurrentDirectory());
}
}
}
public override bool OnDisconnect(DisconnectReason reason, string message)
{
if (reason == DisconnectReason.UserLogout)
{
if (Settings.DebugMessages)
LogToConsole("Ignoring disconnection initiated by User or MCC bot");
LogToConsole("Disconnection initiated by User or MCC bot. Ignoring.");
}
else
{
@ -71,6 +79,14 @@ namespace MinecraftClient.ChatBots
if (Settings.DebugMessages)
LogToConsole("Got disconnected with message: " + message);
if (Settings.AutoRelog_IgnoreKickMessage)
{
if (Settings.DebugMessages)
LogToConsole("Ignoring kick message, reconnecting anyway.");
ReconnectToTheServer();
return true;
}
foreach (string msg in dictionary)
{
if (comp.Contains(msg))

View file

@ -473,6 +473,10 @@ namespace MinecraftClient.Protocol.Handlers
foreach (var item in nbt)
{
// Skip NBT root name
if (item.Key == "" && root)
continue;
byte fieldType;
byte[] fieldNameLength = GetUShort((ushort)item.Key.Length);
byte[] fieldName = Encoding.ASCII.GetBytes(item.Key);

View file

@ -130,6 +130,7 @@ namespace MinecraftClient
public static bool AutoRelog_Enabled = false;
public static int AutoRelog_Delay = 10;
public static int AutoRelog_Retries = 3;
public static bool AutoRelog_IgnoreKickMessage = false;
public static string AutoRelog_KickMessagesFile = "kickmessages.txt";
//Script Scheduler Settings
@ -363,6 +364,7 @@ namespace MinecraftClient
case "enabled": AutoRelog_Enabled = str2bool(argValue); break;
case "delay": AutoRelog_Delay = str2int(argValue); break;
case "retries": AutoRelog_Retries = str2int(argValue); break;
case "ignorekickmessage": AutoRelog_IgnoreKickMessage = str2bool(argValue); break;
case "kickmessagesfile": AutoRelog_KickMessagesFile = argValue; break;
}
break;
@ -639,6 +641,7 @@ namespace MinecraftClient
+ "enabled=false\r\n"
+ "delay=10\r\n"
+ "retries=3 #-1 = unlimited\r\n"
+ "ignorekickmessage=false\r\n"
+ "kickmessagesfile=kickmessages.txt\r\n"
+ "\r\n"
+ "[ChatLog]\r\n"

View file

@ -192,6 +192,7 @@ A kick message "Connection has been lost." is generated by the console itself wh
A kick message "Login failed." is generated the same way when it failed to login to the server.
A kick message "Failed to ping this IP." is generated when it failed to ping the server.
You can use them for reconnecting when connection is lost or the login failed.
If you want to always reconnect, set ignorekickmessage=true in MinecraftClient.ini. Use at own risk!
Using the Script Scheduler
------