mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add random demay in AutoRelog
Useful when reconnecting many accounts at once Related issues: #663, #740, #975, #1312
This commit is contained in:
parent
bea5161d6f
commit
330dda9c15
5 changed files with 47 additions and 24 deletions
|
|
@ -10,22 +10,29 @@ namespace MinecraftClient.ChatBots
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AutoRelog : ChatBot
|
public class AutoRelog : ChatBot
|
||||||
{
|
{
|
||||||
|
private static Random random = new Random();
|
||||||
private string[] dictionary = new string[0];
|
private string[] dictionary = new string[0];
|
||||||
private int attempts;
|
private int attempts;
|
||||||
private int delay;
|
private int delayMin;
|
||||||
|
private int delayMax;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This bot automatically re-join the server if kick message contains predefined string
|
/// This bot automatically re-join the server if kick message contains predefined string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="DelayBeforeRelog">Delay before re-joining the server (in seconds)</param>
|
/// <param name="DelayBeforeRelogMin">Minimum delay before re-joining the server (in seconds)</param>
|
||||||
|
/// <param name="DelayBeforeRelogMax">Maximum 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 DelayBeforeRelogMin, int DelayBeforeRelogMax, int retries)
|
||||||
{
|
{
|
||||||
attempts = retries;
|
attempts = retries;
|
||||||
if (attempts == -1) { attempts = int.MaxValue; }
|
if (attempts == -1) { attempts = int.MaxValue; }
|
||||||
McClient.ReconnectionAttemptsLeft = attempts;
|
McClient.ReconnectionAttemptsLeft = attempts;
|
||||||
delay = DelayBeforeRelog;
|
delayMin = DelayBeforeRelogMin;
|
||||||
if (delay < 1) { delay = 1; }
|
delayMax = DelayBeforeRelogMax;
|
||||||
|
if (delayMin < 1)
|
||||||
|
delayMin = 1;
|
||||||
|
if (delayMax < delayMin)
|
||||||
|
delayMax = delayMin;
|
||||||
LogDebugToConsoleTranslated("bot.autoRelog.launch", attempts);
|
LogDebugToConsoleTranslated("bot.autoRelog.launch", attempts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +70,7 @@ namespace MinecraftClient.ChatBots
|
||||||
{
|
{
|
||||||
if (reason == DisconnectReason.UserLogout)
|
if (reason == DisconnectReason.UserLogout)
|
||||||
{
|
{
|
||||||
LogDebugToConsoleTranslated("bot.autoRelog.ignore");
|
LogDebugToConsoleTranslated("bot.autoRelog.ignore_user_logout");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -74,10 +81,7 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
if (Settings.AutoRelog_IgnoreKickMessage)
|
if (Settings.AutoRelog_IgnoreKickMessage)
|
||||||
{
|
{
|
||||||
LogDebugToConsoleTranslated("bot.autoRelog.reconnect_always");
|
LaunchDelayedReconnection(null);
|
||||||
LogToConsoleTranslated("bot.autoRelog.wait", delay);
|
|
||||||
System.Threading.Thread.Sleep(delay * 1000);
|
|
||||||
ReconnectToTheServer();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,11 +89,7 @@ namespace MinecraftClient.ChatBots
|
||||||
{
|
{
|
||||||
if (comp.Contains(msg))
|
if (comp.Contains(msg))
|
||||||
{
|
{
|
||||||
LogDebugToConsoleTranslated("bot.autoRelog.reconnect", msg);
|
LaunchDelayedReconnection(msg);
|
||||||
LogToConsoleTranslated("bot.autoRelog.wait", delay);
|
|
||||||
System.Threading.Thread.Sleep(delay * 1000);
|
|
||||||
McClient.ReconnectionAttemptsLeft = attempts;
|
|
||||||
ReconnectToTheServer();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -100,11 +100,20 @@ namespace MinecraftClient.ChatBots
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LaunchDelayedReconnection(string msg)
|
||||||
|
{
|
||||||
|
int delay = random.Next(delayMin, delayMax);
|
||||||
|
LogDebugToConsoleTranslated(String.IsNullOrEmpty(msg) ? "bot.autoRelog.reconnect_always" : "bot.autoRelog.reconnect", msg);
|
||||||
|
LogToConsoleTranslated("bot.autoRelog.wait", delay);
|
||||||
|
System.Threading.Thread.Sleep(delay * 1000);
|
||||||
|
ReconnectToTheServer();
|
||||||
|
}
|
||||||
|
|
||||||
public static bool OnDisconnectStatic(DisconnectReason reason, string message)
|
public static bool OnDisconnectStatic(DisconnectReason reason, string message)
|
||||||
{
|
{
|
||||||
if (Settings.AutoRelog_Enabled)
|
if (Settings.AutoRelog_Enabled)
|
||||||
{
|
{
|
||||||
AutoRelog bot = new AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries);
|
AutoRelog bot = new AutoRelog(Settings.AutoRelog_Delay_Min, Settings.AutoRelog_Delay_Max, Settings.AutoRelog_Retries);
|
||||||
bot.Initialize();
|
bot.Initialize();
|
||||||
return bot.OnDisconnect(reason, message);
|
return bot.OnDisconnect(reason, message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ namespace MinecraftClient
|
||||||
if (Settings.Alerts_Enabled) { BotLoad(new ChatBots.Alerts()); }
|
if (Settings.Alerts_Enabled) { BotLoad(new ChatBots.Alerts()); }
|
||||||
if (Settings.ChatLog_Enabled) { BotLoad(new ChatBots.ChatLog(Settings.ExpandVars(Settings.ChatLog_File), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
|
if (Settings.ChatLog_Enabled) { BotLoad(new ChatBots.ChatLog(Settings.ExpandVars(Settings.ChatLog_File), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
|
||||||
if (Settings.PlayerLog_Enabled) { BotLoad(new ChatBots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.ExpandVars(Settings.PlayerLog_File))); }
|
if (Settings.PlayerLog_Enabled) { BotLoad(new ChatBots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.ExpandVars(Settings.PlayerLog_File))); }
|
||||||
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
|
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay_Min, Settings.AutoRelog_Delay_Max, Settings.AutoRelog_Retries)); }
|
||||||
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
|
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
|
||||||
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
|
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
|
||||||
if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); }
|
if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); }
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,10 @@ command=/ping
|
||||||
|
|
||||||
[AutoRelog]
|
[AutoRelog]
|
||||||
enabled=false
|
enabled=false
|
||||||
delay=10
|
delay=10 # use 10 for 10 seconds, 10-60 for a random delay between 10 and 60 seconds
|
||||||
retries=3 #-1 = unlimited
|
retries=3 # retries when failing to relog to the server. use -1 for unlimited retries
|
||||||
ignorekickmessage=false
|
kickmessagesfile=kickmessages.txt # file with list of matches in kick messages that will trigger autorelog
|
||||||
kickmessagesfile=kickmessages.txt
|
ignorekickmessage=false # when set to true, autorelog will reconnect regardless of kick messages
|
||||||
|
|
||||||
[ChatLog]
|
[ChatLog]
|
||||||
enabled=false
|
enabled=false
|
||||||
|
|
|
||||||
|
|
@ -401,7 +401,7 @@ bot.autoRelog.loading=Loading messages from file: {0}
|
||||||
bot.autoRelog.loaded=Loaded message: {0}
|
bot.autoRelog.loaded=Loaded message: {0}
|
||||||
bot.autoRelog.not_found=File not found: {0}
|
bot.autoRelog.not_found=File not found: {0}
|
||||||
bot.autoRelog.curr_dir=Current directory was: {0}
|
bot.autoRelog.curr_dir=Current directory was: {0}
|
||||||
bot.autoRelog.ignore=Disconnection initiated by User or MCC bot. Ignoring.
|
bot.autoRelog.ignore_user_logout=Disconnection initiated by User or MCC bot. Ignoring.
|
||||||
bot.autoRelog.disconnect_msg=Got disconnected with message: {0}
|
bot.autoRelog.disconnect_msg=Got disconnected with message: {0}
|
||||||
bot.autoRelog.reconnect_always=Ignoring kick message, reconnecting anyway.
|
bot.autoRelog.reconnect_always=Ignoring kick message, reconnecting anyway.
|
||||||
bot.autoRelog.reconnect=Message contains '{0}'. Reconnecting.
|
bot.autoRelog.reconnect=Message contains '{0}'. Reconnecting.
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,8 @@ namespace MinecraftClient
|
||||||
|
|
||||||
//AutoRelog Settings
|
//AutoRelog Settings
|
||||||
public static bool AutoRelog_Enabled = false;
|
public static bool AutoRelog_Enabled = false;
|
||||||
public static int AutoRelog_Delay = 10;
|
public static int AutoRelog_Delay_Min = 10;
|
||||||
|
public static int AutoRelog_Delay_Max = 10;
|
||||||
public static int AutoRelog_Retries = 3;
|
public static int AutoRelog_Retries = 3;
|
||||||
public static bool AutoRelog_IgnoreKickMessage = false;
|
public static bool AutoRelog_IgnoreKickMessage = false;
|
||||||
public static string AutoRelog_KickMessagesFile = "kickmessages.txt";
|
public static string AutoRelog_KickMessagesFile = "kickmessages.txt";
|
||||||
|
|
@ -414,10 +415,23 @@ namespace MinecraftClient
|
||||||
switch (argName.ToLower())
|
switch (argName.ToLower())
|
||||||
{
|
{
|
||||||
case "enabled": AutoRelog_Enabled = str2bool(argValue); break;
|
case "enabled": AutoRelog_Enabled = str2bool(argValue); break;
|
||||||
case "delay": AutoRelog_Delay = str2int(argValue); break;
|
|
||||||
case "retries": AutoRelog_Retries = str2int(argValue); break;
|
case "retries": AutoRelog_Retries = str2int(argValue); break;
|
||||||
case "ignorekickmessage": AutoRelog_IgnoreKickMessage = str2bool(argValue); break;
|
case "ignorekickmessage": AutoRelog_IgnoreKickMessage = str2bool(argValue); break;
|
||||||
case "kickmessagesfile": AutoRelog_KickMessagesFile = argValue; break;
|
case "kickmessagesfile": AutoRelog_KickMessagesFile = argValue; break;
|
||||||
|
|
||||||
|
case "delay":
|
||||||
|
string[] delayParts = argValue.Split('-');
|
||||||
|
if (delayParts.Length == 1)
|
||||||
|
{
|
||||||
|
AutoRelog_Delay_Min = str2int(delayParts[0]);
|
||||||
|
AutoRelog_Delay_Max = AutoRelog_Delay_Min;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AutoRelog_Delay_Min = str2int(delayParts[0]);
|
||||||
|
AutoRelog_Delay_Max = str2int(delayParts[1]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue