mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 02:02:24 +00:00
Enhancements
Fix logical error in generating Quantumult X configurations. Fix overwrite_original_rules option not working in pref configuration. Add range support for group ID match condition.
This commit is contained in:
3 files changed
+61
-12
No files matched your search
+59
-11
@@ -244,14 +244,61 @@ std::string vmessLinkConstruct(std::string remarks, std::string add, std::string
|
||||
return sb.GetString();
|
||||
}
|
||||
|
||||
bool matchRange(std::string &range, int target)
|
||||
{
|
||||
string_array vArray = split(range, ",");
|
||||
bool match = false;
|
||||
int range_begin = 0, range_end = 0;
|
||||
const std::string reg_num = "\\d+", reg_range = "(\\d+)-(\\d+)", reg_not = "\\!(\\d+)", reg_not_range = "\\!(\\d+)-(\\d+)", reg_less = "(\\d+)-", reg_more = "(\\d+)\+";
|
||||
for(std::string &x : vArray)
|
||||
{
|
||||
if(regMatch(x, reg_num))
|
||||
{
|
||||
if(to_int(x, INT_MAX) == target)
|
||||
match = true;
|
||||
}
|
||||
else if(regMatch(x, reg_range))
|
||||
{
|
||||
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
|
||||
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
|
||||
if(target >= range_begin && target <= range_end)
|
||||
match = true;
|
||||
}
|
||||
else if(regMatch(x, reg_not))
|
||||
{
|
||||
if(to_int(regReplace(x, reg_not, "$1"), INT_MAX) == target)
|
||||
match = false;
|
||||
}
|
||||
else if(regMatch(x, reg_not_range))
|
||||
{
|
||||
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
|
||||
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
|
||||
if(target >= range_begin && target <= range_end)
|
||||
match = false;
|
||||
}
|
||||
else if(regMatch(x, reg_less))
|
||||
{
|
||||
if(to_int(regReplace(x, reg_less, "$1"), INT_MAX) <= target)
|
||||
match = true;
|
||||
}
|
||||
else if(regMatch(x, reg_more))
|
||||
{
|
||||
if(to_int(regReplace(x, reg_more, "$1"), INT_MIN) >= target)
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
std::string nodeRename(std::string remark, int groupID, const string_array &rename_array)
|
||||
{
|
||||
string_array vArray;
|
||||
int targetGroupID = groupID;
|
||||
std::string targetRange;
|
||||
string_size pos;
|
||||
|
||||
for(const std::string &x : rename_array)
|
||||
{
|
||||
targetRange = std::to_string(groupID);
|
||||
vArray = split(x, "@");
|
||||
if(vArray.size() == 1)
|
||||
{
|
||||
@@ -264,13 +311,13 @@ std::string nodeRename(std::string remark, int groupID, const string_array &rena
|
||||
pos = vArray[0].find("!!", vArray[0].find("!!") + 2);
|
||||
if(pos != vArray[0].npos)
|
||||
{
|
||||
targetGroupID = to_int(vArray[0].substr(10, pos - 10), groupID);
|
||||
targetRange = vArray[0].substr(10, pos - 10);
|
||||
vArray[0] = vArray[0].substr(pos + 2);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if(groupID == targetGroupID)
|
||||
if(matchRange(targetRange, groupID))
|
||||
remark = regReplace(remark, vArray[0], vArray[1]);
|
||||
}
|
||||
return remark;
|
||||
@@ -292,11 +339,12 @@ std::string removeEmoji(std::string remark)
|
||||
std::string addEmoji(std::string remark, int groupID, const string_array &emoji_array)
|
||||
{
|
||||
string_array vArray;
|
||||
int targetGroupID = groupID;
|
||||
std::string targetRange;
|
||||
string_size pos;
|
||||
|
||||
for(const std::string &x : emoji_array)
|
||||
{
|
||||
targetRange = std::to_string(groupID);
|
||||
vArray = split(x, ",");
|
||||
if(vArray.size() != 2)
|
||||
continue;
|
||||
@@ -305,13 +353,13 @@ std::string addEmoji(std::string remark, int groupID, const string_array &emoji_
|
||||
pos = vArray[0].find("!!", vArray[0].find("!!") + 2);
|
||||
if(pos != vArray[0].npos)
|
||||
{
|
||||
targetGroupID = to_int(vArray[0].substr(10, pos - 10), groupID);
|
||||
targetRange = vArray[0].substr(10, pos - 10);
|
||||
vArray[0] = vArray[0].substr(pos + 2);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if(groupID == targetGroupID && regFind(remark, vArray[0]))
|
||||
if(matchRange(targetRange, groupID) && regFind(remark, vArray[0]))
|
||||
{
|
||||
remark = vArray[1] + " " + remark;
|
||||
break;
|
||||
@@ -566,7 +614,7 @@ void groupGenerate(std::string &rule, std::vector<nodeInfo> &nodelist, std::vect
|
||||
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(y.groupID == to_int(group) && regFind(y.remarks, rule) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
if(matchRange(group, y.groupID) && regFind(y.remarks, rule) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
@@ -576,7 +624,7 @@ void groupGenerate(std::string &rule, std::vector<nodeInfo> &nodelist, std::vect
|
||||
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(y.groupID == to_int(group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
if(matchRange(group, y.groupID) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
@@ -1763,7 +1811,7 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
|
||||
{
|
||||
std::string groupdata = n.second;
|
||||
std::string::size_type cpos = groupdata.find(",");
|
||||
if(cpos != std::string::npos)
|
||||
if(cpos != groupdata.npos)
|
||||
return trim(groupdata.substr(0, cpos)) == name;
|
||||
else
|
||||
return false;
|
||||
@@ -1838,9 +1886,9 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
|
||||
{
|
||||
pos = content.find(",");
|
||||
url = ext.managed_config_prefix + "/qx-rewrite?id=" + ext.quanx_dev_id + "&url=" + urlsafe_base64_encode(content.substr(0, pos));
|
||||
content = url;
|
||||
if(pos != content.npos)
|
||||
content += content.substr(content.find(","));
|
||||
url += content.substr(pos);
|
||||
content = url;
|
||||
}
|
||||
ini.Set("{NONAME}", content);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user