From fe73fa9917c8c8983f357dd551c27192518ead11 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 26 Jan 2026 01:19:25 +0100 Subject: [PATCH] Refactor admin and server loading timing logic Adjusted timers for admin and server data loading to improve reliability and reduce delays. Admin data is now loaded more promptly on map changes and during command execution. ServerManager now initializes the cache after setting the server ID, and redundant admin reloads have been removed. Version bumped to 1.7.8-beta-10. --- CS2-SimpleAdmin/CS2-SimpleAdmin.cs | 4 ++-- CS2-SimpleAdmin/Commands/basecommands.cs | 6 +++--- CS2-SimpleAdmin/Events.cs | 8 ++++---- CS2-SimpleAdmin/Managers/ServerManager.cs | 12 +++++------- CS2-SimpleAdmin/VERSION | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs index 7263ea5..c214cd4 100644 --- a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs @@ -22,7 +22,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)"); public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy"; - public override string ModuleVersion => "1.7.8-beta-9"; + public override string ModuleVersion => "1.7.8-beta-10"; public override void Load(bool hotReload) { @@ -83,9 +83,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig ReloadAdmins(null)); RegisterEvents(); AddTimer(0.5f, RegisterCommands.InitializeCommands); + AddTimer(1.0f, () => ReloadAdmins(null)); if (!CoreConfig.UnlockConCommands) { diff --git a/CS2-SimpleAdmin/Commands/basecommands.cs b/CS2-SimpleAdmin/Commands/basecommands.cs index 8d95c33..f8fd417 100644 --- a/CS2-SimpleAdmin/Commands/basecommands.cs +++ b/CS2-SimpleAdmin/Commands/basecommands.cs @@ -512,11 +512,11 @@ public partial class CS2_SimpleAdmin AddTimer(1, () => { if (!string.IsNullOrEmpty(adminsFile)) - AddTimer(2.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json")); + AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"); if (!string.IsNullOrEmpty(groupsFile)) - AddTimer(3.0f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json")); + AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"); if (!string.IsNullOrEmpty(adminsFile)) - AddTimer(4.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json")); + AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"); _logger?.LogInformation("Loaded admins!"); }); diff --git a/CS2-SimpleAdmin/Events.cs b/CS2-SimpleAdmin/Events.cs index cf93e07..d9f8772 100644 --- a/CS2-SimpleAdmin/Events.cs +++ b/CS2-SimpleAdmin/Events.cs @@ -448,13 +448,13 @@ public partial class CS2_SimpleAdmin private void OnMapStart(string mapName) { - if (!ServerLoaded || ServerId == null) - AddTimer(2.0f, OnGameServerSteamAPIActivated); - if (Config.OtherSettings.ReloadAdminsEveryMapChange && ServerLoaded && ServerId != null) - AddTimer(5.0f, () => ReloadAdmins(null)); + ReloadAdmins(null); AddTimer(1.0f, ServerManager.CheckHibernationStatus); + + if (!ServerLoaded || ServerId == null) + AddTimer(1.5f, OnGameServerSteamAPIActivated); // AddTimer(34, () => // { diff --git a/CS2-SimpleAdmin/Managers/ServerManager.cs b/CS2-SimpleAdmin/Managers/ServerManager.cs index e2401bc..274f26d 100644 --- a/CS2-SimpleAdmin/Managers/ServerManager.cs +++ b/CS2-SimpleAdmin/Managers/ServerManager.cs @@ -31,7 +31,7 @@ public class ServerManager /// public void LoadServerData() { - CS2_SimpleAdmin.Instance.AddTimer(2.0f, () => + CS2_SimpleAdmin.Instance.AddTimer(1.0f, () => { if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.DatabaseProvider == null) return; @@ -103,14 +103,12 @@ public class ServerManager CS2_SimpleAdmin.ServerId = serverId; CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress); - if (CS2_SimpleAdmin.ServerId != null) - { - await Server.NextWorldUpdateAsync(() => CS2_SimpleAdmin.Instance.ReloadAdmins(null)); - } - - CS2_SimpleAdmin.ServerLoaded = true; if (CS2_SimpleAdmin.Instance.CacheManager != null) + { await CS2_SimpleAdmin.Instance.CacheManager.InitializeCacheAsync(); + } + + CS2_SimpleAdmin.ServerLoaded = true; } catch (Exception ex) { diff --git a/CS2-SimpleAdmin/VERSION b/CS2-SimpleAdmin/VERSION index 835278e..8e849b7 100644 --- a/CS2-SimpleAdmin/VERSION +++ b/CS2-SimpleAdmin/VERSION @@ -1 +1 @@ -1.7.8-beta-9 \ No newline at end of file +1.7.8-beta-10 \ No newline at end of file