58 lines
2.9 KiB
C#
58 lines
2.9 KiB
C#
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
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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<string, string> 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<string, string> 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<string, string>(StringComparer.Ordinal);
|
|
foreach (var pair in data) copy.Add(pair.Key, pair.Value);
|
|
Data = new ReadOnlyDictionary<string, string>(copy);
|
|
}
|
|
}
|
|
}
|