Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Mar 9, 2024
1 parent dcdc637 commit 70584af
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
4 changes: 0 additions & 4 deletions v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ internal class Global
public const string BlockTag = "block";
public const string StreamSecurity = "tls";
public const string StreamSecurityReality = "reality";
public const string InboundSocks = "socks";
public const string InboundHttp = "http";
public const string InboundSocks2 = "socks2";
public const string InboundHttp2 = "http2";
public const string Loopback = "127.0.0.1";
public const string InboundAPITagName = "api";
public const string InboundAPIProtocol = "dokodemo-door";
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static int LoadConfig(ref Config? config)
config.inbound = new List<InItem>();
InItem inItem = new()
{
protocol = Global.InboundSocks,
protocol = EInboundProtocol.socks.ToString(),
localPort = 10808,
udpEnabled = true,
sniffingEnabled = true,
Expand All @@ -75,7 +75,7 @@ public static int LoadConfig(ref Config? config)
{
if (config.inbound.Count > 0)
{
config.inbound[0].protocol = Global.InboundSocks;
config.inbound[0].protocol = EInboundProtocol.socks.ToString();
}
}
if (config.routingBasicItem == null)
Expand Down
22 changes: 11 additions & 11 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ private int GenInbounds(SingboxConfig singboxConfig)
{
var inbound = new Inbound4Sbox()
{
type = Global.InboundSocks,
tag = Global.InboundSocks,
type = EInboundProtocol.socks.ToString(),
tag = EInboundProtocol.socks.ToString(),
listen = Global.Loopback,
};
singboxConfig.inbounds.Add(inbound);
Expand All @@ -136,18 +136,18 @@ private int GenInbounds(SingboxConfig singboxConfig)
}

//http
var inbound2 = GetInbound(inbound, Global.InboundHttp, 1, false);
var inbound2 = GetInbound(inbound, EInboundProtocol.http, false);
singboxConfig.inbounds.Add(inbound2);

if (_config.inbound[0].allowLANConn)
{
if (_config.inbound[0].newPort4LAN)
{
var inbound3 = GetInbound(inbound, Global.InboundSocks2, 2, true);
var inbound3 = GetInbound(inbound, EInboundProtocol.socks2, true);
inbound3.listen = "::";
singboxConfig.inbounds.Add(inbound3);

var inbound4 = GetInbound(inbound, Global.InboundHttp2, 3, false);
var inbound4 = GetInbound(inbound, EInboundProtocol.http2, false);
inbound4.listen = "::";
singboxConfig.inbounds.Add(inbound4);

Expand Down Expand Up @@ -198,12 +198,12 @@ private int GenInbounds(SingboxConfig singboxConfig)
return 0;
}

private Inbound4Sbox GetInbound(Inbound4Sbox inItem, string tag, int offset, bool bSocks)
private Inbound4Sbox GetInbound(Inbound4Sbox inItem, EInboundProtocol protocol, bool bSocks)
{
var inbound = JsonUtile.DeepCopy(inItem);
inbound.tag = tag;
inbound.listen_port = inItem.listen_port + offset;
inbound.type = bSocks ? Global.InboundSocks : Global.InboundHttp;
inbound.tag = protocol.ToString();
inbound.listen_port = inItem.listen_port + (int)protocol;
inbound.type = bSocks ? EInboundProtocol.socks.ToString() : EInboundProtocol.http.ToString();
return inbound;
}

Expand Down Expand Up @@ -933,9 +933,9 @@ public int GenerateClientSpeedtestConfig(List<ServerTestItem> selecteds, out Sin
{
listen = Global.Loopback,
listen_port = port,
type = Global.InboundHttp
type = EInboundProtocol.http.ToString(),
};
inbound.tag = Global.InboundHttp + inbound.listen_port.ToString();
inbound.tag = inbound.type + inbound.listen_port.ToString();
singboxConfig.inbounds.Add(inbound);

//outbound
Expand Down
20 changes: 10 additions & 10 deletions v2rayN/v2rayN/Handler/CoreConfigV2ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ private int GenInbounds(V2rayConfig v2rayConfig)
{
v2rayConfig.inbounds = new List<Inbounds4Ray>();

Inbounds4Ray? inbound = GetInbound(_config.inbound[0], Global.InboundSocks, 0, true);
Inbounds4Ray? inbound = GetInbound(_config.inbound[0], EInboundProtocol.socks, true);
v2rayConfig.inbounds.Add(inbound);

//http
Inbounds4Ray? inbound2 = GetInbound(_config.inbound[0], Global.InboundHttp, 1, false);
Inbounds4Ray? inbound2 = GetInbound(_config.inbound[0], EInboundProtocol.http, false);
v2rayConfig.inbounds.Add(inbound2);

if (_config.inbound[0].allowLANConn)
{
if (_config.inbound[0].newPort4LAN)
{
var inbound3 = GetInbound(_config.inbound[0], Global.InboundSocks2, 2, true);
var inbound3 = GetInbound(_config.inbound[0], EInboundProtocol.socks2, true);
inbound3.listen = "0.0.0.0";
v2rayConfig.inbounds.Add(inbound3);

var inbound4 = GetInbound(_config.inbound[0], Global.InboundHttp2, 3, false);
var inbound4 = GetInbound(_config.inbound[0], EInboundProtocol.http2, false);
inbound4.listen = "0.0.0.0";
v2rayConfig.inbounds.Add(inbound4);

Expand Down Expand Up @@ -143,7 +143,7 @@ private int GenInbounds(V2rayConfig v2rayConfig)
return 0;
}

private Inbounds4Ray? GetInbound(InItem inItem, string tag, int offset, bool bSocks)
private Inbounds4Ray? GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks)
{
string result = Utile.GetEmbedText(Global.V2raySampleInbound);
if (Utile.IsNullOrEmpty(result))
Expand All @@ -156,9 +156,9 @@ private int GenInbounds(V2rayConfig v2rayConfig)
{
return null;
}
inbound.tag = tag;
inbound.port = inItem.localPort + offset;
inbound.protocol = bSocks ? Global.InboundSocks : Global.InboundHttp;
inbound.tag = protocol.ToString();
inbound.port = inItem.localPort + (int)protocol;
inbound.protocol = bSocks ? EInboundProtocol.socks.ToString() : EInboundProtocol.http.ToString();
inbound.settings.udp = inItem.udpEnabled;
inbound.sniffing.enabled = inItem.sniffingEnabled;
inbound.sniffing.routeOnly = inItem.routeOnly;
Expand Down Expand Up @@ -975,9 +975,9 @@ public int GenerateClientSpeedtestConfig(List<ServerTestItem> selecteds, out V2r
{
listen = Global.Loopback,
port = port,
protocol = Global.InboundHttp
protocol = EInboundProtocol.http.ToString(),
};
inbound.tag = Global.InboundHttp + inbound.port.ToString();
inbound.tag = inbound.protocol + inbound.port.ToString();
v2rayConfig.inbounds.Add(inbound);

//outbound
Expand Down
8 changes: 4 additions & 4 deletions v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,15 +1811,15 @@ private void BindingUI()
public void InboundDisplayStaus()
{
StringBuilder sb = new();
sb.Append($"[{Global.InboundSocks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]");
sb.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]");
sb.Append(" | ");
//if (_config.sysProxyType == ESysProxyType.ForcedChange)
//{
// sb.Append($"[{Global.InboundHttp}({ResUI.SystemProxy}):{LazyConfig.Instance.GetLocalPort(Global.InboundHttp)}]");
//}
//else
//{
sb.Append($"[{Global.InboundHttp}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http)}]");
sb.Append($"[{EInboundProtocol.http}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http)}]");
//}
InboundDisplay = $"{ResUI.LabLocal}:{sb}";

Expand All @@ -1828,9 +1828,9 @@ public void InboundDisplayStaus()
if (_config.inbound[0].newPort4LAN)
{
StringBuilder sb2 = new();
sb2.Append($"[{Global.InboundSocks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks2)}]");
sb2.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks2)}]");
sb2.Append(" | ");
sb2.Append($"[{Global.InboundHttp}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http2)}]");
sb2.Append($"[{EInboundProtocol.http}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.http2)}]");
InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}";
}
else
Expand Down

0 comments on commit 70584af

Please sign in to comment.