diff --git a/Bloxstrap/Integrations/ActivityWatcher.cs b/Bloxstrap/Integrations/ActivityWatcher.cs index 44e0475..0571e3c 100644 --- a/Bloxstrap/Integrations/ActivityWatcher.cs +++ b/Bloxstrap/Integrations/ActivityWatcher.cs @@ -26,7 +26,8 @@ public event EventHandler? OnGameLeave; public event EventHandler? OnRPCMessage; - private Dictionary GeolocationCache = new(); + private readonly Dictionary GeolocationCache = new(); + private DateTime LastRPCRequest; public string LogLocation = null!; @@ -237,6 +238,12 @@ App.Logger.WriteLine(LOG_IDENT, $"Received message: '{messagePlain}'"); + if ((DateTime.Now - LastRPCRequest).TotalSeconds <= 1) + { + App.Logger.WriteLine(LOG_IDENT, "Dropping message as ratelimit has been hit"); + return; + } + try { message = JsonSerializer.Deserialize(messagePlain); @@ -260,6 +267,8 @@ } OnRPCMessage?.Invoke(this, message); + + LastRPCRequest = DateTime.Now; } } }