Add shadowsocks subscription support

This commit is contained in:
Bruce Wayne
2020-01-22 23:09:40 +08:00
parent 1fcc1d208e
commit c857c2a72c
2 changed files with 40 additions and 4 deletions

View File

@@ -0,0 +1,13 @@
namespace Netch.Models.SS
{
public class ShadowsocksServer
{
public string server { get; set; }
public int server_port { get; set; }
public string password { get; set; }
public string method { get; set; }
public string remarks { get; set; }
public string plugin { get; set; }
public string plugin_opts { get; set; }
}
}

View File

@@ -1,9 +1,13 @@
using Netch.Models;
using Netch.Models.SS;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using VMess = Netch.Models.VMess;
namespace Netch.Utils
{
@@ -24,14 +28,33 @@ namespace Netch.Utils
var list = new List<Server>();
try
{
foreach (var line in text.GetLines())
try
{
var servers = ParseLine(line);
if (line != null)
var ssServers = JsonConvert.DeserializeObject<List<ShadowsocksServer>>(text);
list.AddRange(ssServers.Select(shadowsocksServer => new Server
{
list.AddRange(servers);
Type = "SS",
Hostname = shadowsocksServer.server,
Port = shadowsocksServer.server_port,
EncryptMethod = shadowsocksServer.method,
Password = shadowsocksServer.password,
Remark = shadowsocksServer.remarks,
Plugin = shadowsocksServer.plugin,
PluginOption = shadowsocksServer.plugin_opts
}));
}
catch (JsonReaderException)
{
foreach (var line in text.GetLines())
{
var servers = ParseLine(line);
if (line != null)
{
list.AddRange(servers);
}
}
}
if (list.Count == 0)
{
System.Windows.Forms.MessageBox.Show(@"未找到可导入的链接!", @"错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);