home
·
contact
·
privacy
projects
/
plomrogue2
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
81d7eeb
)
Add basic flood protection to server.
author
Christian Heller
<c.heller@plomlompom.de>
Sun, 15 Nov 2020 23:49:37 +0000
(
00:49
+0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Sun, 15 Nov 2020 23:49:37 +0000
(
00:49
+0100)
plomrogue/io.py
patch
|
blob
|
history
diff --git
a/plomrogue/io.py
b/plomrogue/io.py
index 8e0f9bf530548572eb7c07d389d7188e19af47d1..68f580ba3fa689b78075a175ed4a2e880128235f 100644
(file)
--- a/
plomrogue/io.py
+++ b/
plomrogue/io.py
@@
-14,10
+14,21
@@
class GameIO():
self.servers = []
def loop(self, q):
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)
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()
self.handle_input(connection_id, command)
except queue.Empty:
self.game.run_tick()