X-Git-Url: https://plomlompom.com/repos/pick_tasks?a=blobdiff_plain;f=new2%2Fplomrogue%2Fio.py;h=908d7bf504b7c304c937729b1bb5cccb3f47538b;hb=1d9e41e7df05336a6688382c9374c547979cf11e;hp=2283a986d10717511778b1d79aa5dca4b4919557;hpb=47d047c10bacf2463f48aec3e7f3cc3b92a78198;p=plomrogue2-experiments diff --git a/new2/plomrogue/io.py b/new2/plomrogue/io.py index 2283a98..908d7bf 100644 --- a/new2/plomrogue/io.py +++ b/new2/plomrogue/io.py @@ -45,10 +45,15 @@ 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.errors import GameError, ArgError, PlayError from plomrogue.misc import quote def answer(connection_id, msg): @@ -64,13 +69,15 @@ 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: # f.write(input_ + '\n') except ArgError as e: answer(connection_id, 'ARGUMENT_ERROR ' + quote(str(e))) + except PlayError as e: + answer(connection_id, 'PLAY_ERROR ' + quote(str(e))) except GameError as e: answer(connection_id, 'GAME_ERROR ' + quote(str(e)))