|
3 | 3 | #include <numeric> |
4 | 4 | #include <cmath> |
5 | 5 | #include <climits> |
| 6 | +#include <cctype> |
6 | 7 |
|
7 | 8 | #include "config/regmatch.h" |
8 | 9 | #include "generator/config/subexport.h" |
@@ -2258,6 +2259,25 @@ static rapidjson::Value stringArrayToJsonArray(const std::string &array, const s |
2258 | 2259 | return result; |
2259 | 2260 | } |
2260 | 2261 |
|
| 2262 | +static rapidjson::Value buildSingBoxHysteria2ServerPorts(const std::string &ports, rapidjson::MemoryPoolAllocator<> &allocator) |
| 2263 | +{ |
| 2264 | + rapidjson::Value result(rapidjson::kArrayType); |
| 2265 | + string_array port_list = split(ports, ","); |
| 2266 | + for (const auto &raw_port : port_list) |
| 2267 | + { |
| 2268 | + std::string port_entry = trim(raw_port); |
| 2269 | + if (port_entry.empty()) |
| 2270 | + continue; |
| 2271 | + |
| 2272 | + const bool is_single_port = std::all_of(port_entry.begin(), port_entry.end(), [](unsigned char ch) { return std::isdigit(ch); }); |
| 2273 | + if (is_single_port) |
| 2274 | + port_entry = port_entry + ":" + port_entry; |
| 2275 | + |
| 2276 | + result.PushBack(rapidjson::Value(port_entry.c_str(), allocator), allocator); |
| 2277 | + } |
| 2278 | + return result; |
| 2279 | +} |
| 2280 | + |
2261 | 2281 | void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext) { |
2262 | 2282 | using namespace rapidjson_ext; |
2263 | 2283 | rapidjson::Document::AllocatorType &allocator = json.GetAllocator(); |
@@ -2424,7 +2444,7 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v |
2424 | 2444 | { |
2425 | 2445 | addSingBoxCommonMembers(proxy, x, "hysteria2", allocator); |
2426 | 2446 | if (!x.Ports.empty()) |
2427 | | - proxy.AddMember("server_ports", stringArrayToJsonArray(x.Ports, ",", allocator), allocator); |
| 2447 | + proxy.AddMember("server_ports", buildSingBoxHysteria2ServerPorts(x.Ports, allocator), allocator); |
2428 | 2448 | if (!x.Up.empty()) |
2429 | 2449 | proxy.AddMember("up_mbps", x.UpSpeed, allocator); |
2430 | 2450 | if (!x.Down.empty()) |
|
0 commit comments