mirror of
https://github.com/netchx/netch.git
synced 2026-05-11 23:45:06 +08:00
Enable Nullable
This commit is contained in:
@@ -4,7 +4,7 @@ namespace Netch.Servers.Shadowsocks.Form
|
||||
{
|
||||
public class ShadowsocksForm : ServerForm
|
||||
{
|
||||
public ShadowsocksForm(Shadowsocks server = default)
|
||||
public ShadowsocksForm(Shadowsocks? server = default)
|
||||
{
|
||||
server ??= new Shadowsocks();
|
||||
Server = server;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
#nullable disable
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Netch.Servers.Shadowsocks.Models.SSD
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace Netch.Servers.Shadowsocks.Models.SSD
|
||||
#nullable disable
|
||||
namespace Netch.Servers.Shadowsocks.Models.SSD
|
||||
{
|
||||
public class SSDServer
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable disable
|
||||
namespace Netch.Servers.Shadowsocks.Models
|
||||
{
|
||||
public class ShadowsocksConfig
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Netch.Servers.Shadowsocks
|
||||
|
||||
public ushort? Socks5LocalPort { get; set; }
|
||||
|
||||
public string LocalAddress { get; set; }
|
||||
public string? LocalAddress { get; set; }
|
||||
|
||||
public void Start(in Server s, in Mode mode)
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Netch.Servers.Shadowsocks
|
||||
if (text.StartsWith("ssd://"))
|
||||
return ParseSsdUri(text);
|
||||
|
||||
return null;
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public bool CheckServer(Server s)
|
||||
@@ -102,93 +102,82 @@ namespace Netch.Servers.Shadowsocks
|
||||
var data = new Shadowsocks();
|
||||
|
||||
text = text.Replace("/?", "?");
|
||||
try
|
||||
if (text.Contains("#"))
|
||||
{
|
||||
if (text.Contains("#"))
|
||||
{
|
||||
data.Remark = HttpUtility.UrlDecode(text.Split('#')[1]);
|
||||
text = text.Split('#')[0];
|
||||
}
|
||||
|
||||
if (text.Contains("?"))
|
||||
{
|
||||
var finder = new Regex(@"^(?<data>.+?)\?(.+)$");
|
||||
var match = finder.Match(text);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
var plugins = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(text).Query).Get("plugin"));
|
||||
if (plugins != null)
|
||||
{
|
||||
var plugin = plugins.Substring(0, plugins.IndexOf(";", StringComparison.Ordinal));
|
||||
var pluginopts = plugins.Substring(plugins.IndexOf(";", StringComparison.Ordinal) + 1);
|
||||
switch (plugin)
|
||||
{
|
||||
case "obfs-local":
|
||||
case "simple-obfs":
|
||||
plugin = "simple-obfs";
|
||||
if (!pluginopts.Contains("obfs="))
|
||||
pluginopts = "obfs=http;obfs-host=" + pluginopts;
|
||||
|
||||
break;
|
||||
case "simple-obfs-tls":
|
||||
plugin = "simple-obfs";
|
||||
if (!pluginopts.Contains("obfs="))
|
||||
pluginopts = "obfs=tls;obfs-host=" + pluginopts;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
data.Plugin = plugin;
|
||||
data.PluginOption = pluginopts;
|
||||
}
|
||||
|
||||
text = match.Groups["data"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
}
|
||||
|
||||
if (text.Contains("@"))
|
||||
{
|
||||
var finder = new Regex(@"^ss://(?<base64>.+?)@(?<server>.+):(?<port>\d+)");
|
||||
var parser = new Regex(@"^(?<method>.+?):(?<password>.+)$");
|
||||
var match = finder.Match(text);
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
data.Hostname = match.Groups["server"].Value;
|
||||
data.Port = ushort.Parse(match.Groups["port"].Value);
|
||||
|
||||
var base64 = ShareLink.URLSafeBase64Decode(match.Groups["base64"].Value);
|
||||
match = parser.Match(base64);
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
data.EncryptMethod = match.Groups["method"].Value;
|
||||
data.Password = match.Groups["password"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
var parser = new Regex(@"^((?<method>.+?):(?<password>.+)@(?<server>.+):(?<port>\d+))");
|
||||
var match = parser.Match(ShareLink.URLSafeBase64Decode(text.Replace("ss://", "")));
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
data.Hostname = match.Groups["server"].Value;
|
||||
data.Port = ushort.Parse(match.Groups["port"].Value);
|
||||
data.EncryptMethod = match.Groups["method"].Value;
|
||||
data.Password = match.Groups["password"].Value;
|
||||
}
|
||||
|
||||
return CheckServer(data) ? data : null;
|
||||
data.Remark = HttpUtility.UrlDecode(text.Split('#')[1]);
|
||||
text = text.Split('#')[0];
|
||||
}
|
||||
catch (FormatException)
|
||||
|
||||
if (text.Contains("?"))
|
||||
{
|
||||
return null;
|
||||
var finder = new Regex(@"^(?<data>.+?)\?(.+)$");
|
||||
var match = finder.Match(text);
|
||||
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
var plugins = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(text).Query).Get("plugin"));
|
||||
if (plugins != null)
|
||||
{
|
||||
var plugin = plugins.Substring(0, plugins.IndexOf(";", StringComparison.Ordinal));
|
||||
var pluginopts = plugins.Substring(plugins.IndexOf(";", StringComparison.Ordinal) + 1);
|
||||
switch (plugin)
|
||||
{
|
||||
case "obfs-local":
|
||||
case "simple-obfs":
|
||||
plugin = "simple-obfs";
|
||||
if (!pluginopts.Contains("obfs="))
|
||||
pluginopts = "obfs=http;obfs-host=" + pluginopts;
|
||||
|
||||
break;
|
||||
case "simple-obfs-tls":
|
||||
plugin = "simple-obfs";
|
||||
if (!pluginopts.Contains("obfs="))
|
||||
pluginopts = "obfs=tls;obfs-host=" + pluginopts;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
data.Plugin = plugin;
|
||||
data.PluginOption = pluginopts;
|
||||
}
|
||||
|
||||
text = match.Groups["data"].Value;
|
||||
}
|
||||
|
||||
if (text.Contains("@"))
|
||||
{
|
||||
var finder = new Regex(@"^ss://(?<base64>.+?)@(?<server>.+):(?<port>\d+)");
|
||||
var parser = new Regex(@"^(?<method>.+?):(?<password>.+)$");
|
||||
var match = finder.Match(text);
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
data.Hostname = match.Groups["server"].Value;
|
||||
data.Port = ushort.Parse(match.Groups["port"].Value);
|
||||
|
||||
var base64 = ShareLink.URLSafeBase64Decode(match.Groups["base64"].Value);
|
||||
match = parser.Match(base64);
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
data.EncryptMethod = match.Groups["method"].Value;
|
||||
data.Password = match.Groups["password"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
var parser = new Regex(@"^((?<method>.+?):(?<password>.+)@(?<server>.+):(?<port>\d+))");
|
||||
var match = parser.Match(ShareLink.URLSafeBase64Decode(text.Replace("ss://", "")));
|
||||
if (!match.Success)
|
||||
throw new FormatException();
|
||||
|
||||
data.Hostname = match.Groups["server"].Value;
|
||||
data.Port = ushort.Parse(match.Groups["port"].Value);
|
||||
data.EncryptMethod = match.Groups["method"].Value;
|
||||
data.Password = match.Groups["password"].Value;
|
||||
}
|
||||
|
||||
return CheckServer(data) ? data : throw new FormatException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,17 @@ namespace Netch.Servers.Shadowsocks
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 插件
|
||||
/// </summary>
|
||||
public string Plugin { get; set; }
|
||||
public string? Plugin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 插件参数
|
||||
/// </summary>
|
||||
public string PluginOption { get; set; }
|
||||
public string? PluginOption { get; set; }
|
||||
|
||||
public bool HasPlugin()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user