From dae1dfd8240a2f88b25c88275061f792e2e683a3 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Mon, 31 Jul 2023 11:06:12 +0100 Subject: [PATCH] Ratelimit BloxstrapRPC requests --- Bloxstrap/Integrations/ActivityWatcher.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; } } }