test(upserver): 归档存档迁移与玩法闭环回归工具
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using game.Account;
|
||||
using game.PlayerDataStorage;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
if(args.Length==1 && args[0]=="--verify-import-101") { await Import101Tests.Run(); return; }
|
||||
if(args.Length==1 && args[0]=="--import-approved-101") { await Import101.Run(); return; }
|
||||
if(args.Length==1 && args[0]=="--verify-advert") { AdvertCompatibilityTests.Run(); return; }
|
||||
if(args.Length==1 && args[0]=="--import-approved-102") { await Import102.Run(); return; }
|
||||
if(args.Length==1 && args[0]=="--backup-pf-101-102") { await PFSourceBackup.Run(); return; }
|
||||
if(args.Length!=1 || args[0]!="--backup-101-102") throw new ArgumentException("Explicit backup command required.");
|
||||
const string api="http://s101.local:18080/";
|
||||
var folder=Path.GetFullPath("CodexOutput/upserver/KVGameplayLoopTests/backups/"+DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ"));
|
||||
Directory.CreateDirectory(folder);
|
||||
foreach(var id in new[]{"101","102"})
|
||||
{
|
||||
using var session=new S101AccountSession(new Uri(api));
|
||||
var login=await session.LoginAsync(id);
|
||||
if(!login.Success || session.NewlyCreated || session.PlayerId!=id) throw new InvalidOperationException("Existing account login failed: "+id+" "+login.Error);
|
||||
using var http=new HttpClient(new HttpClientHandler{CookieContainer=session.Cookies,UseCookies=true,AllowAutoRedirect=false}){Timeout=TimeSpan.FromSeconds(20)};
|
||||
var kv=new PlayerKVClient(http,session.ApiBaseUri);
|
||||
var read=await kv.GetAsync(null);
|
||||
if(!read.Success) throw new InvalidOperationException("Read failed: "+id+" "+read.Error);
|
||||
var bytes=Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new{playerId=id,api,at=DateTime.UtcNow,data=read.Data},new JsonSerializerOptions{WriteIndented=true}));
|
||||
var path=Path.Combine(folder,id+".json");
|
||||
using(var stream=new FileStream(path,FileMode.CreateNew,FileAccess.Write,FileShare.Read)) { stream.Write(bytes); stream.Flush(true); }
|
||||
var summary=new{playerId=id,path,sha256=Convert.ToHexString(SHA256.HashData(bytes)),count=read.Data.Count,keys=read.Data.Keys.OrderBy(k=>k).ToArray(),hasMainSave=read.Data.ContainsKey("NewPlayerDataDic"),kvWrites=0};
|
||||
File.WriteAllText(Path.Combine(folder,id+"-summary.json"),JsonSerializer.Serialize(summary,new JsonSerializerOptions{WriteIndented=true}));
|
||||
Console.WriteLine(JsonSerializer.Serialize(summary));
|
||||
}
|
||||
Reference in New Issue
Block a user