- def cmd_get_turn(self, connection_id):
- """Send world.turn to caller."""
- self.send_to(connection_id, str(self.world.turn))
-
- def cmd_move(self, direction, connection_id):
- """Set player task to 'move' with direction arg, finish player turn."""
- if not direction in {'UP', 'DOWN'}:
- raise ArgumentError('MOVE ARGUMENT MUST BE "UP" or "DOWN"')
- self.world.player.set_task('move', direction=direction)
- self.proceed_to_next_player_turn(connection_id)
-
- def cmd_wait(self, connection_id):
- """Set player task to 'wait', finish player turn."""
- self.world.player.set_task('wait')
- self.proceed_to_next_player_turn(connection_id)
-
- def cmd_echo(self, tokens, input_, connection_id):
- """Send message in input_ beyond tokens[0] to caller."""
- msg = input_[len(tokens[0]) + 1:]
- self.send_to(connection_id, msg)
-
- def cmd_all(self, tokens, input_):
- """Send message in input_ beyond tokens[0] to all clients."""
- msg = input_[len(tokens[0]) + 1:]
- self.send_all(msg)
-
- def handle_input(self, input_, connection_id):
- """Process input_ to command grammar, call command handler if found."""
- tokens = [token for token in input_.split(' ') if len(token) > 0]
- try:
- if len(tokens) == 0:
- self.send_to(connection_id, 'EMPTY COMMAND')
- elif len(tokens) == 1 and tokens[0] == 'INC_P':
- self.cmd_inc_p(connection_id)
- elif len(tokens) == 1 and tokens[0] == 'GET_TURN':
- self.cmd_get_turn(connection_id)
- elif len(tokens) == 1 and tokens[0] == 'WAIT':
- self.cmd_wait(connection_id)
- elif len(tokens) == 2 and tokens[0] == 'MOVE':
- self.cmd_move(tokens[1], connection_id)
- elif len(tokens) >= 1 and tokens[0] == 'ECHO':
- self.cmd_echo(tokens, input_, connection_id)
- elif len(tokens) >= 1 and tokens[0] == 'ALL':
- self.cmd_all(tokens, input_)
- elif len(tokens) >= 1 and tokens[0] == 'FIB':
- # TODO: Should this really block the whole loop?
- self.cmd_fib(tokens, connection_id)
- else:
- self.send_to(connection_id, 'UNKNOWN COMMAND')
- except ArgumentError as e:
- self.send_to(connection_id, 'ARGUMENT ERROR: ' + str(e))