mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-16 12:35:46 +00:00
Fix hosts resolve rule
This commit is contained in:
parent
dd801a3e55
commit
54c525fbf2
1 changed files with 50 additions and 3 deletions
|
|
@ -84,11 +84,58 @@ public partial class CoreConfigSingboxService
|
|||
}
|
||||
if (hostsDomains.Count > 0)
|
||||
{
|
||||
_coreConfig.route.rules.Add(new()
|
||||
var hostsResolveRule = new Rule4Sbox
|
||||
{
|
||||
action = "resolve",
|
||||
domain = hostsDomains,
|
||||
});
|
||||
};
|
||||
var hostsCounter = 0;
|
||||
foreach (var host in hostsDomains)
|
||||
{
|
||||
var domainRule = new Rule4Sbox();
|
||||
if (!ParseV2Domain(host, domainRule))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (domainRule.domain_keyword?.Count > 0 && !host.StartsWith("keyword:"))
|
||||
{
|
||||
domainRule.domain = domainRule.domain_keyword;
|
||||
domainRule.domain_keyword = null;
|
||||
}
|
||||
if (domainRule.domain?.Count > 0)
|
||||
{
|
||||
hostsResolveRule.domain ??= [];
|
||||
hostsResolveRule.domain.AddRange(domainRule.domain);
|
||||
hostsCounter++;
|
||||
}
|
||||
else if (domainRule.domain_keyword?.Count > 0)
|
||||
{
|
||||
hostsResolveRule.domain_keyword ??= [];
|
||||
hostsResolveRule.domain_keyword.AddRange(domainRule.domain_keyword);
|
||||
hostsCounter++;
|
||||
}
|
||||
else if (domainRule.domain_suffix?.Count > 0)
|
||||
{
|
||||
hostsResolveRule.domain_suffix ??= [];
|
||||
hostsResolveRule.domain_suffix.AddRange(domainRule.domain_suffix);
|
||||
hostsCounter++;
|
||||
}
|
||||
else if (domainRule.domain_regex?.Count > 0)
|
||||
{
|
||||
hostsResolveRule.domain_regex ??= [];
|
||||
hostsResolveRule.domain_regex.AddRange(domainRule.domain_regex);
|
||||
hostsCounter++;
|
||||
}
|
||||
else if (domainRule.geosite?.Count > 0)
|
||||
{
|
||||
hostsResolveRule.geosite ??= [];
|
||||
hostsResolveRule.geosite.AddRange(domainRule.geosite);
|
||||
hostsCounter++;
|
||||
}
|
||||
}
|
||||
if (hostsCounter > 0)
|
||||
{
|
||||
_coreConfig.route.rules.Add(hostsResolveRule);
|
||||
}
|
||||
}
|
||||
|
||||
_coreConfig.route.rules.Add(new()
|
||||
|
|
|
|||
Loading…
Reference in a new issue