X-Git-Url: https://plomlompom.com/repos/bar%20baz.html?a=blobdiff_plain;f=server_%2Fgame.py;h=b52f16ef8eb3f20e7f2b4699c08bc34093c4d3de;hb=6eae766d1b2cdfe0bdbaaabcbf00977a4df4fbbb;hp=e611a0ed825740cf9eff3bc74a2528738182236d;hpb=992fc9b392c4318bd2fda31f526ea838b0138a9e;p=plomrogue2-experiments diff --git a/server_/game.py b/server_/game.py index e611a0e..b52f16e 100644 --- a/server_/game.py +++ b/server_/game.py @@ -207,16 +207,19 @@ class CommandHandler(game_common.Commander): self.pool = Pool() self.pool_result = None - def quote(self, string): - """Quote & escape string so client interprets it as single token.""" - quoted = [] - quoted += ['"'] - for c in string: - if c in {'"', '\\'}: - quoted += ['\\'] - quoted += [c] - quoted += ['"'] - return ''.join(quoted) + def send(self, msg, connection_id=None): + """Send message msg to server's client(s) via self.queues_out. + + If a specific client is identified by connection_id, only + sends msg to that one. Else, sends it to all clients + identified in self.queues_out. + + """ + if connection_id: + self.queues_out[connection_id].put(msg) + else: + for connection_id in self.queues_out: + self.queues_out[connection_id].put(msg) def handle_input(self, input_, connection_id=None, store=True): """Process input_ to command grammar, call command handler if found.""" @@ -245,19 +248,16 @@ class CommandHandler(game_common.Commander): except game.GameError as e: answer(connection_id, 'GAME_ERROR ' + self.quote(str(e))) - def send(self, msg, connection_id=None): - """Send message msg to server's client(s) via self.queues_out. - - If a specific client is identified by connection_id, only - sends msg to that one. Else, sends it to all clients - identified in self.queues_out. - - """ - if connection_id: - self.queues_out[connection_id].put(msg) - else: - for connection_id in self.queues_out: - self.queues_out[connection_id].put(msg) + def quote(self, string): + """Quote & escape string so client interprets it as single token.""" + quoted = [] + quoted += ['"'] + for c in string: + if c in {'"', '\\'}: + quoted += ['\\'] + quoted += [c] + quoted += ['"'] + return ''.join(quoted) def send_gamestate(self, connection_id=None): """Send out game state data relevant to clients.""" @@ -324,6 +324,7 @@ class CommandHandler(game_common.Commander): self.world.turn += 1 self.send_gamestate() self.pool_result = self.pool.map_async(fib, (35, 35)) + def cmd_MOVE(self, direction): """Set player task to 'move' with direction arg, finish player turn.""" if direction not in {'UP', 'DOWN', 'RIGHT', 'LEFT'}: