V2RayGCon手册

Release Badge

导入hy2://...链接

hysteria2支持把分享链接写进配置,所以手搓个解码器很简单。
在NeoLuna的脚本编辑器中粘贴并运行以下代码:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- 自定义core名称
local customCoreName = "hy2"

-- 自定义inbound模板
local customInboundTemplateName = "hy2http"

-- 设置标记
local customMark = "hy2serv"

-- 代码
local hasUriDecodeFunc = std.Sys:GetAppVersion() >= "1.8.9.2"

local function ExtractHy2ShareLinks(s)
    local r = {}
    local lines = string.split(s, '\r\n" ')
    for _, line in ipairs(lines) do
        if string.startswith(line, "hy2://")
            or string.startswith(line, "hysteria2://")
        then
            table.insert(r, line)
        end
    end
    return r
end

local function GetName(link)
    if not hasUriDecodeFunc then
        return ""
    end
    local ps = string.split(link, "#")
    return #ps > 1 and std.Web:UriDecode(ps[#ps]) or ""
end

local function GenConfig(link)
    local http = [[
http:
  listen: 127.0.0.1:8080

]]
    return http .. "server: " .. link
end

local function ChangeServSettings(uid)
    local wserv = std.Server:GetWrappedServerByUid(uid)
    if wserv == nil then
        return
    end
    wserv:SetCustomCoreName(customCoreName)
    wserv:SetInboundName(customInboundTemplateName)
end

local function Import(links)
    local c = 0
    for _, link in ipairs(links) do
        local name = GetName(link)
        local config = GenConfig(link)
        local uid = std.Server:AddNew(name, config, customMark)
        if not string.isempty(uid) then
            c = c + 1
            ChangeServSettings(uid)
            print("成功:", link)
        else
            print("失败:", link)
        end
    end
    return "导入了[" .. c .. "]个服务器"
end

local function Main()
    local text = std.Misc:Input("hy2://...链接:", 10)
    local msg = "内容为空"
    if not string.isempty(text) then
        local links = ExtractHy2ShareLinks(text)
        msg = Import(links)
    end
    std.Misc:Alert(msg)
end

Main()

hy2http模板如下:

1
2
http:
  listen: %host%:%port%

hy2的自定义core配置:


注:需要下载hysteria2内核放到3rd/hy2目录内

Last updated on 1 Feb 2020
Published on 1 Feb 2020
Edit on GitHub