diff --git a/Netch/Forms/ServerForm.cs b/Netch/Forms/ServerForm.cs index bd461800..63142a33 100644 --- a/Netch/Forms/ServerForm.cs +++ b/Netch/Forms/ServerForm.cs @@ -32,7 +32,7 @@ namespace Netch.Forms _saveActions.Add(PortTextBox, s => Server.Port = ushort.Parse((string) s)); } - protected void CreateTextBox(string name, string remark, Func check, Action save, string value, int width = InputBoxWidth) + protected void CreateTextBox(string name, string remark, Func check, Action save, string value, int width = InputBoxWidth) { _controlLines++; @@ -45,7 +45,7 @@ namespace Netch.Forms Text = value }; _checkActions.Add(textBox, check); - _saveActions.Add(textBox, save); + _saveActions.Add(textBox, o => save.Invoke((string) o)); ConfigurationGroupBox.Controls.AddRange( new Control[] { @@ -62,7 +62,7 @@ namespace Netch.Forms ); } - protected void CreateComboBox(string name, string remark, List values, Func parse, Action save, string value, int width = InputBoxWidth) + protected void CreateComboBox(string name, string remark, List values, Func parse, Action save, string value, int width = InputBoxWidth) { _controlLines++; @@ -79,7 +79,7 @@ namespace Netch.Forms comboBox.SelectedIndex = values.IndexOf(value); comboBox.DrawItem += Utils.Utils.DrawCenterComboBox; _checkActions.Add(comboBox, parse); - _saveActions.Add(comboBox, save); + _saveActions.Add(comboBox, o => save.Invoke((string) o)); ConfigurationGroupBox.Controls.AddRange( new Control[] { @@ -96,7 +96,7 @@ namespace Netch.Forms ); } - protected void CreateCheckBox(string name, string remark, Action save, bool value) + protected void CreateCheckBox(string name, string remark, Action save, bool value) { _controlLines++; @@ -108,7 +108,7 @@ namespace Netch.Forms Checked = value, Text = remark }; - _saveActions.Add(checkBox, save); + _saveActions.Add(checkBox, o => save.Invoke((bool) o)); ConfigurationGroupBox.Controls.AddRange( new Control[] { diff --git a/Netch/Servers/Shadowsocks/Form/ShadowsocksForm.cs b/Netch/Servers/Shadowsocks/Form/ShadowsocksForm.cs index 20d0ef21..4adbef01 100644 --- a/Netch/Servers/Shadowsocks/Form/ShadowsocksForm.cs +++ b/Netch/Servers/Shadowsocks/Form/ShadowsocksForm.cs @@ -12,20 +12,20 @@ namespace Netch.Servers.Shadowsocks.Form Server = server; CreateTextBox("Password", "Password", s => true, - s => server.Password = (string) s, + s => server.Password = s, server.Password); CreateComboBox("EncryptMethod", "Encrypt Method", SSGlobal.EncryptMethods, s => SSGlobal.EncryptMethods.Contains(s), - s => server.EncryptMethod = (string) s, + s => server.EncryptMethod = s, server.EncryptMethod); CreateTextBox("Plugin", "Plugin", s => true, - s => server.Plugin = (string) s, + s => server.Plugin = s, server.Plugin); CreateTextBox("PluginsOption", "Plugin Options", s => true, - s => server.PluginOption = (string) s, + s => server.PluginOption = s, server.PluginOption); } } diff --git a/Netch/Servers/ShadowsocksR/Form/ShadowsocksRForm.cs b/Netch/Servers/ShadowsocksR/Form/ShadowsocksRForm.cs index 423969cb..d775fb73 100644 --- a/Netch/Servers/ShadowsocksR/Form/ShadowsocksRForm.cs +++ b/Netch/Servers/ShadowsocksR/Form/ShadowsocksRForm.cs @@ -12,30 +12,30 @@ namespace Netch.Servers.ShadowsocksR.Form Server = server; CreateTextBox("Password", "Password", s => true, - s => server.Password = (string) s, + s => server.Password = s, server.Password); CreateComboBox("EncryptMethod", "Encrypt Method", SSRGlobal.EncryptMethods, s => SSRGlobal.EncryptMethods.Contains(s), - s => server.EncryptMethod = (string) s, + s => server.EncryptMethod = s, server.EncryptMethod); CreateComboBox("Protocol", "Protocol", SSRGlobal.Protocols, s => SSRGlobal.Protocols.Contains(s), - s => server.Protocol = (string) s, + s => server.Protocol = s, server.Protocol); CreateTextBox("ProtocolParam", "Protocol Param", s => true, - s => server.ProtocolParam = (string) s, + s => server.ProtocolParam = s, server.ProtocolParam); CreateComboBox("OBFS", "OBFS", SSRGlobal.OBFSs, s => SSRGlobal.OBFSs.Contains(s), - s => server.OBFS = (string) s, + s => server.OBFS = s, server.OBFS); CreateTextBox("OBFSParam", "OBFS Param", s => true, - s => server.OBFSParam = (string) s, + s => server.OBFSParam = s, server.OBFSParam); } } diff --git a/Netch/Servers/VMess/Form/VMessForm.cs b/Netch/Servers/VMess/Form/VMessForm.cs index d01e74df..24b39016 100644 --- a/Netch/Servers/VMess/Form/VMessForm.cs +++ b/Netch/Servers/VMess/Form/VMessForm.cs @@ -12,50 +12,50 @@ namespace Netch.Servers.VMess.Form Server = server; CreateTextBox("UserId", "User ID", s => true, - s => server.UserID = (string) s, + s => server.UserID = s, server.UserID); CreateTextBox("AlterId", "Alter ID", s => int.TryParse(s, out _), - s => server.AlterID = int.Parse((string) s), + s => server.AlterID = int.Parse(s), server.AlterID.ToString(), 76); CreateComboBox("EncryptMethod", "Encrypt Method", VMessGlobal.EncryptMethods, s => VMessGlobal.EncryptMethods.Contains(s), - s => server.EncryptMethod = (string) s, + s => server.EncryptMethod = s, server.EncryptMethod); CreateComboBox("TransferProtocol", "Transfer Protocol", VMessGlobal.TransferProtocols, s => VMessGlobal.TransferProtocols.Contains(s), - s => server.TransferProtocol = (string) s, + s => server.TransferProtocol = s, server.TransferProtocol); CreateComboBox("FakeType", "Fake Type", VMessGlobal.FakeTypes, s => VMessGlobal.FakeTypes.Contains(s), - s => server.FakeType = (string) s, + s => server.FakeType = s, server.FakeType); CreateTextBox("Host", "Host", s => true, - s => server.Host = (string) s, + s => server.Host = s, server.Host); CreateTextBox("Path", "Path", s => true, - s => server.Path = (string) s, + s => server.Path = s, server.Path); CreateComboBox("QUICSecurity", "QUIC Security", VMessGlobal.QUIC, s => VMessGlobal.QUIC.Contains(s), - s => server.QUIC = (string) s, + s => server.QUIC = s, server.QUIC); CreateTextBox("QUICSecret", "QUIC Secret", s => true, - s => server.QUICSecret = (string) s, + s => server.QUICSecret = s, server.QUICSecret); CreateCheckBox("UseMux", "Use Mux", - s => server.UseMux = (bool) s, + s => server.UseMux = s, server.UseMux); CreateCheckBox("TLSSecure", "TLS Secure", - s => server.TLSSecure = (bool) s, + s => server.TLSSecure = s, server.TLSSecure); } } diff --git a/Test/Tests.cs b/Test/Tests.cs index 7b0a626d..de036dfe 100644 --- a/Test/Tests.cs +++ b/Test/Tests.cs @@ -2,6 +2,8 @@ using System.Windows.Forms; using Netch.Servers.ShadowsocksR.Form; using Netch.Servers.ShadowsocksR; +using Netch.Servers.VMess; +using Netch.Servers.VMess.Form; using Netch.Utils; using NUnit.Framework; @@ -15,12 +17,36 @@ namespace Test { i18N.Load("zh-CN"); - var server = (ShadowsocksR) new SSRUtil().ParseUri(@"ssr://MTI3LjAuMC4xOjEyMzQ6YXV0aF9hZXMxMjhfbWQ1OmFlcy0xMjgtY2ZiOnRsczEuMl90aWNrZXRfYXV0aDpZV0ZoWW1KaS8_b2Jmc3BhcmFtPVluSmxZV3QzWVRFeExtMXZaUSZyZW1hcmtzPTVyV0w2Sy1WNUxpdDVwYUg").First(); - server.ProtocolParam = "ProtocolParam"; + var server = ParseVMessUri(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new ShadowsocksRForm(server)); + Application.Run(new VMessForm(server)); + } + + private static ShadowsocksR ParseSSRUri() + { + return (ShadowsocksR) new SSRUtil().ParseUri(@"ssr://MTI3LjAuMC4xOjEyMzQ6YXV0aF9hZXMxMjhfbWQ1OmFlcy0xMjgtY2ZiOnRsczEuMl90aWNrZXRfYXV0aDpZV0ZoWW1KaS8_b2Jmc3BhcmFtPVluSmxZV3QzWVRFeExtMXZaUSZyZW1hcmtzPTVyV0w2Sy1WNUxpdDVwYUg").First(); + } + + private static VMess ParseVMessUri() + { + /* +{ +"v": "2", +"ps": "备注别名", +"add": "111.111.111.111", +"port": "32000", +"id": "1386f85e-657b-4d6e-9d56-78badb75e1fd", +"aid": "100", +"net": "tcp", +"type": "none", +"host": "www.bbb.com", +"path": "/", +"tls": "tls" +} + */ + return (VMess) new VMessUtil().ParseUri(@"vmess://eyAidiI6ICIyIiwgInBzIjogIuWkh+azqOWIq+WQjSIsICJhZGQiOiAiMTExLjExMS4xMTEuMTExIiwgInBvcnQiOiAiMzIwMDAiLCAiaWQiOiAiMTM4NmY4NWUtNjU3Yi00ZDZlLTlkNTYtNzhiYWRiNzVlMWZkIiwgImFpZCI6ICIxMDAiLCAibmV0IjogInRjcCIsICJ0eXBlIjogIm5vbmUiLCAiaG9zdCI6ICJ3d3cuYmJiLmNvbSIsICJwYXRoIjogIi8iLCAidGxzIjogInRscyIgfQ==").First(); } } } \ No newline at end of file