From 2defb2fe1495f4d6e2c582d7802a0d2266f34492 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Fri, 22 Nov 2024 23:01:31 +0100 Subject: [PATCH] Hotfix - server loading - Fix for server loading --- CS2-SimpleAdmin/CS2-SimpleAdmin.cs | 1 + CS2-SimpleAdmin/Events.cs | 16 +++++++++++----- CS2-SimpleAdmin/Managers/ServerManager.cs | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs index 5a6454c..d03c406 100644 --- a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs @@ -30,6 +30,7 @@ public override void Load(bool hotReload) if (hotReload) { ServerLoaded = false; + _serverLoading = false; OnGameServerSteamAPIActivated(); OnMapStart(string.Empty); diff --git a/CS2-SimpleAdmin/Events.cs b/CS2-SimpleAdmin/Events.cs index 3418bb9..911d1a1 100644 --- a/CS2-SimpleAdmin/Events.cs +++ b/CS2-SimpleAdmin/Events.cs @@ -17,6 +17,8 @@ namespace CS2_SimpleAdmin; public partial class CS2_SimpleAdmin { + private bool _serverLoading; + private void RegisterEvents() { RegisterListener(OnMapStart); @@ -49,6 +51,10 @@ private void RegisterEvents() private void OnGameServerSteamAPIActivated() { + if (_serverLoading) + return; + + _serverLoading = true; new ServerManager().LoadServerData(); } @@ -330,11 +336,11 @@ private void OnMapStart(string mapName) if (Config.OtherSettings.ReloadAdminsEveryMapChange && ServerLoaded && ServerId != null) AddTimer(3.0f, () => ReloadAdmins(null)); - AddTimer(34, () => - { - if (!ServerLoaded) - OnGameServerSteamAPIActivated(); - }); + // AddTimer(34, () => + // { + // if (!ServerLoaded) + // OnGameServerSteamAPIActivated(); + // }); GodPlayers.Clear(); SilentPlayers.Clear(); diff --git a/CS2-SimpleAdmin/Managers/ServerManager.cs b/CS2-SimpleAdmin/Managers/ServerManager.cs index 012329e..47014d9 100644 --- a/CS2-SimpleAdmin/Managers/ServerManager.cs +++ b/CS2-SimpleAdmin/Managers/ServerManager.cs @@ -15,7 +15,7 @@ public void LoadServerData() { if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.ServerId != null || CS2_SimpleAdmin.Database == null) return; - if (_getIpTryCount > 16) + if (_getIpTryCount > 16 && Helper.GetServerIp().StartsWith("0.0.0.0") || string.IsNullOrEmpty(Helper.GetServerIp())) { CS2_SimpleAdmin._logger?.LogError("Unable to load server data - can't fetch ip address!"); return; @@ -39,6 +39,8 @@ public void LoadServerData() var address = $"{ipAddress}:{ConVar.Find("hostport")?.GetPrimitiveValue()}"; var hostname = ConVar.Find("hostname")!.StringValue; CS2_SimpleAdmin.IpAddress = address; + + CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress); Task.Run(async () => {