Skip to content

Commit 315d4b7

Browse files
committed
Optimize code
1 parent 31267cb commit 315d4b7

File tree

7 files changed

+20
-74
lines changed

7 files changed

+20
-74
lines changed

v2rayN/v2rayN/Handler/CoreConfigSingbox.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ private int GenInbounds(SingboxConfig singboxConfig)
111111
{
112112
try
113113
{
114-
singboxConfig.inbounds.Clear();
114+
var listen = "::";
115+
singboxConfig.inbounds = [];
115116

116117
if (!_config.tunModeItem.enableTun || (_config.tunModeItem.enableTun && _config.tunModeItem.enableExInbound))
117118
{
@@ -146,11 +147,11 @@ private int GenInbounds(SingboxConfig singboxConfig)
146147
if (_config.inbound[0].newPort4LAN)
147148
{
148149
var inbound3 = GetInbound(inbound, EInboundProtocol.socks2, true);
149-
inbound3.listen = "::";
150+
inbound3.listen = listen;
150151
singboxConfig.inbounds.Add(inbound3);
151152

152153
var inbound4 = GetInbound(inbound, EInboundProtocol.http2, false);
153-
inbound4.listen = "::";
154+
inbound4.listen = listen;
154155
singboxConfig.inbounds.Add(inbound4);
155156

156157
//auth
@@ -162,8 +163,8 @@ private int GenInbounds(SingboxConfig singboxConfig)
162163
}
163164
else
164165
{
165-
inbound.listen = "::";
166-
inbound2.listen = "::";
166+
inbound.listen = listen;
167+
inbound2.listen = listen;
167168
}
168169
}
169170
}

v2rayN/v2rayN/Handler/CoreConfigV2ray.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ private int GenInbounds(V2rayConfig v2rayConfig)
9898
{
9999
try
100100
{
101-
v2rayConfig.inbounds = new List<Inbounds4Ray>();
101+
var listen = "0.0.0.0";
102+
v2rayConfig.inbounds = [];
102103

103104
Inbounds4Ray? inbound = GetInbound(_config.inbound[0], EInboundProtocol.socks, true);
104105
v2rayConfig.inbounds.Add(inbound);
@@ -112,11 +113,11 @@ private int GenInbounds(V2rayConfig v2rayConfig)
112113
if (_config.inbound[0].newPort4LAN)
113114
{
114115
var inbound3 = GetInbound(_config.inbound[0], EInboundProtocol.socks2, true);
115-
inbound3.listen = "0.0.0.0";
116+
inbound3.listen = listen;
116117
v2rayConfig.inbounds.Add(inbound3);
117118

118119
var inbound4 = GetInbound(_config.inbound[0], EInboundProtocol.http2, false);
119-
inbound4.listen = "0.0.0.0";
120+
inbound4.listen = listen;
120121
v2rayConfig.inbounds.Add(inbound4);
121122

122123
//auth
@@ -131,8 +132,8 @@ private int GenInbounds(V2rayConfig v2rayConfig)
131132
}
132133
else
133134
{
134-
inbound.listen = "0.0.0.0";
135-
inbound2.listen = "0.0.0.0";
135+
inbound.listen = listen;
136+
inbound2.listen = listen;
136137
}
137138
}
138139
}
@@ -143,18 +144,18 @@ private int GenInbounds(V2rayConfig v2rayConfig)
143144
return 0;
144145
}
145146

146-
private Inbounds4Ray? GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks)
147+
private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks)
147148
{
148149
string result = Utils.GetEmbedText(Global.V2raySampleInbound);
149150
if (Utils.IsNullOrEmpty(result))
150151
{
151-
return null;
152+
return new();
152153
}
153154

154155
var inbound = JsonUtils.Deserialize<Inbounds4Ray>(result);
155156
if (inbound == null)
156157
{
157-
return null;
158+
return new();
158159
}
159160
inbound.tag = protocol.ToString();
160161
inbound.port = inItem.localPort + (int)protocol;

v2rayN/v2rayN/Sample/SampleClientConfig

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,7 @@
44
"error": "Verror.log",
55
"loglevel": "warning"
66
},
7-
"inbounds": [{
8-
"tag": "tag1",
9-
"port": 10808,
10-
"protocol": "socks",
11-
"listen": "127.0.0.1",
12-
"settings": {
13-
"auth": "noauth",
14-
"udp": true
15-
},
16-
"sniffing": {
17-
"enabled": true,
18-
"destOverride": [
19-
"http",
20-
"tls"
21-
]
22-
}
23-
},
24-
{
25-
"tag": "tag2",
26-
"port": 10809,
27-
"protocol": "http",
28-
"listen": "127.0.0.1",
29-
"settings": {
30-
"allowTransparent": false
31-
},
32-
"sniffing": {
33-
"enabled": true,
34-
"destOverride": [
35-
"http",
36-
"tls"
37-
]
38-
}
39-
},
40-
{
41-
"tag": "tag3",
42-
"port": 10809,
43-
"protocol": "http",
44-
"listen": "127.0.0.1",
45-
"settings": {
46-
"allowTransparent": false
47-
},
48-
"sniffing": {
49-
"enabled": true,
50-
"destOverride": [
51-
"http",
52-
"tls"
53-
]
54-
}
55-
}
56-
],
7+
"inbounds": [],
578
"outbounds": [{
589
"tag": "proxy",
5910
"protocol": "vmess",

v2rayN/v2rayN/Sample/SingboxSampleClientConfig

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
"level": "debug",
44
"timestamp": true
55
},
6-
"inbounds": [
7-
{
8-
"type": "socks",
9-
"tag": "socks",
10-
"listen": "127.0.0.1",
11-
"listen_port": 10000
12-
}
13-
],
6+
"inbounds": [],
147
"outbounds": [
158
{
169
"type": "vless",

v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public DNSSettingWindow()
5151

5252
private void linkDnsObjectDoc_Click(object sender, RoutedEventArgs e)
5353
{
54-
Utils.ProcessStart("https://www.v2fly.org/config/dns.html#dnsobject");
54+
Utils.ProcessStart("https://xtls.github.io/config/dns.html#dnsobject");
5555
}
5656

5757
private void linkDnsSingboxObjectDoc_Click(object sender, RoutedEventArgs e)

v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void ClbInboundTag_SelectionChanged(object sender, System.Windows.Contro
8383

8484
private void linkRuleobjectDoc_Click(object sender, RoutedEventArgs e)
8585
{
86-
Utils.ProcessStart("https://www.v2fly.org/config/routing.html#ruleobject");
86+
Utils.ProcessStart("https://xtls.github.io/config/routing.html#ruleobject");
8787
}
8888
}
8989
}

v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void LstRoutings_MouseDoubleClick(object sender, MouseButtonEventArgs e)
127127

128128
private void linkdomainStrategy_Click(object sender, System.Windows.RoutedEventArgs e)
129129
{
130-
Utils.ProcessStart("https://www.v2fly.org/config/routing.html");
130+
Utils.ProcessStart("https://xtls.github.io/config/routing.html");
131131
}
132132

133133
private void linkdomainStrategy4Singbox_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)