diff --git a/PlaytimeHistory.cs b/PlaytimeHistory.cs index b4e3df4..e6de1e7 100644 --- a/PlaytimeHistory.cs +++ b/PlaytimeHistory.cs @@ -21,7 +21,7 @@ namespace PlaytimeHistory; public class PlaytimeHistory : BasePlugin, IPluginConfig { public override string ModuleName => "PlaytimeHistory"; - public override string ModuleVersion => "0.1.1"; + public override string ModuleVersion => "0.1.2"; public override string ModuleAuthor => "astra"; public override string ModuleDescription => "Records playtime per session, team and alive/dead state"; @@ -35,6 +35,9 @@ public class PlaytimeHistory : BasePlugin, IPluginConfig private bool _geoBroken; private string _map = ""; + // The hostname last written to pt_servers. The server.cfg that sets it runs after map start, so + // the heartbeat checks again and sends it when it's changed. + private string? _sentHostname; // False between a map's end and the next one's start, when nothing is opened. private bool _mapRunning; @@ -115,7 +118,12 @@ public class PlaytimeHistory : BasePlugin, IPluginConfig ServerSeenNow(); AddTimer(1.0f, Reconcile, TimerFlags.REPEAT); - AddTimer(Config.HeartbeatSeconds, () => _writer.Enqueue(new Heartbeat(Config.ServerId, Now())), TimerFlags.REPEAT); + AddTimer(Config.HeartbeatSeconds, () => + { + _writer.Enqueue(new Heartbeat(Config.ServerId, Now())); + if (_mapRunning) + ServerSeenNow(onlyIfChanged: true); + }, TimerFlags.REPEAT); AddTimer(Config.PingSampleIntervalSeconds, SamplePing, TimerFlags.REPEAT); if (Config.OnlineSnapshotIntervalSeconds > 0) AddTimer(Config.OnlineSnapshotIntervalSeconds, TakeSnapshot, TimerFlags.REPEAT); @@ -178,9 +186,12 @@ public class PlaytimeHistory : BasePlugin, IPluginConfig player is { IsValid: true, IsBot: false, IsHLTV: false } && player.Connected == PlayerConnectedState.Connected && player.SteamID != 0; - private void ServerSeenNow() + private void ServerSeenNow(bool onlyIfChanged = false) { var hostname = ConVar.Find("hostname")?.StringValue ?? ""; + if (onlyIfChanged && hostname == _sentHostname) + return; + _sentHostname = hostname; _writer?.Enqueue(new ServerSeen(Config.ServerId, Config.PublicAddress, hostname, Now())); }