chore(m2): 保存功能验收及后续清理前检查点

This commit is contained in:
Liubing\LB
2026-10-10 20:40:27 +08:00
parent d3c5394a55
commit 144e7f739f
110 changed files with 12672 additions and 7514 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading;
@@ -87,8 +88,13 @@ namespace game.PlayerDataStorage
public PlayerKVGameSessionBridge() : this(jar => new HttpClientHandler
{ CookieContainer = jar, UseCookies = true, AllowAutoRedirect = false }) { }
internal PlayerKVGameSessionBridge(Func<CookieContainer, HttpMessageHandler> handlerFactory)
{ this.handlerFactory = handlerFactory ?? throw new ArgumentNullException(nameof(handlerFactory)); }
private readonly bool prepareOriginalComparison;
internal PlayerKVGameSessionBridge(Func<CookieContainer, HttpMessageHandler> handlerFactory, bool prepareOriginalComparison = false)
{
this.handlerFactory = handlerFactory ?? throw new ArgumentNullException(nameof(handlerFactory));
this.prepareOriginalComparison = prepareOriginalComparison;
}
public Task<PlayerKVGameOpenResult> OpenAsync(S101AccountSession session, string cacheRoot,
string playerId, Uri api, long epoch, Func<long, bool> isCurrent, CancellationToken lifetimeToken = default)
@@ -145,7 +151,7 @@ namespace game.PlayerDataStorage
active = slot;
}
slot.Creation = PlayerKVSessionOwner.CreateAsync(session, cacheRoot, playerId, api,
epoch, slot.IsCurrent, slot.Lifetime.Token, handlerFactory);
epoch, slot.IsCurrent, slot.Lifetime.Token, handlerFactory, prepareOriginalComparison: prepareOriginalComparison);
var opened = await slot.Creation.ConfigureAwait(false);
if (!opened.Success)
{
@@ -261,9 +267,49 @@ namespace game.PlayerDataStorage
? new PlayerKVLocalReadResult(PlayerKVLocalReadError.StaleOrClosing, OwnerInstanceId, PlayerId, Epoch)
: Owner.ReadLocalSnapshot();
public PlayerKVEditResult Update(string key, string value, bool remoteStore = true) =>
slot.Revoked ? BlockedEdit() : Owner.Update(key, value, remoteStore);
public PlayerKVEditResult Update(string key, string value, bool remoteStore = true)
{
return Update(key, value, remoteStore, null);
}
internal PlayerKVStateResult CompareDatas(long nowTicks)
{
return slot.Revoked ? new PlayerKVStateResult(PlayerKVChangeError.Blocked) : Owner.CompareDatas(nowTicks);
}
internal PlayerKVEditResult Update(string key, string value, bool remoteStore, long? updateTicks)
{
return slot.Revoked ? BlockedEdit() : Owner.Update(key, value, remoteStore, updateTicks);
}
internal Task<PlayerKVFlushResult> SyncDataAsync(CancellationToken waitToken = default)
{
if (slot.Revoked)
{
return Task.FromResult(new PlayerKVFlushResult(0, 0, 1, 0, PlayerKVError.Cancelled, Owner.Status));
}
return Owner.SyncDataAsync(waitToken);
}
public PlayerKVEditResult Delete(string key) => slot.Revoked ? BlockedEdit() : Owner.Delete(key);
public Task<bool> SyncDataImmidiate(string key, string value)
{
if (slot.Revoked)
{
return Task.FromResult(false);
}
return Owner.SyncDataImmidiate(key, value);
}
internal Task<bool> SyncDataImmidiate(IReadOnlyDictionary<string, string> values)
{
if (slot.Revoked)
{
return Task.FromResult(false);
}
return Owner.SyncDataImmidiate(values);
}
public Task<PlayerKVFlushResult> FlushAsync(CancellationToken waitToken = default) => slot.Revoked
? Task.FromResult(new PlayerKVFlushResult(0, 0, 1, 0, PlayerKVError.Cancelled, Owner.Status))
: Owner.FlushAsync(waitToken);
@@ -273,4 +319,4 @@ namespace game.PlayerDataStorage
static PlayerKVEditResult BlockedEdit() =>
new PlayerKVEditResult(new PlayerKVStateResult(PlayerKVChangeError.Blocked));
}
}
}