test(upserver): 归档存档迁移与玩法闭环回归工具
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
// Read existing accounts only. No account creation, PF UpdateUserData, or KV mutation entry exists.
|
||||
static class PFSourceBackup
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
const string title="108EE8";
|
||||
const string localConfig="C:/Users/LB/AppData/LocalLow/Ark Game Limited (香港)/Fishing Travel/debugconfig.json";
|
||||
using var configured=JsonDocument.Parse(File.ReadAllText(localConfig));
|
||||
if(configured.RootElement.GetProperty("PlayFabTitle").GetString()!=title) throw new InvalidOperationException("Reviewed PF title changed.");
|
||||
var folder=Path.GetFullPath("CodexOutput/upserver/KVGameplayLoopTests/pf-source-backups/"+DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ"));
|
||||
Directory.CreateDirectory(folder);
|
||||
using var http=new HttpClient(new HttpClientHandler{AllowAutoRedirect=false}){Timeout=TimeSpan.FromSeconds(25)};
|
||||
foreach(var id in new[]{"101","102"})
|
||||
{
|
||||
var body=JsonSerializer.Serialize(new{TitleId=title,CustomId=id,CreateAccount=false,InfoRequestParameters=new{GetUserData=true}});
|
||||
using var response=await http.PostAsync("https://108EE8.playfabapi.com/Client/LoginWithCustomID",new StringContent(body,Encoding.UTF8,"application/json"));
|
||||
using var result=JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
if(!response.IsSuccessStatusCode || !result.RootElement.TryGetProperty("data",out var login))
|
||||
{
|
||||
var reason=result.RootElement.TryGetProperty("error",out var error)?error.GetString():"protocol";
|
||||
Console.WriteLine(JsonSerializer.Serialize(new{customId=id,titleId=title,success=false,http=(int)response.StatusCode,error=reason}));
|
||||
continue;
|
||||
}
|
||||
if(login.GetProperty("NewlyCreated").GetBoolean()) throw new InvalidOperationException("Unexpected account creation.");
|
||||
var data=login.GetProperty("InfoResultPayload").GetProperty("UserData").EnumerateObject()
|
||||
.ToDictionary(p=>p.Name,p=>p.Value.GetProperty("Value").GetString(),StringComparer.Ordinal);
|
||||
var bytes=Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new{source="PlayFab",titleId=title,customId=id,
|
||||
playFabId=login.GetProperty("PlayFabId").GetString(),at=DateTime.UtcNow,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{customId=id,titleId=title,success=true,path,sha256=Convert.ToHexString(SHA256.HashData(bytes)),
|
||||
count=data.Count,keys=data.Keys.OrderBy(k=>k).ToArray(),hasMainSave=data.ContainsKey("NewPlayerDataDic"),pfWrites=0,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