using System; using System.Collections.Generic; using System.Collections.ObjectModel; using game.Account; namespace game.PlayerDataStorage { public enum PlayerKVLoginPrepareError { None, Validation, Cancelled, Stale, AuthenticationFailed, OwnerRejected, NotReady, Unexpected, CloseFailed } /// /// Historical outcome of one preparation, not permission to initialize gameplay or create a save. /// Check the context's IsCurrent before using a prepared snapshot. Failure/cancellation waits for /// actual transport and Close completion; a transport ignoring cancellation may hold it indefinitely. /// public sealed class PlayerKVLoginPrepareResult { public bool Prepared => Error == PlayerKVLoginPrepareError.None; public PlayerKVLoginPrepareError Error { get; } public PlayerKVLoginPrepareError OriginalError { get; } public bool CleanupFailed => Error == PlayerKVLoginPrepareError.CloseFailed; public AccountLoginError? AccountError { get; } public PlayerKVGameOpenError? OpenError { get; } public PlayerKVSessionOpenError? OwnerError { get; } public PlayerKVError? KVError { get; } public PlayerKVSyncStatus? SyncStatus { get; } public int? HttpStatusCode { get; } public string PlayerId { get; } public long Epoch { get; } public string OwnerInstanceId { get; } public string ExceptionType { get; } public string CleanupExceptionType { get; } public IReadOnlyDictionary Data { get; } public bool IsEmpty => Prepared && Data.Count == 0; internal PlayerKVLoginPrepareResult(PlayerKVLoginPrepareError error, string playerId, long epoch, AccountLoginError? accountError = null, int? httpStatus = null, PlayerKVGameOpenError? openError = null, PlayerKVSessionOpenError? ownerError = null, PlayerKVError? kvError = null, PlayerKVSyncStatus? syncStatus = null, string ownerId = null, IReadOnlyDictionary data = null, string exceptionType = null, string cleanupExceptionType = null, PlayerKVLoginPrepareError? originalError = null) { Error = error; OriginalError = originalError ?? error; PlayerId = playerId; Epoch = epoch; AccountError = accountError; HttpStatusCode = httpStatus; OpenError = openError; OwnerError = ownerError; KVError = kvError; SyncStatus = syncStatus; OwnerInstanceId = ownerId; ExceptionType = exceptionType; CleanupExceptionType = cleanupExceptionType; if (!Prepared) return; if (data == null) throw new ArgumentNullException(nameof(data)); var copy = new Dictionary(StringComparer.Ordinal); foreach (var pair in data) copy.Add(pair.Key, pair.Value); Data = new ReadOnlyDictionary(copy); } } }