From 29975da627f7c33ab2707141c20a53f67f644c31 Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 22 Oct 2015 20:56:08 +0200 Subject: [PATCH] Merge onlyforlogin and enabled in proxy settings The 'enabled' setting can now be set to 'login' for enabling proxy only for logging in to the Minecraft account, and then connect to the server directly without proxy. Useful when Minecraft login is blocked on some network, but not Minecraft servers (port 25565) (original idea and enhancement by ZizzyDizzyMC) --- MinecraftClient/McTcpClient.cs | 9 +-------- MinecraftClient/Protocol/ProtocolHandler.cs | 2 +- MinecraftClient/Proxy/ProxyHandler.cs | 7 +++++-- MinecraftClient/Settings.cs | 14 ++++++++------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index cdcf3f6d..fed884a1 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -111,14 +111,7 @@ namespace MinecraftClient try { - if (Settings.OnlyForLogin) - { - client = new TcpClient(host, port); - } - else - { - client = ProxyHandler.newTcpClient(host, port); - } + client = ProxyHandler.newTcpClient(host, port); client.ReceiveBufferSize = 1024 * 1024; handler = Protocol.ProtocolHandler.getProtocolHandler(client, protocolversion, this); Console.WriteLine("Version is supported.\nLogging in..."); diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index 624d6a7f..dcd507d7 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -244,7 +244,7 @@ namespace MinecraftClient.Protocol int statusCode = 520; AutoTimeout.Perform(() => { - TcpClient client = ProxyHandler.newTcpClient(host, 443); + TcpClient client = ProxyHandler.newTcpClient(host, 443, true); SslStream stream = new SslStream(client.GetStream()); stream.AuthenticateAsClient(host); diff --git a/MinecraftClient/Proxy/ProxyHandler.cs b/MinecraftClient/Proxy/ProxyHandler.cs index d18d4ea1..a017e323 100644 --- a/MinecraftClient/Proxy/ProxyHandler.cs +++ b/MinecraftClient/Proxy/ProxyHandler.cs @@ -24,12 +24,15 @@ namespace MinecraftClient.Proxy /// /// Create a regular TcpClient or a proxied TcpClient according to the app Settings. /// + /// Target host + /// Target port + /// True if the purpose is logging in to a Minecraft account - public static TcpClient newTcpClient(string host, int port) + public static TcpClient newTcpClient(string host, int port, bool login = false) { try { - if (Settings.ProxyEnabled) + if (login ? Settings.ProxyEnabledLogin : Settings.ProxyEnabledIngame) { ProxyType innerProxytype = ProxyType.Http; diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index d4290520..407d730f 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -29,13 +29,13 @@ namespace MinecraftClient public static string ConsoleTitle = ""; //Proxy Settings - public static bool ProxyEnabled = false; + public static bool ProxyEnabledLogin = false; + public static bool ProxyEnabledIngame = false; public static string ProxyHost = ""; public static int ProxyPort = 0; public static Proxy.ProxyHandler.Type proxyType = Proxy.ProxyHandler.Type.HTTP; public static string ProxyUsername = ""; public static string ProxyPassword = ""; - public static bool OnlyForLogin = false; //Other Settings public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang @@ -322,8 +322,11 @@ namespace MinecraftClient case ParseMode.Proxy: switch (argName.ToLower()) { - case "enabled": ProxyEnabled = str2bool(argValue); break; - case "onlyforlogin": OnlyForLogin = str2bool(argValue); break; + case "enabled": + ProxyEnabledLogin = ProxyEnabledIngame = str2bool(argValue); + if (argValue.Trim().ToLower() == "login") + ProxyEnabledLogin = true; + break; case "type": argValue = argValue.ToLower(); if (argValue == "http") { proxyType = Proxy.ProxyHandler.Type.HTTP; } @@ -415,12 +418,11 @@ namespace MinecraftClient + "#%username% and %serverip% are reserved variables.\r\n" + "\r\n" + "[Proxy]\r\n" - + "enabled=false\r\n" + + "enabled=false #use 'false', 'true', or 'login' for login only\r\n" + "type=HTTP #Supported types: HTTP, SOCKS4, SOCKS4a, SOCKS5\r\n" + "server=0.0.0.0:0000\r\n" + "username=\r\n" + "password=\r\n" - + "onlyforlogin=false # Change this to \"true\" if you only want to use a proxy for login." + "\r\n" + "#Bot Settings\r\n" + "\r\n"