Beispiel #1
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 #2
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 #3
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 #4
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 #5
0
    def _calc_season_ranking_result(self, proxy, req, seasons, indivs, timer):
        unions = {}
        for union in proxy.get_all_result("unionunion"):
            unions[union.id] = union
        users = {}
        for user in proxy.get_all_result("user"):
            users[user.id] = user
        members = proxy.get_all_result("unionmember")

        res = union_battle_pb2.TryForwardUnionBattleSeasonRes()
        res.status = 0
        res.enable = False

        for ranking, season in enumerate(seasons):
            union = unions[season.union_id]
            pack.pack_ranking_info_of_union(union, season.score, ranking + 1,
                                            res.union_ranking.add())

        for ranking, indiv in enumerate(indivs):
            user = users[indiv.user_id]
            pack.pack_ranking_info_of_user(user, indiv.season_score,
                                           ranking + 1, res.user_ranking.add())

        for member in members:
            member_msg = res.members.add()
            member_msg.user_id = member.user_id
            member_msg.union_id = member.union_id
        for indiv in indivs:
            member_msg = res.members.add()
            member_msg.user_id = indiv.user_id
            member_msg.union_id = indiv.union_id

        dumper = DataDumper()
        defer = dumper.get_all("unionunion", "id")
        defer.addCallback(self._calc_try_forward_season, req, res, timer)
        return defer