Hold on scripts when reconnecting + login 503

- Added "connect" command in scripts (idea from TorchRJ_)
- Handle 503 service unavailable error for Minecraft logins
- Renamed [Scripting] into [StartupScript] (more explicit)
- Startup Script only runs once even using /reco but ...
- Scripts are now kept and resumed when (re)connecting
This commit is contained in:
ORelio 2014-04-10 16:13:30 +02:00
parent cd2fe152e6
commit b0e4e993ce
4 changed files with 31 additions and 9 deletions

View file

@ -931,6 +931,13 @@ namespace MinecraftClient
case "exit": //Exit bot & stay connected to the server
UnloadBot();
break;
case "connect":
if (instruction_line.Length >= 9)
{
Settings.ServerIP = instruction_line.Substring(8);
ReconnectToTheServer();
}
break;
default:
sleepticks = 0; Update(); //Unknown command : process next line immediately
break;

View file

@ -15,7 +15,7 @@ namespace MinecraftClient
{
#region Login to Minecraft.net and get a new session ID
public enum LoginResult { OtherError, SSLError, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
public enum LoginResult { OtherError, ServiceUnavailable, SSLError, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
/// <summary>
/// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme.
@ -66,6 +66,10 @@ namespace MinecraftClient
else return LoginResult.WrongPassword;
}
}
else if ((int)response.StatusCode == 503)
{
return LoginResult.ServiceUnavailable;
}
else return LoginResult.Blocked;
}
else if (e.Status == WebExceptionStatus.SendFailure)
@ -110,6 +114,11 @@ namespace MinecraftClient
bool encrypted = false;
int protocolversion;
public MinecraftCom()
{
foreach (ChatBot bot in scripts_on_hold) { bots.Add(bot); }
scripts_on_hold.Clear();
}
public bool Update()
{
for (int i = 0; i < bots.Count; i++) { bots[i].Update(); }
@ -586,9 +595,14 @@ namespace MinecraftClient
catch (System.IO.IOException) { }
catch (NullReferenceException) { }
catch (ObjectDisposedException) { }
foreach (ChatBot bot in bots)
if (bot is Bots.Scripting)
scripts_on_hold.Add((Bots.Scripting)bot);
}
private List<ChatBot> bots = new List<ChatBot>();
private static List<Bots.Scripting> scripts_on_hold = new List<Bots.Scripting>();
public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; }
public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); }
public void BotClear() { bots.Clear(); }

View file

@ -162,7 +162,7 @@ namespace MinecraftClient
if (Settings.ChatLog_Enabled) { handler.BotLoad(new Bots.ChatLog(Settings.ChatLog_File, Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File)); }
if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); }
if (Settings.StartupScript_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; }
if (Settings.RemoteCtrl_Enabled){ handler.BotLoad(new Bots.RemoteControl()); }
//Start the main TCP client
@ -192,6 +192,7 @@ namespace MinecraftClient
{
case MinecraftCom.LoginResult.AccountMigrated: Console.WriteLine("Account migrated, use e-mail as username."); break;
case MinecraftCom.LoginResult.Blocked: Console.WriteLine("Too many failed logins. Please try again later."); break;
case MinecraftCom.LoginResult.ServiceUnavailable: Console.WriteLine("Login servers are unavailable. Please try again later."); break;
case MinecraftCom.LoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break;
case MinecraftCom.LoginResult.NotPremium: Console.WriteLine("User not premium."); break;
case MinecraftCom.LoginResult.OtherError: Console.WriteLine("Network error."); break;

View file

@ -64,9 +64,9 @@ namespace MinecraftClient
public static int AutoRelog_Retries = 3;
public static string AutoRelog_KickMessagesFile = "kickmessages.txt";
//Scripting Settings
public static bool Scripting_Enabled = false;
public static string Scripting_ScriptFile = "script.txt";
//Startup Script Settings
public static bool StartupScript_Enabled = false;
public static string StartupScript_ScriptFile = "script.txt";
//Remote Control
public static bool RemoteCtrl_Enabled = false;
@ -101,7 +101,7 @@ namespace MinecraftClient
case "chatlog": pMode = ParseMode.ChatLog; break;
case "hangman": pMode = ParseMode.Hangman; break;
case "main": pMode = ParseMode.Main; break;
case "scripting": pMode = ParseMode.Scripting; break;
case "startupscript": pMode = ParseMode.Scripting; break;
case "remotecontrol": pMode = ParseMode.RemoteControl; break;
default: pMode = ParseMode.Default; break;
}
@ -183,8 +183,8 @@ namespace MinecraftClient
case ParseMode.Scripting:
switch (argName.ToLower())
{
case "enabled": Scripting_Enabled = str2bool(argValue); break;
case "scriptfile": Scripting_ScriptFile = argValue; break;
case "enabled": StartupScript_Enabled = str2bool(argValue); break;
case "scriptfile": StartupScript_ScriptFile = argValue; break;
}
break;
@ -259,7 +259,7 @@ namespace MinecraftClient
+ "wordsfile=hangman-en.txt\r\n"
+ "fichiermots=hangman-fr.txt\r\n"
+ "\r\n"
+ "[Scripting]\r\n"
+ "[StartupScript]\r\n"
+ "enabled=false\r\n"
+ "scriptfile=testscript.txt\r\n"
+ "\r\n"