From baab532ba5125527bdc7061864f7cc7db8d7abc3 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 16 Nov 2020 00:49:37 +0100 Subject: [PATCH] Add basic flood protection to server. --- plomrogue/io.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plomrogue/io.py b/plomrogue/io.py index 8e0f9bf..68f580b 100644 --- a/plomrogue/io.py +++ b/plomrogue/io.py @@ -14,10 +14,21 @@ class GameIO(): self.servers = [] def loop(self, q): - """Handle commands coming through queue q, run game, send results back.""" + """Handle commands coming through queue q, run game, send results back. + + As basic flood protection, Only accepts one command per connection per + 1/100 of a second. + + """ + import time + potential_flooders = {} while True: try: command, connection_id = q.get(timeout=0.001) + if connection_id in potential_flooders: + if int(time.time() * 100) == potential_flooders[connection_id]: + continue + potential_flooders[connection_id] = int(time.time() * 100) self.handle_input(connection_id, command) except queue.Empty: self.game.run_tick() -- 2.30.2