def join_room(arg): assert arg.has_key('room'), 'Required argument is missing: "room".' room = Room.get(arg['room']) assert room is not None, 'Specified room is not exists.' assert room.capacity - room.players.count( ) > 0, 'Sorry, specified room is fulled. %s' % (room.capacity - room.players.count()) player = arg['sender'] player.room = room player.put() return _format_message('join_room', 'ok', {'room': str(player.room.key())})
def list_player(arg): player = arg['sender'] if 'room' in arg: room = Room.get(arg['room']) elif player.room: room = player.room else: raise AssertionError('Required argument is missing: "room".') return _format_message( 'list_player', 'ok', { 'players': [{ 'id': p.account.address, 'is_ready': int(p.is_ready) } for p in room.players] })