refactor(kv): 整理存档接线并清理迁移冗余实现

This commit is contained in:
Liubing\LB
2026-10-13 20:38:41 +08:00
parent 144e7f739f
commit edb8a056c7
166 changed files with 3828 additions and 13267 deletions

View File

@@ -0,0 +1,67 @@
using System;
using System.Globalization;
namespace game.KV
{
/// <summary>
/// Immutable process-start selection with canonical positive numeric player identities.
/// </summary>
internal sealed class KvRuntimeSelection
{
internal bool IsKV
{
get;
}
internal Uri Api
{
get;
}
private KvRuntimeSelection(bool isKV, Uri api)
{
IsKV = isKV;
Api = api;
}
internal static string CompiledBackend
{
get
{
#if USE_KV
return "kv";
#else
return "playfab";
#endif
}
}
internal static KvRuntimeSelection CaptureForBuild(string api)
{
var backend = CompiledBackend;
if (backend == "playfab")
{
return new KvRuntimeSelection(false, null);
}
if (!Uri.TryCreate(api, UriKind.Absolute, out var address) ||
(address.Scheme != "http" && address.Scheme != "https") ||
!string.IsNullOrEmpty(address.UserInfo) || !string.IsNullOrEmpty(address.Query) ||
!string.IsNullOrEmpty(address.Fragment))
{
throw new ArgumentException("KV API address is invalid.", nameof(api));
}
return new KvRuntimeSelection(true, new Uri(address.AbsoluteUri.TrimEnd('/') + "/"));
}
internal bool TryAdmitPlayer(string requestedId, out string canonicalId)
{
canonicalId = null;
if (!IsKV || !long.TryParse(requestedId, NumberStyles.None, CultureInfo.InvariantCulture, out var id) ||
id <= 0)
{
return false;
}
canonicalId = id.ToString(CultureInfo.InvariantCulture);
return true;
}
}
}