示例#1
0
def world_ranklist(p, req):
    if hasattr(p, "uid"):
        log.debug('uid:{0}'.format(p.uid))
        uid = p.uid
    else: # used to test
        log.error('client has not found uid.')
        defer.returnValue((CONNECTION_LOSE, None))

    user = g_UserMgr.getUserByUid(uid)
    if not user:
        defer.returnValue((CONNECTION_LOSE, None))

    data = list()
    other_data = list()
    weight_data = yield redis.zrange(SET_RANK_PVP_WEIGHT, 0, 10, True)
    for _rank, (_uid, _weight) in enumerate(weight_data):
        _machine_code = yield redis.hget(HASH_UID_MACHINE_CODE, _uid)
        other_data.append((_rank+1, _uid, _machine_code, _weight))

    self_rank = yield redis.zrank(SET_RANK_PVP_WEIGHT, uid)
    self_rank = 0 if self_rank is None else int(self_rank) + 1
    self_machine_code = yield redis.hget(HASH_UID_MACHINE_CODE, uid)
    self_weight = yield redis.zscore(SET_RANK_PVP_WEIGHT, uid)
    self_weight = 0 if self_weight is None else abs(self_weight)

    data = (other_data, (self_rank, uid, self_machine_code, self_weight))
    defer.returnValue((NO_ERROR, data))
示例#2
0
def world_ranklist(p, req):
    if hasattr(p, "uid"):
        log.debug('uid:{0}'.format(p.uid))
        uid = p.uid
    else:  # used to test
        log.error('client has not found uid.')
        defer.returnValue((CONNECTION_LOSE, None))

    user = g_UserMgr.getUserByUid(uid)
    if not user:
        defer.returnValue((CONNECTION_LOSE, None))

    data = list()
    other_data = list()
    weight_data = yield redis.zrange(SET_RANK_PVP_WEIGHT, 0, 10, True)
    for _rank, (_uid, _weight) in enumerate(weight_data):
        _machine_code = yield redis.hget(HASH_UID_MACHINE_CODE, _uid)
        other_data.append((_rank + 1, _uid, _machine_code, _weight))

    self_rank = yield redis.zrank(SET_RANK_PVP_WEIGHT, uid)
    self_rank = 0 if self_rank is None else int(self_rank) + 1
    self_machine_code = yield redis.hget(HASH_UID_MACHINE_CODE, uid)
    self_weight = yield redis.zscore(SET_RANK_PVP_WEIGHT, uid)
    self_weight = 0 if self_weight is None else abs(self_weight)

    data = (other_data, (self_rank, uid, self_machine_code, self_weight))
    defer.returnValue((NO_ERROR, data))
示例#3
0
    def refresh_cids(self, cid, score, rank):
        ''' 刷新CID '''
        _rank_start = rank
        _char_num = 2  # 玩家的数量
        if score >= JOUST_BASIC_SCORE:
            _rank_start = rank - RANK_RANGE
            _rank_start = _rank_start if _rank_start > 0 else 0
            _char_num = 3

        _cid_pools = []  # 用于随机对手的cid池
        #log.info('For Test. random cid. _rank_start: {0}, _rank_end: {1}, req: {2}.'.format( _rank_start, rank + RANK_RANGE, (cid, score, rank) ))
        _cid_scores = yield redis.zrange(SET_JOUST_CID_SCORE,
                                         _rank_start,
                                         rank + RANK_RANGE,
                                         withscores=True)
        for _cid, _score in _cid_scores:
            if -int(_score) < JOUST_BASIC_SCORE:
                continue
            if _cid == cid:
                continue
            _cid_pools.append(_cid)

        if len(_cid_pools) > _char_num:
            _refresh_data = random.sample(_cid_pools, _char_num)
        else:
            _refresh_data = _cid_pools
        #log.info('For Test. refresh cids: {0}, _cid_pools len: {1}.'.format( _refresh_data, len(_cid_pools) ))
        _robot_num = 3 - len(_refresh_data)
        for _i in range(0, _robot_num):
            _refresh_data.append(random.randint(1, 500))

        defer.returnValue(_refresh_data)
示例#4
0
    def ranklist(self):
        ''' 
        @summary: 竞技场的排行榜的前十名
        '''
        _ranklist  = []
        _cid_ranks = yield redis.zrange( SET_ARENA_CID_RANK, 0, 9, withscores=True )
        for _cid, _rank in _cid_ranks:
            _detail = yield self.get_rank_detail( int(_rank) )
            if _detail and _detail[0] > 0:
                _ranklist.append( _detail )
 
        defer.returnValue( _ranklist )
示例#5
0
    def get_all_char_rank(self):
        ''' rank: 0-没有排名
        '''
        _all_ranks = {}
        _cid_ranks = yield redis.zrange( SET_ARENA_CID_RANK, 0, -1, withscores=True )
        for _cid, _rank in _cid_ranks:
            _cids = _all_ranks.get(_rank, [])
            if _cid not in _cids:
                _cids.append( _cid )
                _all_ranks[_rank] = _cids
 
        defer.returnValue( _all_ranks )
示例#6
0
    def current_rank(self):
        if self._cached_rank:
            if not self._running:  #不在活动期间,直接返回缓存数据
                defer.returnValue(self._cached_rank)
            else:
                _now = time()
                if _now - self._last_rank_time <= 10:
                    defer.returnValue(self._cached_rank)
                else:
                    self._last_rank_time = _now

        _cids = yield redis.zrange(RANK_WORLDBOSS_DAMAGE, 0, 10, True)
        if _cids:
            _dict_char_info = yield redis.hmget(DICT_WORLDBOSS_RANKER_DATA,
                                                [r[0] for r in _cids])
        else:
            _dict_char_info = []

        #log.debug('_cids:', _cids, '_dict_char_info:', _dict_char_info)

        _res = []
        _alli_ids = []

        for idx, (cid, damage) in enumerate(_cids):
            _info = _dict_char_info[idx]
            if _info:
                _name, _level, _alliance_id = loads(_info)
                _alli_ids.append(_alliance_id)
                _res.append(
                    [cid, _name, _level, _alliance_id, -damage, idx + 1])
            else:
                log.error('No such user data in ranker data. cid:', cid)

        if _alli_ids:
            #从公会服务器以ID换取公会名
            _alli_names = yield alli_call('get_alliance_names', (_alli_ids, ))
            for _idx, (_cid, _name) in enumerate(_alli_names):
                if _name:
                    _res[_idx][3] = _name
                else:
                    _res[_idx][3] = ''

            if not self._running:
                self._cached_rank = _res

        defer.returnValue(_res)
示例#7
0
    def reward_to_award_center(self, total_rank=4999, interval=99):
        try:
            timestamp = int(time())
            cid_ranks = yield redis.zrange( SET_ARENA_CID_RANK, total_rank-interval, total_rank, withscores=True )
            if cid_ranks:
                log.debug('redis start: {0}, stop: {1}, cid_ranks: {2}.'.format( total_rank-interval, total_rank, cid_ranks ))
            for _cid, _rank in cid_ranks:
                yield g_AwardCenterMgr.new_award( int(_cid), AWARD_TYPE_ARENARANK, [timestamp, int(_rank)], False )
                #rank_award_conf = get_arena_rank_award( int(_rank) )
                #if rank_award_conf:
                #    items_list = split_items( rank_award_conf['ArenaRankList'] )
                #    ms_send('write_mail', (_cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_1, [timestamp, int(_rank), items_list]))
        except Exception as e:
            log.error('Exception e: {0}.'.format( e ))

        if total_rank  > interval:
            total_rank -= (interval + 1)
            reactor.callLater( 2, self.reward_to_award_center, total_rank, interval )
示例#8
0
    def close(self):
        _last_attacker_id, _last_attacker_name = 0, ''
        if self._last_attackers and self.life <= 0:
            _last_attacker_id, _last_attacker_name = self._last_attackers[
                -1][:2]

        _cids = yield redis.zrange(RANK_WORLDBOSS_DAMAGE, 0, 3)
        if not _cids: defer.returnValue(None)  #没有一个人杀Boss,不算拉拉拉

        _dict_char_info = yield redis.hmget(DICT_WORLDBOSS_RANKER_DATA, _cids)
        self._char_names_last = [
            loads(_info)[0] for _info in _dict_char_info if _info
        ]
        _len = len(self._char_names_last)
        if _len < 3:
            for x in xrange(3 - _len):
                self._char_names_last.append('')

        #log.warn('[ ddd ]:_cids:', _cids, '_dict_char_info:', _dict_char_info, '_len:', _len, '_char_names_last:', self._char_names_last)

        for _cid, _attacker in AttackerData._cache.iteritems():
            if _attacker._attack_count > 0:
                _rank = yield _attacker.rank
                reward_golds, reward_farm, last_kill_golds, last_kill_fame = self.reward_to_char(
                    _cid, _last_attacker_id, _rank + 1)

                if _cid in self._attackers:
                    _attacker.reward(self.life, reward_golds, reward_farm,
                                     last_kill_golds, last_kill_fame,
                                     _last_attacker_name, _rank)

        self._char_name_lastkill = _last_attacker_name

        self.sync()
        res = yield self.current_rank()
        if res != []:
            first_user = g_UserMgr.getUser(res[0][0])
            if first_user:
                msg = [11, [first_user.nick_name, first_user.lead_id]]
                gw_broadcast('sync_broadcast', [[3, msg]])

        log.info('[ CLOSED ]WorldBoss have finished. last kill:',
                 (_last_attacker_id, _last_attacker_name), 'last attackers:',
                 self._last_attackers)
示例#9
0
    def get_joust_data(self, cid, score, rank, flag=False):
        ''' 获取玩家的历史记录 
        @param: flag-强制刷新对手的标志位
        '''
        _changed = False  # 数据变更的标志位

        _joust_data = yield redis.hget(HASH_JOUST_INFO, cid)
        if _joust_data:
            _joust_data = loads(_joust_data)
        else:
            _changed = True
            _joust_data = [int(time()), 0, 0, [], 0]

        _day_status, _time_status = check_joust_status(_joust_data[0])
        # _time_status: 0-活动中 1-非活动时间 2-活动已结束
        if 2 == _time_status:
            if not self.winner:
                self.winner = yield redis.zrange(SET_JOUST_LAST_CID_SCORE, 0,
                                                 2)
                _len = len(self.winner)
                for _i in range(_len, 3):
                    self.winner.append(_i + 1)
            _joust_data[3] = self.winner

            defer.returnValue((_joust_data, _time_status))
        elif 0 == _time_status:
            # _day_status: 0-同一天 1-隔天 2-隔周
            if 1 == _day_status:
                _changed = True
                _joust_data = [
                    int(time()), 0, _joust_data[2], _joust_data[3], 0
                ]
            elif 2 == _day_status:
                _changed = True
                _joust_data = [int(time()), 0, 0, [], 0]

        if flag or (not _joust_data[3]):
            _changed = True
            _joust_data[3] = yield self.refresh_cids(cid, score, rank)

        if _changed:
            yield redis.hset(HASH_JOUST_INFO, cid, dumps(_joust_data))

        defer.returnValue((_joust_data, _time_status))
示例#10
0
    def current_rank(self):
        if self._cached_rank: 
            if not self._running: #不在活动期间,直接返回缓存数据
                defer.returnValue(self._cached_rank)
            else:
                _now = time()
                if _now - self._last_rank_time <= 10:
                    defer.returnValue(self._cached_rank)
                else:
                    self._last_rank_time = _now

        _cids = yield redis.zrange(RANK_WORLDBOSS_DAMAGE, 0, 10, True)
        if _cids:
            _dict_char_info = yield redis.hmget(DICT_WORLDBOSS_RANKER_DATA, [r[0] for r in _cids])
        else:
            _dict_char_info = []

        #log.debug('_cids:', _cids, '_dict_char_info:', _dict_char_info)

        _res = []
        _alli_ids = []

        for idx, (cid, damage) in enumerate(_cids):
            _info = _dict_char_info[idx]
            if _info:
                _name, _level, _alliance_id = loads(_info)
                _alli_ids.append(_alliance_id)
                _res.append([cid, _name, _level, _alliance_id, -damage, idx + 1])
            else:
                log.error('No such user data in ranker data. cid:', cid)

        if _alli_ids:
            #从公会服务器以ID换取公会名
            _alli_names = yield alli_call('get_alliance_names', (_alli_ids,))
            for _idx, (_cid, _name) in enumerate(_alli_names):
                if _name:
                    _res[_idx][3] = _name
                else:
                    _res[_idx][3] = ''

            if not self._running:
                self._cached_rank = _res

        defer.returnValue(_res)
示例#11
0
    def reward_to_award_center(self, total_count, interval):
        try:
            timestamp = int(time())
            start_rank = total_count - interval + 1 if total_count > interval else 0
            all_cids = yield redis.zrange(SET_JOUST_LAST_CID_SCORE, start_rank,
                                          total_count)
            for _idx, _cid in enumerate(all_cids):
                _rank = (_idx + start_rank + 1)
                yield g_AwardCenterMgr.new_award(_cid, AWARD_TYPE_JOUSTRANK,
                                                 [timestamp, _rank])
                # Reset score
                yield redis.zadd(SET_JOUST_CID_SCORE, _cid, -JOUST_BASIC_SCORE)
        except Exception as e:
            log.exception()

        if total_count > interval:
            total_count -= interval
            reactor.callLater(1, self.reward_to_award_center, total_count,
                              interval)
示例#12
0
    def ranklist(self):
        ''' 
        @summary: 排行榜的前十名
        '''
        _ranklist = []
        _redis_key = SET_JOUST_CID_SCORE
        _status = self.check_time_status()
        if _status == JOUST_HAD_END_ERROR:
            _redis_key = SET_JOUST_LAST_CID_SCORE
        _cid_scores = yield redis.zrange(_redis_key, 0, 9, withscores=True)
        for _idx, _data in enumerate(_cid_scores):
            _detail = yield load_joust_user_data(_data[0], flag=True)
            if not _detail:
                log.error('Unknown user. cid: {0}.'.format(_data[0]))
                continue
            _detail.extend([-int(_data[1]), _idx + 1])
            _ranklist.append(_detail)

        defer.returnValue(_ranklist)
示例#13
0
    def ranklist(self):
        ''' 获取天外天的排行榜 '''
        yield self.load()
        # get myself rank and layer
        _my_rank  = yield redis.zrank(SET_CLIMBING_CID_LAYER, self.cid)
        _my_rank  = 0 if _my_rank is None else int(_my_rank)+1
        _ranklist = [self.climbing.max_layer, _my_rank, []]

        _cid_layers = yield redis.zrange(SET_CLIMBING_CID_LAYER, 0, 9, withscores=True)
        for _idx, _data in enumerate(_cid_layers):
            #log.error('For Test. _idx: {0}, _cid_layers: {1}.'.format( _idx+1, _data ))
            if int(_data[1]) >= 0:
                continue
            _detail = yield load_climbing_user_data(_data[0])
            if not _detail:
                log.error('Unknown user. cid: {0}.'.format( _data[0] ))
                continue
            _detail.extend( [-int(_data[1]), _idx+1] )
            _ranklist[2].append( _detail )

        defer.returnValue( _ranklist )
示例#14
0
    def ranklist(self):
        ''' 剧情副本的排行榜 '''
        yield self._load()
        # get myself rank and star
        _my_rank   = yield redis.zrank(SET_SCENE_CID_STAR, self.cid)
        _my_rank   = 0 if _my_rank is None else int(_my_rank)+1
        _ranklist  = [self.total_star, _my_rank, []]

        _cid_stars = yield redis.zrange(SET_SCENE_CID_STAR, 0, 9, withscores=True)
        #log.error('For Test. _cid_stars: {0}.'.format( _cid_stars ))
        for _idx, _data in enumerate(_cid_stars):
            if int(_data[1]) >= 0:
                continue
            _detail = yield load_scene_user_data(_data[0])
            if not _detail:
                log.error('Unknown user. cid: {0}.'.format( _data[0] ))
                continue
            _detail.extend( [-int(_data[1]), _idx+1] )
            _ranklist[2].append( _detail )

        defer.returnValue( _ranklist )
示例#15
0
    def close(self):
        _last_attacker_id, _last_attacker_name = 0, ''
        if self._last_attackers and self.life <= 0:
            _last_attacker_id, _last_attacker_name = self._last_attackers[-1][:2]

        _cids = yield redis.zrange(RANK_WORLDBOSS_DAMAGE, 0, 3)
        if not _cids: defer.returnValue(None) #没有一个人杀Boss,不算拉拉拉

        _dict_char_info = yield redis.hmget(DICT_WORLDBOSS_RANKER_DATA, _cids)
        self._char_names_last = [loads(_info)[0] for _info in _dict_char_info if _info]
        _len = len(self._char_names_last)
        if _len < 3:
            for x in xrange(3 - _len):
                self._char_names_last.append('')

        #log.warn('[ ddd ]:_cids:', _cids, '_dict_char_info:', _dict_char_info, '_len:', _len, '_char_names_last:', self._char_names_last)

        for _cid, _attacker in AttackerData._cache.iteritems():
            if _attacker._attack_count > 0:
                _rank = yield _attacker.rank
                reward_golds, reward_farm, last_kill_golds, last_kill_fame = self.reward_to_char(_cid, _last_attacker_id, _rank + 1)

                if _cid in self._attackers:
                    _attacker.reward(self.life, reward_golds, reward_farm, last_kill_golds, last_kill_fame, _last_attacker_name, _rank)

        self._char_name_lastkill = _last_attacker_name

        self.sync()
        res = yield self.current_rank()
        if res != []:
            first_user = g_UserMgr.getUser(res[0][0])
            if first_user:
                msg = [11, [first_user.nick_name, first_user.lead_id]]
                gw_broadcast('sync_broadcast', [[3, msg]])

        log.info('[ CLOSED ]WorldBoss have finished. last kill:', (_last_attacker_id, _last_attacker_name), 'last attackers:', self._last_attackers)
示例#16
0
    def ranklist(self):
        ''' 剧情副本的排行榜 '''
        yield self._load()
        # get myself rank and star
        _my_rank = yield redis.zrank(SET_SCENE_CID_STAR, self.cid)
        _my_rank = 0 if _my_rank is None else int(_my_rank) + 1
        _ranklist = [self.total_star, _my_rank, []]

        _cid_stars = yield redis.zrange(SET_SCENE_CID_STAR,
                                        0,
                                        9,
                                        withscores=True)
        #log.error('For Test. _cid_stars: {0}.'.format( _cid_stars ))
        for _idx, _data in enumerate(_cid_stars):
            if int(_data[1]) >= 0:
                continue
            _detail = yield load_scene_user_data(_data[0])
            if not _detail:
                log.error('Unknown user. cid: {0}.'.format(_data[0]))
                continue
            _detail.extend([-int(_data[1]), _idx + 1])
            _ranklist[2].append(_detail)

        defer.returnValue(_ranklist)
示例#17
0
    def getRoomRanklist(self, room_id, self_uid):
        other_data = list()
        _volume_data = yield redis.zrange(SET_RANK_ROOM_VOLUME%room_id, 0, 5, True)
        _volume_data = _volume_data if _volume_data else list()
        for _rank, (_uid, _volume) in enumerate(_volume_data):
            _machine_code = yield redis.hget(HASH_UID_MACHINE_CODE, _uid)
            _eat_num = yield redis.zscore(SET_RANK_ROOM_EAT%room_id, _uid)
            _eat_num = abs(int(_eat_num)) if _eat_num else 0
            _be_eated_num = yield redis.hget(SET_RANK_ROOM_EATED%room_id, _uid)
            _be_eated_num = abs(int(_be_eated_num)) if _be_eated_num else 0
            other_data.append((_rank+1, _uid, _machine_code, abs(_volume)*10, _eat_num, _be_eated_num))

        _self_rank = yield redis.zrank(SET_RANK_ROOM_VOLUME%room_id, self_uid)
        _self_rank = 0 if _self_rank is None else int(_self_rank) + 1
        _self_volume = yield redis.zscore(SET_RANK_ROOM_VOLUME%room_id, self_uid)
        _self_weight = abs(_self_volume)*10 if _self_volume else 0
        _self_machine_code = yield redis.hget(HASH_UID_MACHINE_CODE, self_uid)
        _self_eat_num = yield redis.zscore(SET_RANK_ROOM_EAT%room_id, self_uid)
        _self_eat_num = abs(int(_self_eat_num)) if _self_eat_num else 0
        _self_be_eated_num = yield redis.hget(SET_RANK_ROOM_EATED%room_id, self_uid)
        _self_be_eated_num = abs(int(_self_be_eated_num)) if _self_be_eated_num else 0
        self_data = (_self_rank, self_uid, _self_machine_code, _self_weight, _self_eat_num, _self_be_eated_num)

        defer.returnValue((other_data, self_data))
示例#18
0
    def ranklist(self):
        ''' 获取天外天的排行榜 '''
        yield self.load()
        # get myself rank and layer
        _my_rank = yield redis.zrank(SET_CLIMBING_CID_LAYER, self.cid)
        _my_rank = 0 if _my_rank is None else int(_my_rank) + 1
        _ranklist = [self.climbing.max_layer, _my_rank, []]

        _cid_layers = yield redis.zrange(SET_CLIMBING_CID_LAYER,
                                         0,
                                         9,
                                         withscores=True)
        for _idx, _data in enumerate(_cid_layers):
            #log.error('For Test. _idx: {0}, _cid_layers: {1}.'.format( _idx+1, _data ))
            if int(_data[1]) >= 0:
                continue
            _detail = yield load_climbing_user_data(_data[0])
            if not _detail:
                log.error('Unknown user. cid: {0}.'.format(_data[0]))
                continue
            _detail.extend([-int(_data[1]), _idx + 1])
            _ranklist[2].append(_detail)

        defer.returnValue(_ranklist)