0.1.2: update the hostname once server.cfg has set it
This commit is contained in:
parent
d89a078835
commit
d06e240417
1 changed files with 14 additions and 3 deletions
|
|
@ -21,7 +21,7 @@ namespace PlaytimeHistory;
|
||||||
public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "PlaytimeHistory";
|
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 ModuleAuthor => "astra";
|
||||||
public override string ModuleDescription => "Records playtime per session, team and alive/dead state";
|
public override string ModuleDescription => "Records playtime per session, team and alive/dead state";
|
||||||
|
|
||||||
|
|
@ -35,6 +35,9 @@ public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
||||||
private bool _geoBroken;
|
private bool _geoBroken;
|
||||||
|
|
||||||
private string _map = "";
|
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.
|
// False between a map's end and the next one's start, when nothing is opened.
|
||||||
private bool _mapRunning;
|
private bool _mapRunning;
|
||||||
|
|
||||||
|
|
@ -115,7 +118,12 @@ public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
||||||
ServerSeenNow();
|
ServerSeenNow();
|
||||||
|
|
||||||
AddTimer(1.0f, Reconcile, TimerFlags.REPEAT);
|
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);
|
AddTimer(Config.PingSampleIntervalSeconds, SamplePing, TimerFlags.REPEAT);
|
||||||
if (Config.OnlineSnapshotIntervalSeconds > 0)
|
if (Config.OnlineSnapshotIntervalSeconds > 0)
|
||||||
AddTimer(Config.OnlineSnapshotIntervalSeconds, TakeSnapshot, TimerFlags.REPEAT);
|
AddTimer(Config.OnlineSnapshotIntervalSeconds, TakeSnapshot, TimerFlags.REPEAT);
|
||||||
|
|
@ -178,9 +186,12 @@ public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
||||||
player is { IsValid: true, IsBot: false, IsHLTV: false } &&
|
player is { IsValid: true, IsBot: false, IsHLTV: false } &&
|
||||||
player.Connected == PlayerConnectedState.Connected && player.SteamID != 0;
|
player.Connected == PlayerConnectedState.Connected && player.SteamID != 0;
|
||||||
|
|
||||||
private void ServerSeenNow()
|
private void ServerSeenNow(bool onlyIfChanged = false)
|
||||||
{
|
{
|
||||||
var hostname = ConVar.Find("hostname")?.StringValue ?? "";
|
var hostname = ConVar.Find("hostname")?.StringValue ?? "";
|
||||||
|
if (onlyIfChanged && hostname == _sentHostname)
|
||||||
|
return;
|
||||||
|
_sentHostname = hostname;
|
||||||
_writer?.Enqueue(new ServerSeen(Config.ServerId, Config.PublicAddress, hostname, Now()));
|
_writer?.Enqueue(new ServerSeen(Config.ServerId, Config.PublicAddress, hostname, Now()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue