X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=plomrogue%2Fio.py;h=252fac18d3c3fba5a5f6308f535e165746f20b7d;hb=df9a8d0a788b29913dae3eec4ef8113e2d8e9a41;hp=8e0f9bf530548572eb7c07d389d7188e19af47d1;hpb=540aec0e9bf55d0452cffda4b34e1995d3724abf;p=plomrogue2 diff --git a/plomrogue/io.py b/plomrogue/io.py index 8e0f9bf..252fac1 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() @@ -69,9 +80,9 @@ class GameIO(): command(*args, connection_id=connection_id) elif god_mode: command(*args) - #if store and not hasattr(command, 'dont_save'): - # with open(self.game_file_name, 'a') as f: - # f.write(input_ + '\n') + # if store and not hasattr(command, 'dont_save'): + # with open(self.game_file_name, 'a') as f: + # f.write(input_ + '\n') except ArgError as e: answer(connection_id, 'ARGUMENT_ERROR ' + quote(str(e))) except PlayError as e: @@ -88,7 +99,7 @@ class GameIO(): """ if connection_id: for server in self.servers: - if connection_id in server.clients: + if connection_id in server.clients: client = server.clients[connection_id] client.put(msg) else: