Beispiel #1
0
    def _query_melee_ranking_succeed(self, proxy, user_id, self_arena,
                                     self_ranking, all_arenas, all_arenas_rank,
                                     req, timer):

        users = proxy.get_all_result("user")

        res = ranking_pb2.QueryRankingRes()
        res.status = 0

        for i, user in enumerate(users):
            if user.id == user_id:
                pack.pack_ranking_info_of_user(
                    user, MeleeInfo.get_real_score(self_arena.score),
                    self_ranking, res.rankings.add())

            else:
                pack.pack_ranking_info_of_user(
                    user, MeleeInfo.get_real_score(all_arenas[user.id].score),
                    all_arenas_rank[user.id], res.rankings.add())

        response = res.SerializeToString()
        log = log_formater.output2(user_id, "Query melee ranking succeed", req,
                                   res, timer.count_ms())
        logger.notice(log)
        return response
Beispiel #2
0
    def _query_battle_score_ranking_succeed(self, proxy, user_id, req,
                                            self_ranking, self_battlescore,
                                            player_scores, player_rankings,
                                            timer):
        users = proxy.get_all_result("user")
        if len(users) != len(player_scores) and len(users) != (
                len(player_scores) + 1):
            raise Exception("Ranking players num error")
        logger.debug('len users [%d]' % len(users))

        res = ranking_pb2.QueryRankingRes()
        res.status = 0

        for i, user in enumerate(users):
            if user.id == user_id:
                pack.pack_ranking_info_of_user(user,
                                               self_battlescore, self_ranking,
                                               res.rankings.add())
            else:
                pack.pack_ranking_info_of_user(user,
                                               player_scores[user.id].score,
                                               player_rankings[user.id] + 1,
                                               res.rankings.add())

        response = res.SerializeToString()
        log = log_formater.output2(user_id,
                                   "Query battle score ranking succeed", req,
                                   res, timer.count_ms())
        logger.notice(log)
        return response
Beispiel #3
0
    def _query_official_position_ranking_succeed(self, proxy, user_id,
                                                 self_arena, all_arenas,
                                                 all_arenas_rank, req, timer):

        users = proxy.get_all_result("user")

        res = ranking_pb2.QueryRankingRes()
        res.status = 0

        for i, user in enumerate(users):
            #官职榜不用ranking值
            if user.id == user_id:
                if user.id not in all_arenas_rank:
                    pack.pack_ranking_info_of_user(
                        user, self_arena.calc_arena_title_level(0), 0,
                        res.rankings.add())
                else:
                    pack.pack_ranking_info_of_user(
                        user,
                        self_arena.calc_arena_title_level(
                            all_arenas_rank[user.id]), 0, res.rankings.add())
            else:
                pack.pack_ranking_info_of_user(
                    user, all_arenas[user.id].calc_arena_title_level(
                        all_arenas_rank[user.id]), 0, res.rankings.add())

        response = res.SerializeToString()
        log = log_formater.output2(user_id,
                                   "Query official position ranking succeed",
                                   req, res, timer.count_ms())
        logger.notice(log)
        return response
Beispiel #4
0
 def _query_failed(self, err, req, timer):
     logger.fatal("Query ranking failed[reason=%s]" % err)
     res = ranking_pb2.QueryRankingRes()
     res.status = -1
     response = res.SerializeToString()
     logger.notice("Query ranking failed"
                   "[user_id=%d][req=%s][res=%s][consume=%d]" %
                   (timer.id, req, res, timer.count_ms()))
     return response
Beispiel #5
0
 def _query_transfer_arena_failed(self, err, req, timer):
     logger.fatal("Query transfer arena rank failed[reason=%s]" % err)
     res = ranking_pb2.QueryRankingRes()
     res.status = -1
     response = res.SerializeToString()
     logger.notice(
         "Query transfer arena rank failed[req=%s][res=%s][consume=%d]" %
         (req, res, timer.count_ms()))
     return response
Beispiel #6
0
    def _calc_union_season_battle_individual_result(self, proxy, rankings,
                                                    data, req, timer):
        users = {}
        for user in proxy.get_all_result("user"):
            users[user.id] = user

        res = ranking_pb2.QueryRankingRes()
        res.status = 0
        for ranking in rankings:
            union = rankings[ranking]
            user = users[union.user_id]
            pack.pack_ranking_info_of_user(user, union.season_score,
                                           ranking + 1, res.rankings.add())

        return res
Beispiel #7
0
    def _calc_union_season_battle_result(self, proxy, rankings, data, req,
                                         timer):
        unions = {}
        for union in proxy.get_all_result("unionunion"):
            unions[union.id] = union

        res = ranking_pb2.QueryRankingRes()
        res.status = 0
        for ranking in rankings:
            season = rankings[ranking]
            union = unions[season.union_id]
            pack.pack_ranking_info_of_union(union, season.score, ranking + 1,
                                            res.rankings.add())

        return res
Beispiel #8
0
    def _calc_query_transfer_arena_match(self, results, data, req, timer,
                                         ranks):
        res = ranking_pb2.QueryRankingRes()
        res.status = 0

        for rank in ranks:
            rank_info = res.rankings.add()
            rank_info.id = rank.user_id
            rank_info.ranking = rank.rank
            rank_info.name = results[rank.user_id]['name']
            rank_info.level = results[rank.user_id]['level']
            rank_info.value = results[
                rank.user_id]['battle_score'] if not rank.is_robot else 0
            rank_info.icon_id = results[rank.user_id]['icon_id']
            rank_info.value1 = int(rank.transfer_type)

        defer = DataBase().commit(data)
        defer.addCallback(self._query_transfer_arena_succeed, req, res, timer)
        return defer