Merge remote-tracking branch 'fork/master' into dev

# Conflicts:
#	.github/workflows/build.yml
#	.github/workflows/docker.yml
#	.gitignore
#	base/pref.example.toml
#	base/snippets/emoji.toml
#	base/snippets/emoji.txt
#	scripts/build.macos.release.sh
#	scripts/build.windows.release.sh
#	scripts/rules_config.conf
#	src/generator/config/subexport.cpp
#	src/handler/interfaces.cpp
#	src/handler/settings.cpp
#	src/parser/config/proxy.h
#	src/parser/subparser.cpp
#	src/parser/subparser.h
#	src/utils/map_extra.h
#	src/version.h
This commit is contained in:
asdlokj1qpi23 committed 2025-03-25 14:08:43 +08:00
commit e88f8fd485
33 files changed
+887 -729

No files matched your search

+90 -23
View File
@@ -161,7 +161,8 @@ void processRemark(std::string &remark, const string_array &remarks_list, bool p
}
std::string tempRemark = remark;
int cnt = 2;
while (std::find(remarks_list.cbegin(), remarks_list.cend(), tempRemark) != remarks_list.cend()) {
while(std::find(remarks_list.cbegin(), remarks_list.cend(), tempRemark) != remarks_list.cend())
{
tempRemark = remark + " " + std::to_string(cnt);
cnt++;
}
@@ -218,6 +219,30 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
case "compact"_hash:
compact = true;
break;
bool proxy_block = false, proxy_compact = false, group_block = false, group_compact = false;
switch(hash_(ext.clash_proxies_style))
{
case "block"_hash:
proxy_block = true;
break;
default:
case "flow"_hash:
break;
case "compact"_hash:
proxy_compact = true;
break;
}
switch(hash_(ext.clash_proxy_groups_style))
{
case "block"_hash:
group_block = true;
break;
default:
case "flow"_hash:
break;
case "compact"_hash:
group_compact = true;
break;
}
for (Proxy &x: nodes) {
@@ -644,7 +669,10 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
string_array filtered_nodelist;
singlegroup["name"] = x.Name;
singlegroup["type"] = x.TypeStr();
if (x.Type == ProxyGroupType::Smart)
singlegroup["type"] = "url-test";
else
singlegroup["type"] = x.TypeStr();
switch (x.Type) {
case ProxyGroupType::Select:
@@ -666,6 +694,29 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
break;
default:
continue;
switch(x.Type)
{
case ProxyGroupType::Select:
case ProxyGroupType::Relay:
break;
case ProxyGroupType::LoadBalance:
singlegroup["strategy"] = x.StrategyStr();
[[fallthrough]];
case ProxyGroupType::Smart:
[[fallthrough]];
case ProxyGroupType::URLTest:
if(!x.Lazy.is_undef())
singlegroup["lazy"] = x.Lazy.get();
[[fallthrough]];
case ProxyGroupType::Fallback:
singlegroup["url"] = x.Url;
if(x.Interval > 0)
singlegroup["interval"] = x.Interval;
if(x.Tolerance > 0)
singlegroup["tolerance"] = x.Tolerance;
break;
default:
continue;
}
if (!x.DisableUdp.is_undef())
singlegroup["disable-udp"] = x.DisableUdp.get();
@@ -681,7 +732,10 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
}
if (!filtered_nodelist.empty())
singlegroup["proxies"] = filtered_nodelist;
//singlegroup.SetStyle(YAML::EmitterStyle::Flow);
if(group_block)
singlegroup.SetStyle(YAML::EmitterStyle::Block);
else
singlegroup.SetStyle(YAML::EmitterStyle::Flow);
bool replace_flag = false;
for (auto &&original_group: original_groups) {
@@ -694,6 +748,8 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
if (!replace_flag)
original_groups.push_back(singlegroup);
}
if(group_compact)
original_groups.SetStyle(YAML::EmitterStyle::Flow);
if (ext.clash_new_field_name)
yamlnode["proxy-groups"] = original_groups;
@@ -975,11 +1031,18 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
proxy += ", version=" + std::to_string(x.SnellVersion);
break;
case ProxyType::Hysteria2:
if (surge_ver < 4 && surge_ver != -3)
if(surge_ver < 4)
continue;
proxy = "hysteria2, " + hostname + ", " + port + ", password=" + password;
if (!scv.is_undef())
proxy += ", skip-cert-verify=" + scv.get_str();
proxy = "hysteria, " + hostname + ", " + port + ", password=" + password;
if(x.DownSpeed)
proxy += ", download-bandwidth=" + x.DownSpeed;
if(!scv.is_undef())
proxy += ",skip-cert-verify=" + std::string(scv.get() ? "true" : "false");
if(!x.Fingerprint.empty())
proxy += ",server-cert-fingerprint-sha256=" + x.Fingerprint;
if(!x.SNI.empty())
proxy += ",sni=" + x.SNI;
break;
case ProxyType::WireGuard:
if (surge_ver < 4 && surge_ver != -3)
@@ -1011,7 +1074,8 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
proxy += ", tfo=" + tfo.get_str();
if (!udp.is_undef())
proxy += ", udp-relay=" + udp.get_str();
if (underlying_proxy != "")
proxy += ", underlying-proxy=" + underlying_proxy;
if (ext.nodelist)
output_nodelist += x.Remark + " = " + proxy + "\n";
else {
@@ -1030,22 +1094,24 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
string_array filtered_nodelist;
std::string group;
switch (x.Type) {
case ProxyGroupType::Select:
case ProxyGroupType::URLTest:
case ProxyGroupType::Fallback:
break;
case ProxyGroupType::LoadBalance:
if (surge_ver < 1 && surge_ver != -3)
continue;
break;
case ProxyGroupType::SSID:
group = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
switch(x.Type)
{
case ProxyGroupType::Select:
case ProxyGroupType::Smart:
case ProxyGroupType::URLTest:
case ProxyGroupType::Fallback:
break;
case ProxyGroupType::LoadBalance:
if(surge_ver < 1 && surge_ver != -3)
continue;
break;
case ProxyGroupType::SSID:
group = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
group += join(x.Proxies.begin() + 1, x.Proxies.end(), ",");
ini.set("{NONAME}", x.Name + " = " + group); //insert order
continue;
default:
continue;
continue;
default:
continue;
}
for (const auto &y: x.Proxies)
@@ -1693,7 +1759,8 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
std::string proxies = join(filtered_nodelist, ", ");
std::string singlegroup = type + "=" + x.Name + ", " + proxies;
if (type != "static") {
if(x.Type != ProxyGroupType::Select && x.Type != ProxyGroupType::SSID)
{
singlegroup += ", check-interval=" + std::to_string(x.Interval);
if (x.Tolerance > 0)
singlegroup += ", tolerance=" + std::to_string(x.Tolerance);
+1
View File
@@ -40,6 +40,7 @@ struct extra_settings
bool clash_classical_ruleset = false;
std::string sort_script;
std::string clash_proxies_style = "flow";
std::string clash_proxy_groups_style = "flow";
bool authorized = false;
extra_settings() = default;
+17 -15
View File
@@ -357,10 +357,10 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
if(x.rule_type == RULESET_CLASH_IPCIDR || x.rule_type == RULESET_CLASH_DOMAIN || x.rule_type == RULESET_CLASH_CLASSICAL)
{
//rule_name = std::to_string(hash_(rule_group + rule_path));
rule_name = old_rule_name = findFileName(rule_path);
rule_name = old_rule_name = urlDecode(findFileName(rule_path));
int idx = 2;
while(std::find(groups.begin(), groups.end(), rule_name) != groups.end())
rule_name = old_rule_name + "_" + std::to_string(idx++);
rule_name = old_rule_name + " " + std::to_string(idx++);
names[rule_name] = rule_group;
urls[rule_name] = "*" + rule_path;
rule_type[rule_name] = x.rule_type;
@@ -386,10 +386,10 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
if(fileExist(rule_path, true) || isLink(rule_path))
{
//rule_name = std::to_string(hash_(rule_group + rule_path));
rule_name = old_rule_name = findFileName(rule_path);
rule_name = old_rule_name = urlDecode(findFileName(rule_path));
int idx = 2;
while(std::find(groups.begin(), groups.end(), rule_name) != groups.end())
rule_name = old_rule_name + "_" + std::to_string(idx++);
rule_name = old_rule_name + " " + std::to_string(idx++);
names[rule_name] = rule_group;
urls[rule_name] = rule_path_typed;
rule_type[rule_name] = x.rule_type;
@@ -436,9 +436,9 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
if(vArray.size() < 2)
continue;
if(keywords.find(rule_name) == keywords.end())
keywords[rule_name] = "\"" + vArray[1] + "\"";
keywords[rule_name] = "\"" + trim(vArray[1]) + "\"";
else
keywords[rule_name] += ",\"" + vArray[1] + "\"";
keywords[rule_name] += ",\"" + trim(vArray[1]) + "\"";
}
else
{
@@ -449,7 +449,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
}
else
{
strLine = vArray[0] + "," + vArray[1] + "," + rule_group;
strLine = vArray[0] + "," + trim(vArray[1]) + "," + rule_group;
if(vArray.size() > 2)
strLine += "," + vArray[2];
}
@@ -466,14 +466,16 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
}
}
if(has_domain[rule_name] && !script)
rules.emplace_back("RULE-SET," + rule_name + "_domain," + rule_group);
rules.emplace_back("RULE-SET," + rule_name + " (Domain)," + rule_group);
if(has_ipcidr[rule_name] && !script)
{
if(has_no_resolve)
rules.emplace_back("RULE-SET," + rule_name + "_ipcidr," + rule_group + ",no-resolve");
rules.emplace_back("RULE-SET," + rule_name + " (IP-CIDR)," + rule_group + ",no-resolve");
else
rules.emplace_back("RULE-SET," + rule_name + "_ipcidr," + rule_group);
rules.emplace_back("RULE-SET," + rule_name + " (IP-CIDR)," + rule_group);
}
if(!has_domain[rule_name] && !has_ipcidr[rule_name] && !script)
rules.emplace_back("RULE-SET," + rule_name + "," + rule_group);
if(std::find(groups.begin(), groups.end(), rule_name) == groups.end())
groups.emplace_back(rule_name);
}
@@ -488,14 +490,14 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
{
std::string yaml_key = x;
if(rule_type[x] != RULESET_CLASH_DOMAIN)
yaml_key += "_domain";
yaml_key += " (Domain)";
base_rule["rule-providers"][yaml_key]["type"] = "http";
base_rule["rule-providers"][yaml_key]["behavior"] = "domain";
if(url[0] == '*')
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
else
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=3&url=" + urlSafeBase64Encode(url);
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/" + std::to_string(hash_(url)) + "_domain.yaml";
if(interval)
base_rule["rule-providers"][yaml_key]["interval"] = interval;
}
@@ -503,14 +505,14 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
{
std::string yaml_key = x;
if(rule_type[x] != RULESET_CLASH_IPCIDR)
yaml_key += "_ipcidr";
yaml_key += " (IP-CIDR)";
base_rule["rule-providers"][yaml_key]["type"] = "http";
base_rule["rule-providers"][yaml_key]["behavior"] = "ipcidr";
if(url[0] == '*')
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
else
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=4&url=" + urlSafeBase64Encode(url);
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/" + std::to_string(hash_(url)) + "_ipcidr.yaml";
if(interval)
base_rule["rule-providers"][yaml_key]["interval"] = interval;
}
@@ -523,7 +525,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
else
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlSafeBase64Encode(url);
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/" + std::to_string(hash_(url)) + ".yaml";
if(interval)
base_rule["rule-providers"][yaml_key]["interval"] = interval;
}