Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MinecraftClient/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/bin/
/obj/
MinecraftClient.sln
MinecraftClient.v11.suo
34 changes: 22 additions & 12 deletions MinecraftClient/ChatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ private static string color2tag(string colorname)
case "black": return "§0";
case "dark_blue": return "§1";
case "dark_green": return "§2";
case "dark_cyan": return "§3";
case "dark_cyanred": return "§4";
case "dark_magenta": return "§5";
case "dark_yellow": return "§6";
case "dark_aqua": return "§3";
case "dark_red": return "§4";
case "dark_purple": return "§5";
case "gold": return "§6";
case "gray": return "§7";
case "dark_gray": return "§8";
case "blue": return "§9";
case "green": return "§a";
case "cyan": return "§b";
case "aqua": return "§b";
case "red": return "§c";
case "magenta": return "§d";
case "light_purple": return "§d";
case "yellow": return "§e";
case "white": return "§f";
default: return "";
Expand All @@ -95,10 +95,13 @@ private static void InitRules()
TranslationRules["commands.message.display.incoming"] = "§7%s whispers to you: %s";
TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s";

//Use translations from Minecraft assets if a copy of the game is installed?
if (!System.IO.File.Exists(Settings.TranslationsFile)
//Use translations from Minecraft assets if translation file is not found but a copy of the game is installed?
if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_US.lang
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir))
{ Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir; }
if (!System.IO.File.Exists(Settings.TranslationsFile) //Still not found? try en_GB.lang
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir_Alt))
{ Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir_Alt; }

//Load an external dictionnary of translation rules
if (System.IO.File.Exists(Settings.TranslationsFile))
Expand All @@ -123,7 +126,7 @@ private static void InitRules()
else //No external dictionnary found.
{
Console.ForegroundColor = ConsoleColor.DarkGray;
ConsoleIO.WriteLine("MC 1.6+ warning: Translations file not found: \"" + Settings.TranslationsFile + "\""
ConsoleIO.WriteLine("Translations file not found: \"" + Settings.TranslationsFile + "\""
+ "\nYou can pick a translation file from .minecraft\\assets\\lang\\"
+ "\nSome messages won't be properly printed without this file.");
Console.ForegroundColor = ConsoleColor.Gray;
Expand Down Expand Up @@ -282,17 +285,24 @@ private static JSONData String2Data(string toparse, ref int cursorpos)

private static string JSONData2String(JSONData data)
{
string extra_result = "";
string colorcode = "";
switch (data.Type)
{
case JSONData.DataType.Object:
if (data.Properties.ContainsKey("extra"))
{
JSONData[] extras = data.Properties["extra"].DataArray.ToArray();
foreach (JSONData item in extras)
extra_result = extra_result + JSONData2String(item) + "§r";
}
if (data.Properties.ContainsKey("color"))
{
colorcode = color2tag(JSONData2String(data.Properties["color"]));
}
if (data.Properties.ContainsKey("text"))
{
return colorcode + JSONData2String(data.Properties["text"]) + colorcode;
return extra_result + colorcode + JSONData2String(data.Properties["text"]) + colorcode;
}
else if (data.Properties.ContainsKey("translate"))
{
Expand All @@ -305,9 +315,9 @@ private static string JSONData2String(JSONData data)
using_data.Add(JSONData2String(array[i]));
}
}
return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode;
return extra_result + colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode;
}
else return "";
else return extra_result;

case JSONData.DataType.Array:
string result = "";
Expand Down
82 changes: 38 additions & 44 deletions MinecraftClient/McTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class McTcpClient
/// <param name="sessionID">A valid sessionID obtained with MinecraftCom.GetLogin()</param>
/// <param name="server_port">The server IP (serveradress or serveradress:port)</param>

public McTcpClient(string username, string sessionID, string server_port, MinecraftCom handler)
public McTcpClient(string username, string uuid, string sessionID, string server_port, MinecraftCom handler)
{
StartClient(username, sessionID, server_port, false, handler, "");
StartClient(username, uuid, sessionID, server_port, false, handler, "");
}

/// <summary>
Expand All @@ -47,9 +47,9 @@ public McTcpClient(string username, string sessionID, string server_port, Minecr
/// <param name="server_port">The server IP (serveradress or serveradress:port)</param>
/// <param name="command">The text or command to send.</param>

public McTcpClient(string username, string sessionID, string server_port, MinecraftCom handler, string command)
public McTcpClient(string username, string uuid, string sessionID, string server_port, MinecraftCom handler, string command)
{
StartClient(username, sessionID, server_port, true, handler, command);
StartClient(username, uuid, sessionID, server_port, true, handler, command);
}

/// <summary>
Expand All @@ -61,7 +61,7 @@ public McTcpClient(string username, string sessionID, string server_port, Minecr
/// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param>
/// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param>

private void StartClient(string user, string sessionID, string server_port, bool singlecommand, MinecraftCom handler, string command)
private void StartClient(string user, string uuid, string sessionID, string server_port, bool singlecommand, MinecraftCom handler, string command)
{
this.handler = handler;
username = user;
Expand All @@ -82,54 +82,43 @@ private void StartClient(string user, string sessionID, string server_port, bool

try
{
Console.WriteLine("Connecting...");
Console.WriteLine("Logging in...");
client = new TcpClient(host, port);
client.ReceiveBufferSize = 1024 * 1024;
handler.setClient(client);
byte[] token = new byte[1]; string serverID = "";
if (handler.Handshake(user, sessionID, ref serverID, ref token, host, port))
if (handler.Login(user, uuid, sessionID, host, port))
{
Console.WriteLine("Logging in...");

if (handler.FinalizeLogin())
//Single command sending
if (singlecommand)
{
//Single command sending
if (singlecommand)
{
handler.SendChatMessage(command);
Console.Write("Command ");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(command);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" sent.");
Thread.Sleep(5000);
handler.Disconnect("disconnect.quitting");
Thread.Sleep(1000);
}
else
{
Console.WriteLine("Server was successfuly joined.\nType '/quit' to leave the server.");

//Command sending thread, allowing user input
t_sender = new Thread(new ThreadStart(StartTalk));
t_sender.Name = "CommandSender";
t_sender.Start();

//Data receiving thread, allowing text receiving
t_updater = new Thread(new ThreadStart(Updater));
t_updater.Name = "PacketHandler";
t_updater.Start();
}
handler.SendChatMessage(command);
Console.Write("Command ");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(command);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" sent.");
Thread.Sleep(5000);
handler.Disconnect("disconnect.quitting");
Thread.Sleep(1000);
}
else
{
Console.WriteLine("Login failed.");
if (!singlecommand) { Program.ReadLineReconnect(); }
Console.WriteLine("Server was successfuly joined.\nType '/quit' to leave the server.");

//Command sending thread, allowing user input
t_sender = new Thread(new ThreadStart(StartTalk));
t_sender.Name = "CommandSender";
t_sender.Start();

//Data receiving thread, allowing text receiving
t_updater = new Thread(new ThreadStart(Updater));
t_updater.Name = "PacketHandler";
t_updater.Start();
}
}
else
{
Console.WriteLine("Invalid session ID.");
Console.WriteLine("Login failed.");
if (!singlecommand) { Program.ReadLineReconnect(); }
}
}
Expand Down Expand Up @@ -171,7 +160,7 @@ private void StartTalk()
}
else
{
if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; }
if (text.ToLower() == "/quit" || text.ToLower().StartsWith("/exec ") || text.ToLower() == "/reco" || text.ToLower() == "/reconnect") { break; }
while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); }
if (text != "")
{
Expand Down Expand Up @@ -200,13 +189,18 @@ private void StartTalk()
}
}

if (text == "/quit")
if (text.ToLower() == "/quit")
{
ConsoleIO.WriteLine("You have left the server.");
Disconnect();
}

else if (text == "/reco" || text == "/reconnect")
else if (text.ToLower().StartsWith("/exec ")) {
handler.BotLoad(new Bots.Scripting("config/" + text.Split()[1]));
}


else if (text.ToLower() == "/reco" || text.ToLower() == "/reconnect")
{
ConsoleIO.WriteLine("You have left the server.");
handler.SendRespawnPacket();
Expand Down
4 changes: 0 additions & 4 deletions MinecraftClient/MinecraftClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.7.4114.6375, Culture=neutral, PublicKeyToken=0e99375e54769942">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="IKVM.OpenJDK.Core, Version=7.0.4335.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\IKVM.OpenJDK.Core.dll</HintPath>
Expand Down
Loading