home · contact · privacy
Introduce god mode to protect against destructive commands.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 27 Oct 2020 04:57:23 +0000 (05:57 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 27 Oct 2020 04:57:23 +0000 (05:57 +0100)
new2/plomrogue/commands.py
new2/plomrogue/game.py
new2/plomrogue/io.py

index 9e67ce02600682eaa12823c3d63bf7c6ffaed6a8..28b76006fe8088ffcc3d93bc64a455f71db8348b 100644 (file)
@@ -49,8 +49,7 @@ def cmd_TURN(game, n):
     game.turn = n
 cmd_TURN.argtypes = 'int:nonneg'
 
-#def cmd_ANNOTATE(game, yx, connection_id):
-def cmd_ANNOTATE(game, yx, msg):
+def cmd_ANNOTATE(game, yx, msg, connection_id):
     if msg == ' ':
         if yx in game.annotations:
             del game.annotations[yx]
@@ -66,7 +65,6 @@ def cmd_GET_ANNOTATION(game, yx, connection_id):
     game.io.send('ANNOTATION %s %s' % (yx, quote(annotation)))
 cmd_GET_ANNOTATION.argtypes = 'yx_tuple:nonneg'
 
-# TODO: disallow these commands from clients? (maybe by failing on connection_id?)
 def cmd_MAP_LINE(game, y, line):
     game.map.set_line(y, line)
 cmd_MAP_LINE.argtypes = 'int:nonneg string'
index 74c79d1e2eadddc7502bd803455f6c691ad70eb5..406d96d2675ca00930d7999fed48fd648d62ac15 100755 (executable)
@@ -67,7 +67,7 @@ class Game(GameBase):
                 for i in range(len(lines)):
                     line = lines[i]
                     print("FILE INPUT LINE %5s: %s" % (i, line), end='')
-                    self.io.handle_input(line)
+                    self.io.handle_input(line, god_mode=True)
 
     def get_string_options(self, string_option_type):
         import string
index 2283a986d10717511778b1d79aa5dca4b4919557..9f34b180f851793b04ce02e32c52b46ea9c68481 100644 (file)
@@ -45,8 +45,13 @@ class GameIO():
             print('Killing server')
             self.server.server_close()
 
-    def handle_input(self, input_, connection_id=None):
-        """Process input_ to command grammar, call command handler if found."""
+    def handle_input(self, input_, connection_id=None, god_mode=False):
+        """Process input_ to command grammar, call command handler if found.
+
+        Command handlers that have no connectin_i argument in their
+        signature will only be called if god_mode is set.
+
+        """
         from inspect import signature
         from plomrogue.errors import GameError, ArgError
         from plomrogue.misc import quote
@@ -64,7 +69,7 @@ class GameIO():
             else:
                 if 'connection_id' in list(signature(command).parameters):
                     command(*args, connection_id=connection_id)
-                else:
+                elif god_mode:
                     command(*args)
                     #if store and not hasattr(command, 'dont_save'):
                     #    with open(self.game_file_name, 'a') as f: