Improve bot suspend while reconnecting

See #259
This commit is contained in:
ORelio 2017-03-29 21:25:14 +02:00
parent b848460a5c
commit bab472df05

View file

@ -26,7 +26,7 @@ namespace MinecraftClient
private readonly Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid, string>(); private readonly Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid, string>();
private readonly List<ChatBot> bots = new List<ChatBot>(); private readonly List<ChatBot> bots = new List<ChatBot>();
private static readonly List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>(); private static readonly List<ChatBot> botsOnHold = new List<ChatBot>();
private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new Dictionary<string, List<ChatBot>>(); private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new Dictionary<string, List<ChatBot>>();
private readonly List<string> registeredServerPluginChannels = new List<String>(); private readonly List<string> registeredServerPluginChannels = new List<String>();
@ -108,6 +108,8 @@ namespace MinecraftClient
this.port = port; this.port = port;
if (!singlecommand) if (!singlecommand)
{
if (botsOnHold.Count == 0)
{ {
if (Settings.AntiAFK_Enabled) { BotLoad(new ChatBots.AntiAFK(Settings.AntiAFK_Delay)); } if (Settings.AntiAFK_Enabled) { BotLoad(new ChatBots.AntiAFK(Settings.AntiAFK_Delay)); }
if (Settings.Hangman_Enabled) { BotLoad(new ChatBots.HangmanGame(Settings.Hangman_English)); } if (Settings.Hangman_Enabled) { BotLoad(new ChatBots.HangmanGame(Settings.Hangman_English)); }
@ -121,6 +123,7 @@ namespace MinecraftClient
//Add your ChatBot here by uncommenting and adapting //Add your ChatBot here by uncommenting and adapting
//BotLoad(new ChatBots.YourBot()); //BotLoad(new ChatBots.YourBot());
} }
}
try try
{ {
@ -143,10 +146,9 @@ namespace MinecraftClient
} }
else else
{ {
foreach (ChatBot bot in scripts_on_hold) foreach (ChatBot bot in botsOnHold)
bot.SetHandler(this); BotLoad(bot, false);
bots.AddRange(scripts_on_hold); botsOnHold.Clear();
scripts_on_hold.Clear();
Console.WriteLine("Server was successfully joined.\nType '" Console.WriteLine("Server was successfully joined.\nType '"
+ (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar)
@ -310,9 +312,8 @@ namespace MinecraftClient
/// </summary> /// </summary>
public void Disconnect() public void Disconnect()
{ {
foreach (ChatBot bot in bots) botsOnHold.Clear();
if (bot is ChatBots.Script) botsOnHold.AddRange(bots);
scripts_on_hold.Add((ChatBots.Script)bot);
if (handler != null) if (handler != null)
{ {
@ -332,15 +333,14 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Load a new bot /// Load a new bot
/// </summary> /// </summary>
public void BotLoad(ChatBot b) public void BotLoad(ChatBot b, bool init = true)
{ {
b.SetHandler(this); b.SetHandler(this);
bots.Add(b); bots.Add(b);
if (init)
b.Initialize(); b.Initialize();
if (this.handler != null) if (this.handler != null)
{
b.AfterGameJoined(); b.AfterGameJoined();
}
Settings.SingleCommand = ""; Settings.SingleCommand = "";
} }