zio fork 1.8.2b-zio11: reloading admins removes deleted and demoted admins
Some checks are pending
Build and Publish / build (push) Waiting to run
Build and Publish / publish (push) Blocked by required conditions

CSS's admin loaders only add, and the per-admin cleanup in CreateAdminsJsonFile
reset AdminCache once per admin, so it only ever tracked the last one and a
reload never took anyone else out of memory. ReloadAdmins now removes every
admin it loaded last time and loads the new set in one tick. admins.json is
keyed by SteamID instead of name, so admins sharing a name aren't merged, and a
failed admins query keeps the loaded admins instead of removing them.
This commit is contained in:
Astra 2026-10-02 21:21:09 +01:00
parent f46ccf18ce
commit d042aab1c0
3 changed files with 63 additions and 103 deletions

View file

@ -507,26 +507,31 @@ public partial class CS2_SimpleAdmin
Task.Run(async () =>
{
await PermissionManager.CreateGroupsJsonFile();
await PermissionManager.CreateAdminsJsonFile();
var adminsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/admins.json");
var groupsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/groups.json");
await Server.NextWorldUpdateAsync(() =>
{
AddTimer(1, () =>
{
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(2.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
if (!string.IsNullOrEmpty(groupsFile))
AddTimer(3.0f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(4.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
var admins = await PermissionManager.CreateAdminsJsonFile();
if (admins == null) return;
_logger?.LogInformation("Loaded admins!");
});
await Server.NextWorldUpdateAsync(() =>
{
// zio: CSS's loaders only ever add, so first remove everyone loaded last time (removed or
// demoted admins kept their old rank until a restart otherwise), then load the new set,
// all in one tick so nobody is left without their flags in between. Groups can't be
// removed from CSS, so flags taken off a group still need a restart.
foreach (var steamId in PermissionManager.AdminCache.Keys.ToList())
AdminManager.RemovePlayerAdminData(steamId);
PermissionManager.AdminCache.Clear();
foreach (var admin in admins.GroupBy(a => a.SteamId))
{
var ends = admin.Any(a => a.Ends == null) ? null : admin.Max(a => a.Ends);
PermissionManager.AdminCache[admin.Key] = (ends, admin.SelectMany(a => a.Flags).Distinct().ToList());
}
AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json");
AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json");
_logger?.LogInformation("Loaded {count} admins!", PermissionManager.AdminCache.Count);
});
});
});
//_ = _adminManager.GiveAllGroupsFlags();
//_ = _adminManager.GiveAllFlags();