From 13edd308bf19a8d432b7edd19a99398c54297a0b Mon Sep 17 00:00:00 2001 From: Myra Date: Tue, 14 Jan 2025 21:38:26 +0100 Subject: [PATCH] Fix IPIntel causing frequent errors with the cleanup job. (#34428) Co-authored-by: Pieter-Jan Briers --- Content.Server/Connection/ConnectionManager.cs | 11 +++++++++-- Content.Server/Connection/IPIntel/IPIntel.cs | 8 +++++--- Content.Server/Database/ServerDbBase.cs | 5 ++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index 927ebf5f6f..ab27553f44 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -94,9 +94,16 @@ namespace Content.Server.Connection time = newTime; } - public void Update() + public async void Update() { - _ipintel.Update(); + try + { + await _ipintel.Update(); + } + catch (Exception e) + { + _sawmill.Error("IPIntel update failed:" + e); + } } /* diff --git a/Content.Server/Connection/IPIntel/IPIntel.cs b/Content.Server/Connection/IPIntel/IPIntel.cs index 033cdb5cd1..51a0b74089 100644 --- a/Content.Server/Connection/IPIntel/IPIntel.cs +++ b/Content.Server/Connection/IPIntel/IPIntel.cs @@ -38,6 +38,7 @@ public sealed class IPIntel _sawmill = logManager.GetSawmill("ipintel"); cfg.OnValueChanged(CCVars.GameIPIntelEmail, b => _contactEmail = b, true); + cfg.OnValueChanged(CCVars.GameIPIntelEnabled, b => _enabled = b, true); cfg.OnValueChanged(CCVars.GameIPIntelRejectUnknown, b => _rejectUnknown = b, true); cfg.OnValueChanged(CCVars.GameIPIntelRejectBad, b => _rejectBad = b, true); cfg.OnValueChanged(CCVars.GameIPIntelRejectRateLimited, b => _rejectLimited = b, true); @@ -74,6 +75,7 @@ public sealed class IPIntel // CCVars private string? _contactEmail; + private bool _enabled; private bool _rejectUnknown; private bool _rejectBad; private bool _rejectLimited; @@ -273,12 +275,12 @@ public sealed class IPIntel return _rejectBad ? (true, Loc.GetString("ipintel-suspicious")) : (false, string.Empty); } - public void Update() + public async Task Update() { - if (_gameTiming.RealTime >= _nextClean) + if (_enabled && _gameTiming.RealTime >= _nextClean) { _nextClean = _gameTiming.RealTime + TimeSpan.FromMinutes(_cleanupMins); - _db.CleanIPIntelCache(_cacheDays); + await _db.CleanIPIntelCache(_cacheDays); } } diff --git a/Content.Server/Database/ServerDbBase.cs b/Content.Server/Database/ServerDbBase.cs index cedf369d50..8ab2df88b3 100644 --- a/Content.Server/Database/ServerDbBase.cs +++ b/Content.Server/Database/ServerDbBase.cs @@ -1774,8 +1774,11 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id} { await using var db = await GetDb(); + // Calculating this here cause otherwise sqlite whines. + var cutoffTime = DateTime.UtcNow.Subtract(range); + await db.DbContext.IPIntelCache - .Where(w => DateTime.UtcNow - w.Time >= range) + .Where(w => w.Time <= cutoffTime) .ExecuteDeleteAsync(); await db.DbContext.SaveChangesAsync(); -- 2.51.2