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)
This commit is contained in:
ORelio 2015-10-22 20:56:08 +02:00
parent e8a8ca4e7a
commit 29975da627
4 changed files with 15 additions and 17 deletions

View file

@ -110,15 +110,8 @@ namespace MinecraftClient
}
try
{
if (Settings.OnlyForLogin)
{
client = new TcpClient(host, port);
}
else
{
client = ProxyHandler.newTcpClient(host, port);
}
client.ReceiveBufferSize = 1024 * 1024;
handler = Protocol.ProtocolHandler.getProtocolHandler(client, protocolversion, this);
Console.WriteLine("Version is supported.\nLogging in...");

View file

@ -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);

View file

@ -24,12 +24,15 @@ namespace MinecraftClient.Proxy
/// <summary>
/// Create a regular TcpClient or a proxied TcpClient according to the app Settings.
/// </summary>
/// <param name="host">Target host</param>
/// <param name="port">Target port</param>
/// <param name="login">True if the purpose is logging in to a Minecraft account</param>
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;

View file

@ -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"