diff --git a/MinecraftClient/Commands/Connect.cs b/MinecraftClient/Commands/Connect.cs index 3449177c..3d57dbd3 100644 --- a/MinecraftClient/Commands/Connect.cs +++ b/MinecraftClient/Commands/Connect.cs @@ -8,7 +8,7 @@ namespace MinecraftClient.Commands public class Connect : Command { public override string CMDName { get { return "connect"; } } - public override string CMDDesc { get { return "connect [account]: connect to the specified server."; } } + public override string CMDDesc { get { return "connect [account]: connect to the specified server."; } } public override string Run(McTcpClient handler, string command) { diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 4f3f20db..ebe64f76 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -87,6 +87,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 enum ParseMode { Default, Main, AppVars, Proxy, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl }; @@ -145,11 +146,13 @@ namespace MinecraftClient case "timestamps": chatTimeStamps = str2bool(argValue); break; case "exitonfailure": exitOnFailure = str2bool(argValue); break; case "mcversion": ServerVersion = argValue; break; + case "botowners": Bots_Owners.Clear(); foreach (string name in argValue.ToLower().Replace(" ", "").Split(',')) Bots_Owners.Add(name); break; + case "internalcmdchar": switch (argValue.ToLower()) { @@ -158,7 +161,8 @@ namespace MinecraftClient case "backslash": internalCmdChar = '\\'; break; } break; - case "accountsfile": + + case "accountlist": if (File.Exists(argValue)) { foreach (string account_line in File.ReadAllLines(argValue)) @@ -171,6 +175,31 @@ namespace MinecraftClient } } break; + + case "serverlist": + if (File.Exists(argValue)) + { + //Backup current server info + string server_host_temp = ServerIP; + short server_port_temp = ServerPort; + + foreach (string server_line in File.ReadAllLines(argValue)) + { + //Each line contains server data: 'Alias,Host:Port' + string[] server_data = server_line.Split('#')[0].Trim().Split(','); + if (server_data.Length == 2 + && server_data[0] != "localhost" + && !server_data[0].Contains('.') + && setServerIP(server_data[1])) + Servers[server_data[0].ToLower()] + = new KeyValuePair(ServerIP, ServerPort); + } + + //Restore current server info + ServerIP = server_host_temp; + ServerPort = server_port_temp; + } + break; } break; @@ -296,7 +325,8 @@ namespace MinecraftClient + "consoletitle=%username% - Minecraft Console Client\r\n" + "internalcmdchar=slash #use 'none', 'slash' or 'backslash'\r\n" + "mcversion=auto #use 'auto' or '1.X.X' values\r\n" - + "accountsfile=accounts.txt\r\n" + + "accountlist=accounts.txt\r\n" + + "serverlist=servers.txt\r\n" + "exitonfailure=false\r\n" + "timestamps=false\r\n" + "\r\n" @@ -373,13 +403,13 @@ namespace MinecraftClient } /// - /// Parse a "serverip:port" couple and store the values in ServerIP and ServerPort variables + /// Load server information in ServerIP and ServerPort variables from a "serverip:port" couple or server alias /// /// True if the server IP was valid and loaded, false otherwise - public static bool setServerIP(string serverIP) + public static bool setServerIP(string server) { - string[] sip = serverIP.Split(':'); + string[] sip = server.Split(':'); string host = sip[0]; short port = 25565; @@ -398,6 +428,11 @@ namespace MinecraftClient ServerPort = port; return true; } + else if (Servers.ContainsKey(server)) + { + ServerIP = Servers[server].Key; + ServerPort = Servers[server].Value; + } return false; } diff --git a/MinecraftClient/config/sample-servers.txt b/MinecraftClient/config/sample-servers.txt new file mode 100644 index 00000000..2657da3b --- /dev/null +++ b/MinecraftClient/config/sample-servers.txt @@ -0,0 +1,18 @@ +# Minecraft Console Client +# Server list file + +# Put server data as comma separated values +# Values are: Alias,ServerIP:Port +# Aliases cannot contains dots or spaces +# The name "localhost" cannot be used as an alias +# It allows an easier and faster server switching +# with short aliases instead of full server IP +# It also adds a bit of privacy for remote control + +# Usage examples: +# /tell connect Server1 +# /connect Server2 + +Server1,localhost +Server2,mc.awesomeserver.com:25567 +Server3,192.168.1.27:1348 # Example of LAN server \ No newline at end of file