44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using System;
|
|
using System.Globalization;
|
|
|
|
namespace game.PlayerDataStorage
|
|
{
|
|
/// <summary>
|
|
/// Immutable process-start selection. Accounts 101 and 102 are the reviewed first cohort;
|
|
/// expanding it requires a new complete migration design review.
|
|
/// </summary>
|
|
internal sealed class PlayerKVRuntimeSelection
|
|
{
|
|
internal const string FormalApiUrl = "http://s101.local:18080/";
|
|
|
|
internal bool IsKV { get; }
|
|
internal Uri Api { get; }
|
|
|
|
private PlayerKVRuntimeSelection(bool isKV, Uri api)
|
|
{
|
|
IsKV = isKV;
|
|
Api = api;
|
|
}
|
|
|
|
internal static PlayerKVRuntimeSelection Capture(string backend, string api, bool agg)
|
|
{
|
|
if (backend == null || backend == "playfab")
|
|
return new PlayerKVRuntimeSelection(false, null);
|
|
if (backend != "kv")
|
|
throw new ArgumentException("Unsupported save backend.", nameof(backend));
|
|
if (!string.Equals(api, FormalApiUrl, StringComparison.Ordinal))
|
|
throw new ArgumentException("KV API address does not match the reviewed endpoint.", nameof(api));
|
|
return new PlayerKVRuntimeSelection(true, new Uri(FormalApiUrl));
|
|
}
|
|
|
|
internal bool TryAdmitPlayer(string requestedId, out string canonicalId)
|
|
{
|
|
canonicalId = null;
|
|
if (!IsKV || !long.TryParse(requestedId, NumberStyles.None, CultureInfo.InvariantCulture, out var id) ||
|
|
(id != 101 && id != 102)) return false;
|
|
canonicalId = id.ToString(CultureInfo.InvariantCulture);
|
|
return true;
|
|
}
|
|
}
|
|
}
|