コード例 #1
0
ファイル: players.py プロジェクト: Andrioden/dotacareer
    def post(self):
        request_data = json.loads(self.request.body)
        logging.info(request_data)
        user = users.get_current_user()

        # VALIDATION
        if not validate_request_data(self.response, request_data, ['nick', 'player_class']):
            return
        if not validate_logged_inn(self.response):
            return
        if not self._validate_has_not_player_already(user):
            return
        if Player.query(Player.nick_lower == request_data['nick'].lower()).count() > 0:
            error_400(self.response, "ERROR_NICK_TAKEN", "The nickname %s is already taken" % request_data['nick'])
            return
        if not is_valid_player_class_name(request_data['player_class']):
            error_400(self.response, "ERROR_BAD_PLAYER_CLASS", "Player class ' %s ' is not valid." % request_data['player_class'])
            return

        # REGISTER PLAYER
        new_player = Player(
            id=user.user_id(),
            nick=request_data['nick']
        )

        for player_class in player_class_metrics:
            if player_class['name'] == request_data['player_class']:
                logging.info(player_class['stat_modifiers'])
                for stat_name, stat_value in player_class['stat_modifiers'].iteritems():
                    current_stat_value = getattr(new_player, stat_name)
                    new_stat_value = current_stat_value + stat_value
                    setattr(new_player, stat_name, new_stat_value)

        new_player.put().get()
        set_json_response(self.response, new_player.get_data("full"))
コード例 #2
0
ファイル: shinobi.py プロジェクト: meszka/shinobi
 def get(self, gid, pid):
     user = authenticate(request.authorization)
     if not user:
         return auth_response()
     player = Player(gid, pid)
     if not player.exists():
         return '', 404
     cards = player.get_cards()
     response_data = player.get_data()
     if user.username == player.get_username():
         response_data['color'] = player.get_color()
     return jsonify(response_data)
コード例 #3
0
ファイル: shinobi.py プロジェクト: meszka/shinobi
 def get(self, gid):
     user = authenticate(request.authorization)
     if not user:
         return auth_response()
     game = Game(gid)
     game_state = game.get_state()
     pids = game.get_pids()
     players = []
     for pid in pids:
         player = Player(gid, pid)
         cards = player.get_cards()
         username = player.get_username()
         player_data = player.get_data()
         if (user and username == user.username) or game_state == 'ended':
             player_data['color'] = player.get_color()
         players.append(player_data)
     return jsonify({'players': players})