Publish Zonghengjia Windows 0.4.0 client source
This commit is contained in:
@@ -5,20 +5,26 @@ internal sealed record ConnectionSelection(string NodeSlug, bool Manual)
|
||||
{
|
||||
internal static ConnectionSelection Create(bool manual, string? selectedSlug, IEnumerable<string> authorizedSlugs)
|
||||
{
|
||||
if (!manual) return new("auto", false);
|
||||
if (!manual)
|
||||
{
|
||||
if (!authorizedSlugs.Contains(SingleNodeClientPolicy.FixedNodeSlug, StringComparer.Ordinal))
|
||||
throw new InvalidOperationException("默认线路暂不可用,请联系管理员。");
|
||||
return new(SingleNodeClientPolicy.FixedNodeSlug, false);
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(selectedSlug) || selectedSlug == "auto"
|
||||
|| !authorizedSlugs.Contains(selectedSlug, StringComparer.Ordinal))
|
||||
throw new InvalidOperationException("请选择当前账号有权使用的节点;节点可能已下线或授权已变更。");
|
||||
throw new InvalidOperationException("当前账号的默认线路授权不可用。");
|
||||
return new(selectedSlug, true);
|
||||
}
|
||||
|
||||
internal int Attempts(int availableCount) => Manual ? 1 : Math.Clamp(availableCount, 0, 3);
|
||||
internal int Attempts(int availableCount) => NodeSlug == SingleNodeClientPolicy.FixedNodeSlug ? 1
|
||||
: Manual ? 1 : Math.Clamp(availableCount, 0, 3);
|
||||
|
||||
internal void ValidateResponse(string actualSlug)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(actualSlug) || actualSlug == "auto"
|
||||
|| (Manual && !string.Equals(NodeSlug, actualSlug, StringComparison.Ordinal)))
|
||||
throw new InvalidOperationException("服务器返回的节点与连接选择不一致,已拒绝连接。");
|
||||
|| !string.Equals(NodeSlug, actualSlug, StringComparison.Ordinal))
|
||||
throw new InvalidOperationException("平台返回的默认线路与请求不一致,已拒绝连接。");
|
||||
}
|
||||
|
||||
internal void ValidateConfig(ConnectionAttempt attempt, ConfigResponse response, string routeMode,
|
||||
@@ -27,11 +33,11 @@ internal sealed record ConnectionSelection(string NodeSlug, bool Manual)
|
||||
var slug = response.Node.Slug;
|
||||
ValidateResponse(slug);
|
||||
if ((attempt.Slug != "auto" && slug != attempt.Slug) || response.RouteMode != routeMode)
|
||||
throw new InvalidOperationException("服务器返回的节点或代理模式与请求不一致,已拒绝连接。");
|
||||
throw new InvalidOperationException("平台返回的默认线路或代理模式与请求不一致,已拒绝连接。");
|
||||
if (!attempt.IsPrivate && (response.ConnectionScope is not ("" or "public")
|
||||
|| !authorizedNodes.Any(n => n is not PrivateAuxiliaryNode && n.Slug == slug)))
|
||||
throw new InvalidOperationException("公共配置的节点不属于当前账号的授权范围,已拒绝连接。");
|
||||
throw new InvalidOperationException("默认公网线路不属于当前账号授权,已拒绝连接。");
|
||||
if (attempt.Slug == "auto" && excludedNodes.ContainsKey(slug))
|
||||
throw new InvalidOperationException("后台返回了本次连接已排除的节点,未再次尝试。");
|
||||
throw new InvalidOperationException("平台返回的线路已被本次连接排除,未再次尝试。");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user