Skip to content

Commit

Permalink
Merge pull request #39 from ORelio/Indev
Browse files Browse the repository at this point in the history
Merging changes from Indev for 1.7.3 release
  • Loading branch information
ORelio committed May 14, 2014
2 parents 60ee2a3 + 879c124 commit 1225a29
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 198 deletions.
339 changes: 272 additions & 67 deletions MinecraftClient/Bots.cs

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions MinecraftClient/ConsoleIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ public static string ReadPassword()
break;

default:
Console.Write('*');
password += k.KeyChar;
if (k.KeyChar != 0)
{
Console.Write('*');
password += k.KeyChar;
}
break;
}
}
Expand Down Expand Up @@ -159,7 +162,8 @@ public static string ReadLine()
}
break;
default:
AddChar(k.KeyChar);
if (k.KeyChar != 0)
AddChar(k.KeyChar);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions MinecraftClient/McTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void StartClient(string user, string uuid, string sessionID, string serv
else
{
Console.WriteLine("Login failed.");
if (!singlecommand) { Program.ReadLineReconnect(); }
if (!singlecommand && !handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, "Login failed.")) { Program.ReadLineReconnect(); }
}
}
catch (SocketException)
Expand Down Expand Up @@ -175,7 +175,7 @@ private void StartTalk()
}
else if (text.ToLower().StartsWith("/script "))
{
handler.BotLoad(new Bots.Scripting(text.Substring(8)));
handler.BotLoad(new Bots.Script(text.Substring(8)));
}
else if (text != "")
{
Expand Down Expand Up @@ -235,7 +235,7 @@ private void Updater()
if (!handler.HasBeenKicked)
{
ConsoleIO.WriteLine("Connection has been lost.");
if (!handler.OnConnectionLost() && !Program.ReadLineReconnect()) { t_sender.Abort(); }
if (!handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "Connection has been lost.") && !Program.ReadLineReconnect()) { t_sender.Abort(); }
}
else if (Program.ReadLineReconnect()) { t_sender.Abort(); }
}
Expand Down
28 changes: 24 additions & 4 deletions MinecraftClient/MinecraftCom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MinecraftCom : IAutoComplete
{
#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.
Expand Down Expand Up @@ -66,6 +66,10 @@ public static LoginResult GetLogin(ref string user, string pass, ref string acce
else return LoginResult.WrongPassword;
}
}
else if ((int)response.StatusCode == 503)
{
return LoginResult.ServiceUnavailable;
}
else return LoginResult.Blocked;
}
else if (e.Status == WebExceptionStatus.SendFailure)
Expand Down Expand Up @@ -110,6 +114,11 @@ public static bool SessionCheck(string uuid, string accesstoken, string serverha
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(); }
Expand Down Expand Up @@ -174,14 +183,14 @@ public void DebugDump()
System.IO.File.WriteAllText("debug.txt", dump);
System.Diagnostics.Process.Start("debug.txt");
}
public bool OnConnectionLost()
public bool OnConnectionLost(ChatBot.DisconnectReason reason, string reason_message)
{
if (!connectionlost)
{
connectionlost = true;
for (int i = 0; i < bots.Count; i++)
{
if (bots[i].OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Connection has been lost."))
if (bots[i].OnDisconnect(reason, reason_message))
{
return true; //The client is about to restart
}
Expand Down Expand Up @@ -302,6 +311,11 @@ private static void printstring(string str, bool acceptnewlines)
{
if (!String.IsNullOrEmpty(str))
{
if (Settings.chatTimeStamps)
{
int hour = DateTime.Now.Hour, minute = DateTime.Now.Minute, second = DateTime.Now.Second;
ConsoleIO.Write(hour.ToString("00") + ':' + minute.ToString("00") + ':' + second.ToString("00") + ' ');
}
if (!acceptnewlines) { str = str.Replace('\n', ' '); }
if (ConsoleIO.basicIO) { ConsoleIO.WriteLine(str); return; }
string[] subs = str.Split(new char[] { '§' });
Expand Down Expand Up @@ -450,7 +464,7 @@ public static bool GetServerInfo(string serverIP, ref int protocolversion, ref s
public bool Login(string username, string uuid, string sessionID, string host, int port)
{
byte[] packet_id = getVarInt(0);
byte[] protocol_version = getVarInt(4);
byte[] protocol_version = getVarInt(protocolversion);
byte[] server_adress_val = Encoding.UTF8.GetBytes(host);
byte[] server_adress_len = getVarInt(server_adress_val.Length);
byte[] server_port = BitConverter.GetBytes((ushort)port); Array.Reverse(server_port);
Expand Down Expand Up @@ -580,9 +594,15 @@ public void Disconnect(string message)
catch (SocketException) { }
catch (System.IO.IOException) { }
catch (NullReferenceException) { }
catch (ObjectDisposedException) { }

foreach (ChatBot bot in bots)
if (bot is Bots.Script)
scripts_on_hold.Add((Bots.Script)bot);
}

private List<ChatBot> bots = new List<ChatBot>();
private static List<Bots.Script> scripts_on_hold = new List<Bots.Script>();
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(); }
Expand Down
108 changes: 12 additions & 96 deletions MinecraftClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class Program
{
private static McTcpClient Client;
public static string[] startupargs;
public const string Version = "1.7.2";
public const string Version = "1.7.3";

/// <summary>
/// The main entry point of Minecraft Console Client
/// </summary>

static void Main(string[] args)
{
Console.WriteLine("Console Client for MC 1.7.2 to 1.7.5 - v" + Version + " - By ORelio & Contributors");
Console.WriteLine("Console Client for MC 1.7.2 to 1.7.9 - v" + Version + " - By ORelio & Contributors");

//Basic Input/Output ?
if (args.Length >= 1 && args[args.Length - 1] == "BasicIO")
Expand Down Expand Up @@ -65,91 +65,6 @@ static void Main(string[] args)
{
Settings.SingleCommand = args[3];
}

//Use bots? (will disable single command)
for (int i = 3; i < args.Length; i++)
{
if (args[i].Length > 4 && args[i].Substring(0, 4).ToLower() == "bot:")
{
Settings.SingleCommand = "";
string[] botargs = args[i].ToLower().Split(':');
switch (botargs[1])
{
#region Process bots settings
case "antiafk":
Settings.AntiAFK_Enabled = true;
if (botargs.Length > 2)
{
try { Settings.AntiAFK_Delay = Convert.ToInt32(botargs[2]); }
catch (FormatException) { }
} break;

case "pendu":
Settings.Hangman_Enabled = true;
Settings.Hangman_English = false;
break;

case "hangman":
Settings.Hangman_Enabled = true;
Settings.Hangman_English = true;
break;

case "alerts":
Settings.Alerts_Enabled = true;
break;

case "log":
Settings.ChatLog_Enabled = true;
Settings.ChatLog_DateTime = true;
Settings.ChatLog_File = "chat-" + Settings.ServerIP.Replace(':', '-') + ".log";
if (botargs.Length > 2)
{
Settings.ChatLog_DateTime = Settings.str2bool(botargs[2]);
if (botargs.Length > 3)
{
Settings.ChatLog_Filter = Bots.ChatLog.str2filter(botargs[3]);
if (botargs.Length > 4 && botargs[4] != "") { Settings.ChatLog_File = botargs[4]; }
}
} break;

case "logplayerlist":
Settings.PlayerLog_File = "connected-" + Settings.ServerIP.Replace(':', '-') + ".log";
if (botargs.Length > 2)
{
try { Settings.PlayerLog_Delay = Convert.ToInt32(botargs[2]); }
catch (FormatException) { }
} break;

case "autorelog":
if (botargs.Length > 2)
{
try { Settings.AutoRelog_Delay = Convert.ToInt32(botargs[2]); }
catch (FormatException) { }
if (botargs.Length > 3)
{
try { Settings.AutoRelog_Retries = Convert.ToInt32(botargs[3]); }
catch (FormatException) { }
}
} break;

case "xauth":
if (botargs.Length > 2)
{
Settings.xAuth_Enabled = true;
Settings.xAuth_Password = botargs[2];
} break;

case "scripting":
if (botargs.Length > 2)
{
Settings.Scripting_Enabled = true;
Settings.Scripting_ScriptFile = botargs[2];
} break;

#endregion
}
}
}
}
}
}
Expand Down Expand Up @@ -228,7 +143,7 @@ private static void InitializeClient()
if (MinecraftCom.GetServerInfo(Settings.ServerIP, ref protocolversion, ref version))
{
//Supported protocol version ?
int[] supportedVersions = { 4 };
int[] supportedVersions = { 4, 5 };
if (Array.IndexOf(supportedVersions, protocolversion) > -1)
{
//Load translations (Minecraft 1.6+)
Expand All @@ -241,14 +156,14 @@ private static void InitializeClient()
handler.setVersion(protocolversion);

//Load & initialize bots if needed
if (Settings.AntiAFK_Enabled) { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); }
if (Settings.Hangman_Enabled) { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); }
if (Settings.Alerts_Enabled) { handler.BotLoad(new Bots.Alerts()); }
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.xAuth_Enabled) { handler.BotLoad(new Bots.xAuth(Settings.xAuth_Password)); }
if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); }
if (Settings.AntiAFK_Enabled) { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); }
if (Settings.Hangman_Enabled) { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); }
if (Settings.Alerts_Enabled) { handler.BotLoad(new Bots.Alerts()); }
if (Settings.ChatLog_Enabled) { handler.BotLoad(new Bots.ChatLog(Settings.ChatLog_File.Replace("%username%", Settings.Username), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File.Replace("%username%", Settings.Username))); }
if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
if (Settings.ScriptScheduler_Enabled) { handler.BotLoad(new Bots.ScriptScheduler(Settings.ScriptScheduler_TasksFile.Replace("%username%", Settings.Username))); }
if (Settings.RemoteCtrl_Enabled) { handler.BotLoad(new Bots.RemoteControl()); }

//Start the main TCP client
if (Settings.SingleCommand != "")
Expand Down Expand Up @@ -277,6 +192,7 @@ private static void InitializeClient()
{
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;
Expand Down
Loading

0 comments on commit 1225a29

Please sign in to comment.