From b90466447f7efa7f8805e600ef138545fb36e979 Mon Sep 17 00:00:00 2001 From: Lauchlin Date: Wed, 5 Nov 2014 01:59:32 +1100 Subject: [PATCH 1/4] Use usigned short to cover full range of ports Each side of a TCP connection has an associated 16-bit unsigned port number (0-65535). Use an unsigned short rather than a signed short otherwise you'll only get half the ports! --- MinecraftClient/Settings.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 6ccbe85e..03f14f9c 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -20,7 +20,7 @@ namespace MinecraftClient public static string Username = ""; public static string Password = ""; public static string ServerIP = ""; - public static short ServerPort = 25565; + public static unsigned short ServerPort = 25565; public static string ServerVersion = ""; public static string SingleCommand = ""; public static string ConsoleTitle = ""; @@ -90,7 +90,7 @@ namespace MinecraftClient //Custom app variables and Minecraft accounts private static Dictionary AppVars = new Dictionary(); private static Dictionary> Accounts = new Dictionary>(); - private static Dictionary> Servers = new Dictionary>(); + private static Dictionary> Servers = new Dictionary>(); private enum ParseMode { Default, Main, AppVars, Proxy, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl }; @@ -186,7 +186,7 @@ namespace MinecraftClient { //Backup current server info string server_host_temp = ServerIP; - short server_port_temp = ServerPort; + unsigned short server_port_temp = ServerPort; foreach (string server_line in File.ReadAllLines(argValue)) { @@ -198,7 +198,7 @@ namespace MinecraftClient && !server_data[0].Contains('.') && setServerIP(server_data[1])) Servers[server_data[0]] - = new KeyValuePair(ServerIP, ServerPort); + = new KeyValuePair(ServerIP, ServerPort); } //Restore current server info @@ -432,13 +432,13 @@ namespace MinecraftClient server = server.ToLower(); string[] sip = server.Split(':'); string host = sip[0]; - short port = 25565; + unsigned short port = 25565; if (sip.Length > 1) { try { - port = Convert.ToInt16(sip[1]); + port = Convert.ToUInt16(sip[1]); } catch (FormatException) { return false; } } From 466ad07b71271c3091b6d91043ec95f1bb99f827 Mon Sep 17 00:00:00 2001 From: Lauchlin Date: Wed, 5 Nov 2014 02:04:33 +1100 Subject: [PATCH 2/4] Using ushort rather than keyword I'm not so familiar with this syntax. --- MinecraftClient/Settings.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 03f14f9c..5b22bc90 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -20,7 +20,7 @@ namespace MinecraftClient public static string Username = ""; public static string Password = ""; public static string ServerIP = ""; - public static unsigned short ServerPort = 25565; + public static ushort ServerPort = 25565; public static string ServerVersion = ""; public static string SingleCommand = ""; public static string ConsoleTitle = ""; @@ -90,7 +90,7 @@ namespace MinecraftClient //Custom app variables and Minecraft accounts private static Dictionary AppVars = new Dictionary(); private static Dictionary> Accounts = new Dictionary>(); - private static Dictionary> Servers = new Dictionary>(); + private static Dictionary> Servers = new Dictionary>(); private enum ParseMode { Default, Main, AppVars, Proxy, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl }; @@ -186,7 +186,7 @@ namespace MinecraftClient { //Backup current server info string server_host_temp = ServerIP; - unsigned short server_port_temp = ServerPort; + ushort server_port_temp = ServerPort; foreach (string server_line in File.ReadAllLines(argValue)) { @@ -198,7 +198,7 @@ namespace MinecraftClient && !server_data[0].Contains('.') && setServerIP(server_data[1])) Servers[server_data[0]] - = new KeyValuePair(ServerIP, ServerPort); + = new KeyValuePair(ServerIP, ServerPort); } //Restore current server info @@ -432,7 +432,7 @@ namespace MinecraftClient server = server.ToLower(); string[] sip = server.Split(':'); string host = sip[0]; - unsigned short port = 25565; + ushort port = 25565; if (sip.Length > 1) { From 284d335b2a4bb8eea2f8946f8c1088edc7af0a18 Mon Sep 17 00:00:00 2001 From: Lauchlin Date: Wed, 5 Nov 2014 02:05:33 +1100 Subject: [PATCH 3/4] Update short to ushort --- MinecraftClient/McTcpClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index ceaedfb9..4e59d1b3 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -53,7 +53,7 @@ namespace MinecraftClient /// The server port to use /// Minecraft protocol version to use - public McTcpClient(string username, string uuid, string sessionID, int protocolversion, string server_ip, short port) + public McTcpClient(string username, string uuid, string sessionID, int protocolversion, string server_ip, ushort port) { StartClient(username, uuid, sessionID, server_ip, port, protocolversion, false, ""); } @@ -69,7 +69,7 @@ namespace MinecraftClient /// Minecraft protocol version to use /// The text or command to send. - public McTcpClient(string username, string uuid, string sessionID, string server_ip, short port, int protocolversion, string command) + public McTcpClient(string username, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, string command) { StartClient(username, uuid, sessionID, server_ip, port, protocolversion, true, command); } @@ -86,7 +86,7 @@ namespace MinecraftClient /// If set to true, the client will send a single command and then disconnect from the server /// The text or command to send. Will only be sent if singlecommand is set to true. - private void StartClient(string user, string uuid, string sessionID, string server_ip, short port, int protocolversion, bool singlecommand, string command) + private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, bool singlecommand, string command) { this.sessionid = sessionID; this.uuid = uuid; From 006a1a5f4b86aa96a734528ed32a06ccd8c888e9 Mon Sep 17 00:00:00 2001 From: Lauchlin Wilkinson Date: Thu, 6 Nov 2014 17:59:19 +1100 Subject: [PATCH 4/4] Missed ushort in protocol handler --- MinecraftClient/Protocol/ProtocolHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index ce3a704b..bc8aaf8b 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -23,7 +23,7 @@ namespace MinecraftClient.Protocol /// Will contain protocol version, if ping successful /// TRUE if ping was successful - public static bool GetServerInfo(string serverIP, short serverPort, ref int protocolversion) + public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion) { try {