class GameIO():
- def __init__(self, game):
+ def __init__(self, game, save_file='savefile'):
from plomrogue.parser import Parser
self.clients = {}
self.parser = Parser(game)
self.game = game
+ self.save_file = save_file
def loop(self, q):
"""Handle commands coming through queue q, run game, send results back."""
while True:
try:
- command, connection_id = q.get(timeout=1)
+ command, connection_id = q.get(timeout=0.001)
self.handle_input(connection_id, command)
except queue.Empty:
self.game.run_tick()
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
+ print('DEBUG', input_);
def answer(connection_id, msg):
if connection_id:
self.send(msg, connection_id)
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)))