Skip to content

Commit fe73fa9

Browse files
committed
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.
1 parent bdada2d commit fe73fa9

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

CS2-SimpleAdmin/CS2-SimpleAdmin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
2222
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
2323
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
2424
public override string ModuleAuthor => "daffyy";
25-
public override string ModuleVersion => "1.7.8-beta-9";
25+
public override string ModuleVersion => "1.7.8-beta-10";
2626

2727
public override void Load(bool hotReload)
2828
{
@@ -83,9 +83,9 @@ public override void OnAllPluginsLoaded(bool hotReload)
8383
Unload(false);
8484
}
8585

86-
AddTimer(6.0f, () => ReloadAdmins(null));
8786
RegisterEvents();
8887
AddTimer(0.5f, RegisterCommands.InitializeCommands);
88+
AddTimer(1.0f, () => ReloadAdmins(null));
8989

9090
if (!CoreConfig.UnlockConCommands)
9191
{

CS2-SimpleAdmin/Commands/basecommands.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ await Server.NextWorldUpdateAsync(() =>
512512
AddTimer(1, () =>
513513
{
514514
if (!string.IsNullOrEmpty(adminsFile))
515-
AddTimer(2.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
515+
AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json");
516516
if (!string.IsNullOrEmpty(groupsFile))
517-
AddTimer(3.0f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
517+
AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json");
518518
if (!string.IsNullOrEmpty(adminsFile))
519-
AddTimer(4.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
519+
AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json");
520520

521521
_logger?.LogInformation("Loaded admins!");
522522
});

CS2-SimpleAdmin/Events.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info
448448

449449
private void OnMapStart(string mapName)
450450
{
451-
if (!ServerLoaded || ServerId == null)
452-
AddTimer(2.0f, OnGameServerSteamAPIActivated);
453-
454451
if (Config.OtherSettings.ReloadAdminsEveryMapChange && ServerLoaded && ServerId != null)
455-
AddTimer(5.0f, () => ReloadAdmins(null));
452+
ReloadAdmins(null);
456453

457454
AddTimer(1.0f, ServerManager.CheckHibernationStatus);
455+
456+
if (!ServerLoaded || ServerId == null)
457+
AddTimer(1.5f, OnGameServerSteamAPIActivated);
458458

459459
// AddTimer(34, () =>
460460
// {

CS2-SimpleAdmin/Managers/ServerManager.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void CheckHibernationStatus()
3131
/// </summary>
3232
public void LoadServerData()
3333
{
34-
CS2_SimpleAdmin.Instance.AddTimer(2.0f, () =>
34+
CS2_SimpleAdmin.Instance.AddTimer(1.0f, () =>
3535
{
3636
if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.DatabaseProvider == null) return;
3737

@@ -103,14 +103,12 @@ await connection.ExecuteAsync(
103103
CS2_SimpleAdmin.ServerId = serverId;
104104
CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress);
105105

106-
if (CS2_SimpleAdmin.ServerId != null)
106+
if (CS2_SimpleAdmin.Instance.CacheManager != null)
107107
{
108-
await Server.NextWorldUpdateAsync(() => CS2_SimpleAdmin.Instance.ReloadAdmins(null));
108+
await CS2_SimpleAdmin.Instance.CacheManager.InitializeCacheAsync();
109109
}
110-
110+
111111
CS2_SimpleAdmin.ServerLoaded = true;
112-
if (CS2_SimpleAdmin.Instance.CacheManager != null)
113-
await CS2_SimpleAdmin.Instance.CacheManager.InitializeCacheAsync();
114112
}
115113
catch (Exception ex)
116114
{

CS2-SimpleAdmin/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.8-beta-9
1+
1.7.8-beta-10

0 commit comments

Comments
 (0)