diff --git a/main.cpp b/main.cpp index e0eba7591..50148068d 100644 --- a/main.cpp +++ b/main.cpp @@ -188,6 +188,7 @@ int main() if(!url.size()) url = default_url; string_array urls = split(url, "|"); std::vector nodes; + int groupID = 0; if(include.size()) { eraseElements(def_include_remarks); @@ -197,7 +198,8 @@ int main() for(std::string &x : urls) { std::cerr<<"Fetching node data from url '"< nodes; + int groupID = 0; if(include.size()) { eraseElements(def_include_remarks); @@ -227,7 +230,8 @@ int main() for(std::string &x : urls) { std::cerr<<"Fetching node data from url '"< nodes; + int groupID = 0; if(include.size()) { eraseElements(def_include_remarks); @@ -258,12 +263,11 @@ int main() for(std::string &x : urls) { std::cerr<<"Fetching node data from url '"< *source, std::vector *dest) { @@ -20,7 +21,7 @@ void copyNodes(std::vector *source, std::vector *dest) } } -void addNodes(std::string link, std::vector &allNodes) +void addNodes(std::string link, std::vector &allNodes, int groupID) { int linkType = -1; std::vector nodes; @@ -67,6 +68,8 @@ void addNodes(std::string link, std::vector &allNodes) { writeLog(LOG_TYPE_INFO, "Parsing subscription data..."); explodeConfContent(strSub, override_conf_port, socksport, ss_libev, ssr_libev, nodes); + for(nodeInfo &x : nodes) + x.groupID = groupID; copyNodes(&nodes, &allNodes); } else @@ -75,6 +78,8 @@ void addNodes(std::string link, std::vector &allNodes) } break; case SPEEDTEST_MESSAGE_FOUNDLOCAL: + if(api_mode) + break; writeLog(LOG_TYPE_INFO, "Parsing configuration file data..."); if(explodeConf(link, override_conf_port, socksport, ss_libev, ssr_libev, nodes) == SPEEDTEST_ERROR_UNRECOGFILE) { @@ -82,6 +87,8 @@ void addNodes(std::string link, std::vector &allNodes) } else { + for(nodeInfo &x : nodes) + x.groupID = groupID; copyNodes(&nodes, &allNodes); } break; @@ -97,6 +104,7 @@ void addNodes(std::string link, std::vector &allNodes) } else { + node.groupID = groupID; allNodes.push_back(node); } } diff --git a/nodemanip.h b/nodemanip.h index b69398d14..e8f2a9414 100644 --- a/nodemanip.h +++ b/nodemanip.h @@ -6,6 +6,6 @@ #include "nodeinfo.h" -void addNodes(std::string link, std::vector &allNodes); +void addNodes(std::string link, std::vector &allNodes, int groupID); #endif // NODEMANIP_H_INCLUDED diff --git a/pref.ini b/pref.ini index 9bf465d78..54850ea4a 100644 --- a/pref.ini +++ b/pref.ini @@ -103,6 +103,10 @@ surge_ruleset=💕 规则自选,[]MATCH ;custom_proxy_group=FallBack`fallback`.*`http://www.gstatic.com/generate_204`300 ;custom_proxy_group=LoadBalance`load-balance`.*`http://www.gstatic.com/generate_204`300 +;custom_proxy_group=g1`select`!!GROUPID=0 +;custom_proxy_group=g2`select`!!GROUPID=1 +;custom_proxy_group=v2ray`select`!!GROUP=V2RayProvider + ;for forcerule.yml ;custom_proxy_group=Proxy`select`.*[]AUTO`[]DIRECT`.* ;custom_proxy_group=AUTO`url-test`.*`http://www.gstatic.com/generate_204`300 @@ -142,5 +146,5 @@ listen=0.0.0.0 port=25500 [advanced] -max_pending_connections=10 +max_pending_connections=10240 max_concurrent_threads=4 diff --git a/speedtestutil.cpp b/speedtestutil.cpp index fc601f29e..da92e049e 100644 --- a/speedtestutil.cpp +++ b/speedtestutil.cpp @@ -165,19 +165,19 @@ void explodeVmess(std::string vmess, std::string custom_port, int local_port, no version = "1"; //link without version will treat as version 1 GetMember(jsondata, "v", version); //try to get version - jsondata["ps"] >> ps; - jsondata["add"] >> add; - jsondata["type"] >> type; - jsondata["id"] >> id; - jsondata["aid"] >> aid; - jsondata["net"] >> net; - jsondata["tls"] >> tls; + GetMember(jsondata, "ps", ps); + GetMember(jsondata, "add", add); + GetMember(jsondata, "type", type); + GetMember(jsondata, "id", id); + GetMember(jsondata, "aid", aid); + GetMember(jsondata, "net", net); + GetMember(jsondata, "tls", tls); if(custom_port != "") port = custom_port; else - jsondata["port"] >> port; + GetMember(jsondata, "port", port); - jsondata["host"] >> host; + GetMember(jsondata, "host", host); if(version == "1") { if(host != "") @@ -872,24 +872,12 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v yamlnode["Proxy"][i]["password"] >> password; if(yamlnode["Proxy"][i]["plugin"].IsDefined()) { - if(yamlnode["Proxy"][i]["plugin"].as() == "obfs") - { - plugin = "simple-obfs"; - if(yamlnode["Proxy"][i]["plugin-opts"].IsDefined()) - { - yamlnode["Proxy"][i]["plugin-opts"]["mode"] >> pluginopts_mode; - if(yamlnode["Proxy"][i]["plugin-opts"]["host"].IsDefined()) - yamlnode["Proxy"][i]["plugin-opts"]["host"] >> pluginopts_host; - } - } - } - else if(yamlnode["Proxy"][i]["obfs"].IsDefined()) - { - plugin = "simple-obfs"; - yamlnode["Proxy"][i]["obfs"] >> pluginopts_mode; - if(yamlnode["Proxy"][i]["obfs-host"].IsDefined()) + yamlnode["Proxy"][i]["plugin"] >> plugin; + if(yamlnode["Proxy"][i]["plugin-opts"].IsDefined()) { - yamlnode["Proxy"][i]["obfs-host"] >> pluginopts_host; + yamlnode["Proxy"][i]["plugin-opts"]["mode"] >> pluginopts_mode; + if(yamlnode["Proxy"][i]["plugin-opts"]["host"].IsDefined()) + yamlnode["Proxy"][i]["plugin-opts"]["host"] >> pluginopts_host; } } else diff --git a/subexport.cpp b/subexport.cpp index 9573272d6..5797d4c5f 100644 --- a/subexport.cpp +++ b/subexport.cpp @@ -286,7 +286,8 @@ std::string netchToClash(std::vector &nodes, std::string &baseConf, st std::string plugin, pluginopts; std::string protocol, protoparam, obfs, obfsparam; std::string id, aid, transproto, faketype, host, path, quicsecure, quicsecret; - std::vector nodelist; + std::vector nodelist; + std::string group; bool tlssecure, replace_flag; string_array vArray, filtered_nodelist; @@ -305,7 +306,7 @@ std::string netchToClash(std::vector &nodes, std::string &baseConf, st singleproxy.reset(); json.Parse(x.proxyStr.data()); type = GetMember(json, "Type"); - remark = addEmoji(trim(removeEmoji(nodeRename(x.remarks)))); + remark = x.remarks = addEmoji(trim(removeEmoji(nodeRename(x.remarks)))); hostname = GetMember(json, "Hostname"); port = GetMember(json, "Port"); username = GetMember(json, "Username"); @@ -378,7 +379,7 @@ std::string netchToClash(std::vector &nodes, std::string &baseConf, st singleproxy["server"] = hostname; singleproxy["port"] = (unsigned short)stoi(port); proxies.push_back(singleproxy); - nodelist.emplace_back(remark); + nodelist.emplace_back(x); } yamlnode["Proxy"] = proxies; @@ -439,12 +440,30 @@ std::string netchToClash(std::vector &nodes, std::string &baseConf, st { filtered_nodelist.emplace_back(vArray[i].substr(2)); } + else if(vArray[i].find("!!GROUP=") == 0) + { + group = vArray[i].substr(8); + for(nodeInfo &y : nodelist) + { + if(regFind(y.group, group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end()) + filtered_nodelist.emplace_back(y.remarks); + } + } + else if(vArray[i].find("!!GROUPID=") == 0) + { + group = vArray[i].substr(10); + for(nodeInfo &y : nodelist) + { + if(y.groupID == stoi(group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end()) + filtered_nodelist.emplace_back(y.remarks); + } + } else { - for(std::string &y : nodelist) + for(nodeInfo &y : nodelist) { - if(regFind(y, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y) == filtered_nodelist.end()) - filtered_nodelist.emplace_back(y); + if(regFind(y.remarks, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end()) + filtered_nodelist.emplace_back(y.remarks); } } } @@ -484,8 +503,8 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s std::string type, remark, hostname, port, username, password, method; std::string plugin, pluginopts; std::string id, aid, transproto, faketype, host, path, quicsecure, quicsecret; - std::string url; - std::vector nodelist; + std::string url, group; + std::vector nodelist; bool tlssecure; string_array vArray, filtered_nodelist; @@ -500,7 +519,7 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s { json.Parse(x.proxyStr.data()); type = GetMember(json, "Type"); - remark = addEmoji(trim(removeEmoji(nodeRename(x.remarks)))); + remark = x.remarks = addEmoji(trim(removeEmoji(nodeRename(x.remarks)))); hostname = GetMember(json, "Hostname"); port = std::__cxx11::to_string((unsigned short)stoi(GetMember(json, "Port"))); username = GetMember(json, "Username"); @@ -565,7 +584,7 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s else continue; ini.Set(remark, proxy); - nodelist.emplace_back(remark); + nodelist.emplace_back(x); } ini.SetCurrentSection("Proxy Group"); @@ -600,12 +619,30 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s { filtered_nodelist.emplace_back(vArray[i].substr(2)); } + else if(vArray[i].find("!!GROUP=") == 0) + { + group = vArray[i].substr(8); + for(nodeInfo &y : nodelist) + { + if(regFind(y.group, group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end()) + filtered_nodelist.emplace_back(y.remarks); + } + } + else if(vArray[i].find("!!GROUPID=") == 0) + { + group = vArray[i].substr(10); + for(nodeInfo &y : nodelist) + { + if(y.groupID == stoi(group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end()) + filtered_nodelist.emplace_back(y.remarks); + } + } else { - for(std::string &y : nodelist) + for(nodeInfo &y : nodelist) { - if(regFind(y, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y) == filtered_nodelist.end()) - filtered_nodelist.emplace_back(y); + if(regFind(y.remarks, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end()) + filtered_nodelist.emplace_back(y.remarks); } } }