mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Refactoring Settings.cs
This commit is contained in:
parent
f16b1c118b
commit
16c1d1fd77
59 changed files with 3425 additions and 2180 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System.Net.Sockets;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using Starksoft.Aspen.Proxy;
|
||||
using Tomlet.Attributes;
|
||||
|
||||
namespace MinecraftClient.Proxy
|
||||
{
|
||||
|
|
@ -11,7 +13,45 @@ namespace MinecraftClient.Proxy
|
|||
|
||||
public static class ProxyHandler
|
||||
{
|
||||
public enum Type { HTTP, SOCKS4, SOCKS4a, SOCKS5 };
|
||||
public static Configs Config = new();
|
||||
|
||||
[TomlDoNotInlineObject]
|
||||
public class Configs
|
||||
{
|
||||
[TomlInlineComment("$Config.Proxy.Enabled_Login$")]
|
||||
public bool Enabled_Login = false;
|
||||
|
||||
[TomlInlineComment("$Config.Proxy.Enabled_Ingame$")]
|
||||
public bool Enabled_Ingame = false;
|
||||
|
||||
[TomlInlineComment("$Config.Proxy.Server$")]
|
||||
public ProxyInfoConfig Server = new("0.0.0.0", 8080);
|
||||
|
||||
[TomlInlineComment("$Config.Proxy.Proxy_Type$")]
|
||||
public ProxyType Proxy_Type = ProxyType.HTTP;
|
||||
|
||||
[TomlInlineComment("$Config.Proxy.Username$")]
|
||||
public string Username = "";
|
||||
|
||||
[TomlInlineComment("$Config.Proxy.Password$")]
|
||||
public string Password = "";
|
||||
|
||||
public void OnSettingUpdate() { }
|
||||
|
||||
public struct ProxyInfoConfig
|
||||
{
|
||||
public string Host;
|
||||
public ushort Port;
|
||||
|
||||
public ProxyInfoConfig(string host, ushort port)
|
||||
{
|
||||
Host = host;
|
||||
Port = port;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProxyType { HTTP, SOCKS4, SOCKS4a, SOCKS5 };
|
||||
}
|
||||
|
||||
private static readonly ProxyClientFactory factory = new();
|
||||
private static IProxyClient? proxy;
|
||||
|
|
@ -28,27 +68,26 @@ namespace MinecraftClient.Proxy
|
|||
{
|
||||
try
|
||||
{
|
||||
if (login ? Settings.ProxyEnabledLogin : Settings.ProxyEnabledIngame)
|
||||
if (login ? Config.Enabled_Login : Config.Enabled_Ingame)
|
||||
{
|
||||
ProxyType innerProxytype = ProxyType.Http;
|
||||
|
||||
switch (Settings.proxyType)
|
||||
switch (Config.Proxy_Type)
|
||||
{
|
||||
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;
|
||||
case Configs.ProxyType.HTTP: innerProxytype = ProxyType.Http; break;
|
||||
case Configs.ProxyType.SOCKS4: innerProxytype = ProxyType.Socks4; break;
|
||||
case Configs.ProxyType.SOCKS4a: innerProxytype = ProxyType.Socks4a; break;
|
||||
case Configs.ProxyType.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 (Config.Username != "" && Config.Password != "")
|
||||
proxy = factory.CreateProxyClient(innerProxytype, Config.Server.Host, Config.Server.Port, Config.Username, Config.Password);
|
||||
else
|
||||
proxy = factory.CreateProxyClient(innerProxytype, Config.Server.Host, Config.Server.Port);
|
||||
|
||||
if (!proxy_ok)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("proxy.connected", Settings.ProxyHost, Settings.ProxyPort));
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("proxy.connected", Config.Server.Host, Config.Server.Port));
|
||||
proxy_ok = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue