Minecraft-Console-Client/MinecraftClient/ChatBots/AutoRelog.cs
ORelio d2ec2f48b7 App refactoring almost done
- Created specific namespaces and folders for each app brick
- Added proxy support using Starksoft's Biko Library
- App bricks: Main, ChatBots, Crypto, Protocol, Proxy
- Each class is now in its own file (Aes streams, chatbots)
- Used "Bridge" design pattern for Crypto, Protocol, Proxy
- Added back support for Minecraft 1.4.6 to 1.6.4 (MCC 1.6.2)
- Need to fully re-test everything and fix bugs
- To Fix : Server pinging is slow on SpigotMC
- To Do : Add Minecraft 1.2.5 (MCC 1.3) and maybe 1.3 to 1.4.5
2014-05-31 01:59:03 +02:00

66 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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];
private int attempts;
private int delay;
/// <summary>
/// This bot automatically re-join the server if kick message contains predefined string
/// </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;
if (attempts == -1) { attempts = int.MaxValue; }
McTcpClient.AttemptsLeft = attempts;
delay = DelayBeforeRelog;
if (delay < 1) { delay = 1; }
}
public override void Initialize()
{
McTcpClient.AttemptsLeft = attempts;
if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile))
{
dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile);
for (int i = 0; i < dictionary.Length; i++)
{
dictionary[i] = dictionary[i].ToLower();
}
}
else LogToConsole("File not found: " + Settings.AutoRelog_KickMessagesFile);
}
public override bool OnDisconnect(DisconnectReason reason, string message)
{
message = getVerbatim(message);
string comp = message.ToLower();
foreach (string msg in dictionary)
{
if (comp.Contains(msg))
{
LogToConsole("Waiting " + delay + " seconds before reconnecting...");
System.Threading.Thread.Sleep(delay * 1000);
McTcpClient.AttemptsLeft = attempts;
ReconnectToTheServer();
return true;
}
}
return false;
}
}
}