mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
App refactoring almost done
- Created specific namespaces and folders for each app brick - Added proxy support using Starksoft's Biko Library - App bricks: Main, ChatBots, Crypto, Protocol, Proxy - Each class is now in its own file (Aes streams, chatbots) - Used "Bridge" design pattern for Crypto, Protocol, Proxy - Added back support for Minecraft 1.4.6 to 1.6.4 (MCC 1.6.2) - Need to fully re-test everything and fix bugs - To Fix : Server pinging is slow on SpigotMC - To Do : Add Minecraft 1.2.5 (MCC 1.3) and maybe 1.3 to 1.4.5
This commit is contained in:
parent
9be1d99ca0
commit
d2ec2f48b7
43 changed files with 6039 additions and 2178 deletions
68
MinecraftClient/Proxy/ProxyHandler.cs
Normal file
68
MinecraftClient/Proxy/ProxyHandler.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using Starksoft.Net.Proxy;
|
||||
|
||||
namespace MinecraftClient.Proxy
|
||||
{
|
||||
/// <summary>
|
||||
/// Automatically handle proxies according to the app Settings.
|
||||
/// Note: Underlying proxy handling is taken from Starksoft, LLC's Biko Library.
|
||||
/// This library is open source and provided under the MIT license. More info at biko.codeplex.com.
|
||||
/// </summary>
|
||||
|
||||
public static class ProxyHandler
|
||||
{
|
||||
public enum Type { HTTP, SOCKS4, SOCKS4a, SOCKS5 };
|
||||
|
||||
private static ProxyClientFactory factory = new ProxyClientFactory();
|
||||
private static IProxyClient proxy;
|
||||
private static bool proxy_ok = false;
|
||||
|
||||
/// <summary>
|
||||
/// Create a regular TcpClient or a proxied TcpClient according to the app Settings.
|
||||
/// </summary>
|
||||
|
||||
public static TcpClient newTcpClient(string host, int port)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Settings.ProxyEnabled)
|
||||
{
|
||||
ProxyType innerProxytype = ProxyType.Http;
|
||||
|
||||
switch (Settings.proxyType)
|
||||
{
|
||||
case Type.HTTP: innerProxytype = ProxyType.Http; break;
|
||||
case Type.SOCKS4: innerProxytype = ProxyType.Socks4; break;
|
||||
case Type.SOCKS4a: innerProxytype = ProxyType.Socks4a; break;
|
||||
case Type.SOCKS5: innerProxytype = ProxyType.Socks5; break;
|
||||
}
|
||||
|
||||
if (Settings.ProxyUsername != "" && Settings.ProxyPassword != "")
|
||||
{
|
||||
proxy = factory.CreateProxyClient(innerProxytype, Settings.ProxyHost, Settings.ProxyPort, Settings.ProxyUsername, Settings.ProxyPassword);
|
||||
}
|
||||
else proxy = factory.CreateProxyClient(innerProxytype, Settings.ProxyHost, Settings.ProxyPort);
|
||||
|
||||
if (!proxy_ok)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8Connected to proxy " + Settings.ProxyHost + ':' + Settings.ProxyPort, false);
|
||||
proxy_ok = true;
|
||||
}
|
||||
|
||||
return proxy.CreateConnection(host, port);
|
||||
}
|
||||
else return new TcpClient(host, port);
|
||||
}
|
||||
catch (ProxyException e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.Message, false);
|
||||
proxy = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue