From: Christian Heller Date: Tue, 27 Oct 2020 04:57:23 +0000 (+0100) Subject: Introduce god mode to protect against destructive commands. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/templates?a=commitdiff_plain;h=f7f11798a90187ab83d038f737368317a99e15b0;p=plomrogue2-experiments Introduce god mode to protect against destructive commands. --- diff --git a/new2/plomrogue/commands.py b/new2/plomrogue/commands.py index 9e67ce0..28b7600 100644 --- a/new2/plomrogue/commands.py +++ b/new2/plomrogue/commands.py @@ -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' diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index 74c79d1..406d96d 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -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 diff --git a/new2/plomrogue/io.py b/new2/plomrogue/io.py index 2283a98..9f34b18 100644 --- a/new2/plomrogue/io.py +++ b/new2/plomrogue/io.py @@ -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: