using XFEWarframe.Desktop.Editing; using CommunityToolkit.Mvvm.ComponentModel; using Newtonsoft.Json.Linq; namespace XFEWarframe.Admin.Models; public partial class AdminState : ObservableObject { // Keep the chosen player while navigating inventory categories; never persist across servers. public string? SelectedAccountId { get; set; } partial void OnAddressChanged(string value) => SelectedAccountId = null; [ObservableProperty] public partial string Address { get; set; } = "http://127.0.0.1:8444"; // Management credentials remain in memory; they are never written to desktop profiles. [ObservableProperty] public partial string Token { get; set; } = ""; [ObservableProperty] public partial string Status { get; set; } = UiText.Translate("尚未连接服务器"); [ObservableProperty] public partial string LastRefresh { get; set; } = UiText.Translate("等待同步"); [ObservableProperty] public partial string Players { get; set; } = "—"; [ObservableProperty] public partial string Online { get; set; } = "—"; [ObservableProperty] public partial string Requests { get; set; } = "—"; [ObservableProperty] public partial string Uptime { get; set; } = "—"; [ObservableProperty] public partial string RouteSummary { get; set; } = UiText.Translate("等待读取 API 清单"); [ObservableProperty] public partial string Revision { get; set; } = ""; [ObservableProperty] public partial string MaintenanceAction { get; set; } = UiText.Translate("进入维护模式"); [ObservableProperty] public partial bool IsMaintenance { get; set; } [ObservableProperty] public partial bool Connected { get; set; } public void Apply(JObject snapshot) { if (snapshot.Value("apiVersion") < 2) throw new InvalidOperationException(UiText.Translate("服务器版本过旧。请启动同一发行包中的新版 Server,再重新连接。")); Connected = true; IsMaintenance = snapshot.Value("status") == "maintenance"; Status = IsMaintenance ? UiText.Translate("服务维护中") : UiText.Translate("服务器已连接"); MaintenanceAction = IsMaintenance ? UiText.Translate("恢复游戏 API") : UiText.Translate("进入维护模式"); LastRefresh = $"上次更新 {DateTime.Now:HH:mm:ss}"; Players = snapshot.Value("players").ToString("N0"); Online = snapshot.Value("online").ToString("N0"); Requests = snapshot.Value("totalRequests").ToString("N0"); var uptime = TimeSpan.FromSeconds(snapshot.Value("uptimeSeconds")); Uptime = $"{(int)uptime.TotalHours:00}:{uptime.Minutes:00}:{uptime.Seconds:00}"; Revision = UiText.Format("数据修订 {0} · 失败请求 {1}", snapshot.Value("revision"), snapshot.Value("failedRequests")); var routes = snapshot["routes"]!; RouteSummary = UiText.Format("{0} 条已核对 · {1} 条待完整核验 · {2} 条待接入 / 共 {3} 条", routes.Value("ported"), routes.Value("partial"), routes.Value("pending"), routes.Value("total")); } } public sealed record AccountRow(string Id, string Name, string Email, bool Banned, bool Online, int Level, long Credits, bool SkipTutorial = false) { public string Status => Banned ? UiText.Translate("已禁用") : Online ? UiText.Translate("在线") : UiText.Translate("离线"); public string Details => $"段位 {Level} · 星币 {Credits:N0} · {Status}"; public string ProgressDetails => $"段位 {Level} · 星币 {Credits:N0}"; public string BanAction => Banned ? UiText.Translate("启用账户") : UiText.Translate("禁用账户"); public string Label => $"{Name} · {Email}"; public static AccountRow FromJson(JToken value) => new(value.Value("id")!, value.Value("DisplayName") ?? "", value.Value("email") ?? "", value.Value("Banned"), value.Value("Online"), value.Value("PlayerLevel"), value.Value("RegularCredits"), value.Value("SkipTutorial")); } public sealed record CatalogRow(string Name, string Type, string Category, string Tags = ""); public sealed record RouteRow(string Method, string Path, string Status, string Controller); public sealed record LogRow(string Time, int Status, string Method, string Path, string Duration); public sealed record NewAccount(string DisplayName, string Email, string Password); public sealed record ItemGrant(string AccountId, int Count);