Skip to content

Commit

Permalink
Hotfix - server loading
Browse files Browse the repository at this point in the history
- Fix for server loading
  • Loading branch information
daffyyyy committed Nov 22, 2024
1 parent b2ebe13 commit 2defb2f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CS2-SimpleAdmin/CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override void Load(bool hotReload)
if (hotReload)
{
ServerLoaded = false;
_serverLoading = false;
OnGameServerSteamAPIActivated();
OnMapStart(string.Empty);

Expand Down
16 changes: 11 additions & 5 deletions CS2-SimpleAdmin/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace CS2_SimpleAdmin;

public partial class CS2_SimpleAdmin
{
private bool _serverLoading;

private void RegisterEvents()
{
RegisterListener<Listeners.OnMapStart>(OnMapStart);
Expand Down Expand Up @@ -49,6 +51,10 @@ private void RegisterEvents()

private void OnGameServerSteamAPIActivated()
{
if (_serverLoading)
return;

_serverLoading = true;
new ServerManager().LoadServerData();
}

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion CS2-SimpleAdmin/Managers/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +39,8 @@ public void LoadServerData()
var address = $"{ipAddress}:{ConVar.Find("hostport")?.GetPrimitiveValue<int>()}";
var hostname = ConVar.Find("hostname")!.StringValue;
CS2_SimpleAdmin.IpAddress = address;

CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress);

Task.Run(async () =>
{
Expand Down

0 comments on commit 2defb2f

Please sign in to comment.