mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-05 21:12:07 +03:00
@@ -753,11 +753,11 @@ public class Utils
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetFreePort(int defaultPort = 0)
|
public static int GetFreePort(int defaultPort)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!(defaultPort == 0 || Utils.PortInUse(defaultPort)))
|
if (!PortInUse(defaultPort))
|
||||||
{
|
{
|
||||||
return defaultPort;
|
return defaultPort;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -586,7 +586,6 @@ public static class ConfigHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static async Task<int> AddCustomOutboundServer(Config config, ProfileItem profileItem, bool blDelete, bool toFile = true)
|
public static async Task<int> AddCustomOutboundServer(Config config, ProfileItem profileItem, bool blDelete, bool toFile = true)
|
||||||
{
|
{
|
||||||
var fileName = profileItem.Address;
|
var fileName = profileItem.Address;
|
||||||
@@ -1739,8 +1738,16 @@ public static class ConfigHandler
|
|||||||
SubItem? subItem)
|
SubItem? subItem)
|
||||||
{
|
{
|
||||||
var subRemarks = subItem?.Remarks;
|
var subRemarks = subItem?.Remarks;
|
||||||
// Safe Mode: Only allow full configuration if it's not from a subscription
|
// Prioritize using complete custom parsing, followed by custom outbound parsing.
|
||||||
var lstProfiles = V2rayFmt.ResolveToCustomOutbound(strData, subRemarks);
|
var lstProfiles = V2rayFmt.ResolveToCustom(strData, subRemarks);
|
||||||
|
if (lstProfiles.Count == 0)
|
||||||
|
{
|
||||||
|
lstProfiles = SingboxFmt.ResolveToCustom(strData, subRemarks);
|
||||||
|
}
|
||||||
|
if (lstProfiles.Count == 0)
|
||||||
|
{
|
||||||
|
lstProfiles = V2rayFmt.ResolveToCustomOutbound(strData, subRemarks);
|
||||||
|
}
|
||||||
if (lstProfiles.Count == 0)
|
if (lstProfiles.Count == 0)
|
||||||
{
|
{
|
||||||
lstProfiles = SingboxFmt.ResolveToCustomOutbound(strData, subRemarks);
|
lstProfiles = SingboxFmt.ResolveToCustomOutbound(strData, subRemarks);
|
||||||
@@ -1750,7 +1757,7 @@ public static class ConfigHandler
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = await AddCustomOutboundServers(config, lstProfiles, subid, isSub);
|
var count = await AddBatchCustomServers(config, lstProfiles, subid, isSub);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
return count;
|
return count;
|
||||||
@@ -1786,7 +1793,7 @@ public static class ConfigHandler
|
|||||||
var subRemarks = subItem.Remarks;
|
var subRemarks = subItem.Remarks;
|
||||||
var customCoreType = subItem.CustomCoreType!.Value;
|
var customCoreType = subItem.CustomCoreType!.Value;
|
||||||
|
|
||||||
List<ProfileItem>? lstProfiles = customCoreType switch
|
var lstProfiles = customCoreType switch
|
||||||
{
|
{
|
||||||
ECoreType.Xray => V2rayFmt.ResolveToCustom(strData, subRemarks),
|
ECoreType.Xray => V2rayFmt.ResolveToCustom(strData, subRemarks),
|
||||||
ECoreType.sing_box => SingboxFmt.ResolveToCustom(strData, subRemarks),
|
ECoreType.sing_box => SingboxFmt.ResolveToCustom(strData, subRemarks),
|
||||||
@@ -1800,7 +1807,7 @@ public static class ConfigHandler
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = await AddCustomOutboundServers(config, lstProfiles, subid, isSub);
|
var count = await AddBatchCustomServers(config, lstProfiles, subid, isSub);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
return count;
|
return count;
|
||||||
@@ -1810,7 +1817,7 @@ public static class ConfigHandler
|
|||||||
return await SaveCustomRawFileServer(config, strData, subid, isSub, subItem, customCoreType);
|
return await SaveCustomRawFileServer(config, strData, subid, isSub, subItem, customCoreType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<int> AddCustomOutboundServers(
|
private static async Task<int> AddBatchCustomServers(
|
||||||
Config config,
|
Config config,
|
||||||
List<ProfileItem> lstProfiles,
|
List<ProfileItem> lstProfiles,
|
||||||
string subid,
|
string subid,
|
||||||
@@ -1821,11 +1828,22 @@ public static class ConfigHandler
|
|||||||
{
|
{
|
||||||
it.Subid = subid;
|
it.Subid = subid;
|
||||||
it.IsSub = isSub;
|
it.IsSub = isSub;
|
||||||
|
|
||||||
|
if (it.ConfigType == EConfigType.Custom)
|
||||||
|
{
|
||||||
|
if (await AddCustomServer(config, it, true) == 0)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (await AddCustomOutboundServer(config, it, true) == 0)
|
if (await AddCustomOutboundServer(config, it, true) == 0)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class SingboxFmt : BaseFmt
|
|||||||
var fileName = WriteAllText(JsonUtils.Serialize(jsonObject));
|
var fileName = WriteAllText(JsonUtils.Serialize(jsonObject));
|
||||||
var profileItem = new ProfileItem
|
var profileItem = new ProfileItem
|
||||||
{
|
{
|
||||||
|
ConfigType = EConfigType.Custom,
|
||||||
CoreType = ECoreType.sing_box,
|
CoreType = ECoreType.sing_box,
|
||||||
Address = fileName,
|
Address = fileName,
|
||||||
Remarks = subRemarks ?? "singbox_custom",
|
Remarks = subRemarks ?? "singbox_custom",
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public class V2rayFmt : BaseFmt
|
|||||||
|
|
||||||
var profileItem = new ProfileItem
|
var profileItem = new ProfileItem
|
||||||
{
|
{
|
||||||
|
ConfigType = EConfigType.Custom,
|
||||||
CoreType = ECoreType.Xray,
|
CoreType = ECoreType.Xray,
|
||||||
Address = fileName,
|
Address = fileName,
|
||||||
Remarks = jsonObject["remarks"]?.ToString() ?? subRemarks ?? "v2ray_custom",
|
Remarks = jsonObject["remarks"]?.ToString() ?? subRemarks ?? "v2ray_custom",
|
||||||
|
|||||||
Reference in New Issue
Block a user