예제 #1
0
def check_grant_items(cid, user):
    ''' 检查是否有全服发放的道具可领, 有时发放到领奖中心
    '''
    _register_ts    = datetime2time( user.base_att.register_time )
    _grant_keys_got = yield redis.smembers( SET_GOT_GRANT_KEYS%cid )

    _all_grants = yield redis.hgetall( HASH_GM_GRANT_ITEMS )
    if not _all_grants:
        defer.returnValue( NO_ERROR )

    for _grant_key, _grant_info in _all_grants.iteritems():
        _grant_key = int(_grant_key)
        # 判断注册时间点是否在发送道具时间点之后
        if _register_ts and _grant_key < _register_ts:
            continue
        if _grant_key in _grant_keys_got:
            continue
        # 检查时间是否过期, 14天
        if check_valid_time(_grant_key, hour=AWARD_VALID_HOURS):
            yield redis.hdel( HASH_GM_GRANT_ITEMS, _grant_key )
            continue
        # _grant_info=[玩家cid列表, 发放的道具, 过期时间戳]
        _grant_info = loads(_grant_info)
        if not _grant_info[0] or cid in _grant_info[0]:
            yield redis.sadd( SET_GOT_GRANT_KEYS%cid, _grant_key )
            yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_GM, [_grant_key, _grant_info[1]], flag=False )
 
    defer.returnValue( NO_ERROR )
예제 #2
0
    def get_group_buy_info(self):
        _infos = yield redis.hgetall(DICT_GROUP_BUY_INFO)
        if not _infos:
            _group_buy_info = {1:0,2:0,3:0,4:0}  #buy_type:buy_num
            for buy_type in xrange(1,5):
                yield redis.hset(DICT_GROUP_BUY_INFO, buy_type, dumps(_group_buy_info[buy_type]))
        else:
            _group_buy_info = dict()
            for k, v in _infos.iteritems():
                _group_buy_info[k] = loads(v)

        _res = []
        _ret = []
        for _buy_type, _bought_num in _group_buy_info.iteritems():
           _res.append([_buy_type, _bought_num])

        _stream = yield redis.hget(DICT_GROUP_BUY_PERSON_INFO, self.cid)#[[buy_count, [status,2,3,4]],..]
        if _stream:
            try:
                _data = loads(_stream)
                if _data:
                    # [bought_count, [0,0,0,0]]
                    for _bought_count_info, _info in zip(_data, _res):
                        _info.append(_bought_count_info)
                        _ret.append(_info)
            except:
                log.exception()
        else:
            _value = [[0,[0,0,0,0]]] * 4
            yield redis.hset(DICT_GROUP_BUY_PERSON_INFO, self.cid, dumps(_value))
            for _info in _res:
                _info.append([0,[0,0,0,0]])
                _ret.append(_info)
        defer.returnValue( _ret )
예제 #3
0
    def get_all_rank_detail(self, flag=True):
        _data = []
        _all_details = yield redis.hgetall( HASH_ARENA_RANK )
        if not _all_details:
            defer.returnValue( _data )

        for rank, _detail in _all_details.iteritems():
            _detail = loads(_detail)
            if _detail[0] <= 0:
                continue

            if len(_detail) == 7:
                _detail.append( 0 )
            # 获取排名对应的奖励 及 阵容详情
            if flag:
                _detail[4], _detail[5] = self.get_rank_award( rank )
                # 排名上是个玩家, 加载玩家阵容
                if _detail[0] > 0:
                    major_level, fellow_ids, lead_id = yield load_offline_user_info(_detail[0])
                    if fellow_ids:
                        _detail[1] = major_level if major_level else _detail[1]
                        _detail[6] = fellow_ids
                        _detail[7] = lead_id
                else:
                    robot_conf = get_arena_robot_rank( rank )
                    _fellow_ids = map(int, robot_conf['RobotList'].split(','))
                    _detail[1], _detail[2], _detail[6] = robot_conf['RobotLevel'], robot_conf['RobotName'], _fellow_ids
            _data.append( (rank, _detail) )
 
        defer.returnValue( _data )
예제 #4
0
def gm_character_status(cmd, ts, args, sign):
    ''' 查询服务器上的封号&禁言玩家 
    @param: type 1-封号 2-禁言
    '''
    res_err = {'result': 1, 'character_ids': []}

    if len(args) != 1:
        res_err['result'] = GM_INVALID_ARGS
        defer.returnValue( res_err )

    _type = int(args['query_type'])
    _time_now = int(time())
    if _type == TYPE_FORBIDDEN:
        _all_datas = yield redis.hgetall( HASH_SERVER_FORBIDDEN )
        if not _all_datas:
            defer.returnValue( res_err )

        for _cid, _end_timestamp in _all_datas.iteritems():
            _temp = {'character_id': _cid, 'seconds': 0}
            if _end_timestamp < 0:
                _temp['seconds'] = -1
            elif _end_timestamp > _time_now:
                _temp['seconds'] = _end_timestamp - _time_now
            else:
                continue
            res_err['character_ids'].append( _temp )
    elif _type == TYPE_MUTE:
        _all_datas = yield redis.hgetall( HASH_SERVER_MUTE )
        if not _all_datas:
            defer.returnValue( res_err )

        for _cid, _end_timestamp in _all_datas.iteritems():
            _temp = {'character_id': _cid, 'seconds': 0}
            if _end_timestamp < 0:
                _temp['seconds'] = -1
            elif _end_timestamp > _time_now:
                _temp['seconds'] = _end_timestamp - _time_now
            else:
                continue
            res_err['character_ids'].append( _temp )
    else:
        res_err['result'] = GM_INVALID_ARGS
        defer.returnValue( res_err )

    defer.returnValue( res_err )
예제 #5
0
def gm_character_status(cmd, ts, args, sign):
    ''' 查询服务器上的封号&禁言玩家 
    @param: type 1-封号 2-禁言
    '''
    res_err = {'result': 1, 'character_ids': []}

    if len(args) != 1:
        res_err['result'] = GM_INVALID_ARGS
        defer.returnValue(res_err)

    _type = int(args['query_type'])
    _time_now = int(time())
    if _type == TYPE_FORBIDDEN:
        _all_datas = yield redis.hgetall(HASH_SERVER_FORBIDDEN)
        if not _all_datas:
            defer.returnValue(res_err)

        for _cid, _end_timestamp in _all_datas.iteritems():
            _temp = {'character_id': _cid, 'seconds': 0}
            if _end_timestamp < 0:
                _temp['seconds'] = -1
            elif _end_timestamp > _time_now:
                _temp['seconds'] = _end_timestamp - _time_now
            else:
                continue
            res_err['character_ids'].append(_temp)
    elif _type == TYPE_MUTE:
        _all_datas = yield redis.hgetall(HASH_SERVER_MUTE)
        if not _all_datas:
            defer.returnValue(res_err)

        for _cid, _end_timestamp in _all_datas.iteritems():
            _temp = {'character_id': _cid, 'seconds': 0}
            if _end_timestamp < 0:
                _temp['seconds'] = -1
            elif _end_timestamp > _time_now:
                _temp['seconds'] = _end_timestamp - _time_now
            else:
                continue
            res_err['character_ids'].append(_temp)
    else:
        res_err['result'] = GM_INVALID_ARGS
        defer.returnValue(res_err)

    defer.returnValue(res_err)
예제 #6
0
    def award_center_info(self, cid):
        '''
        @summary: 获取玩家的奖励信息
        @param  : 详见redis_data_record.py说明
        '''
        _award_info = []  # 玩家的奖励列表
        _expired_ids = []  # 过期的award_ids
        _all_data = yield redis.hgetall(HASH_AWARD_CENTER % cid)
        if _all_data:
            for _data in _all_data.itervalues():
                _data = loads(_data)
                if len(_data) != 3:
                    continue
                res_err, items_list = get_award_conf(_data[1], *_data[2])
                if res_err:
                    _expired_ids.append(_data[0])
                    continue
                if not items_list:
                    log.error('No conf in award center. cid: {0}, _data: {1}.'.
                              format(cid, _data))
                    continue
                ## 过滤掉天外天中的塔层
                #if _data[1] == AWARD_TYPE_CLIMBING:
                #    _award_info.append( [_data[0], _data[1], [_data[2][0], items_list]] )
                ## 过滤掉VIP福利的VIP Level
                #elif _data[1] == AWARD_TYPE_VIP_WELFARE:
                #    _award_info.append( [_data[0], _data[1], [_data[2][0], items_list]] )
                ## 过滤掉限时神将的活动ID、排名
                #elif _data[1] in [AWARD_TYPE_LIMIT_FELLOW_RANK, AWARD_TYPE_LIMIT_FELLOW_SCORE]:
                #    _award_info.append( [_data[0], _data[1], [_data[2][0], items_list]] )
                ## 过滤掉累计充值、累计消费的活动ID、奖励ID列表
                #elif _data[1] in [AWARD_TYPE_PAY_ACTIVITY, AWARD_TYPE_CONSUME_ACTIVITY]:
                #    _award_info.append( [_data[0], _data[1], [_data[2][0], items_list]] )
                ## 过滤掉每日任务中的奖励档次ID
                #elif _data[1] == AWARD_TYPE_DAILY_QUEST:
                #    _award_info.append( [_data[0], _data[1], [_data[2][0], items_list]] )

                # 组织奖励信息
                if _data[1] in [AWARD_TYPE_CLIMBING, AWARD_TYPE_VIP_WELFARE, AWARD_TYPE_LIMIT_FELLOW_RANK, \
                        AWARD_TYPE_LIMIT_FELLOW_SCORE, AWARD_TYPE_PAY_ACTIVITY, AWARD_TYPE_CONSUME_ACTIVITY, \
                        AWARD_TYPE_DAILY_QUEST, AWARD_TYPE_PAY_LOGIN, AWARD_TYPE_JOUSTRANK, AWARD_TYPE_GROUP_BUY]:
                    _award_info.append(
                        [_data[0], _data[1], [_data[2][0], items_list]])
                elif _data[1] in [
                        AWARD_TYPE_FIRSTPAY, AWARD_TYPE_ARENARANK,
                        AWARD_TYPE_MONTGLY_CARD, AWARD_TYPE_RESOURCE_REWARD
                ]:
                    _data[2].append(items_list)
                    _award_info.append(_data)
                else:  # 不需要任何处理
                    _award_info.append(_data)

        if _expired_ids:
            yield redis.hdel(HASH_AWARD_CENTER % cid, *_expired_ids)
            #log.info('For Test. Del Redis Data. _expired_ids: {0}.'.format( _expired_ids ))

        defer.returnValue(_award_info)
예제 #7
0
def grant_group_buy_award(activity_id,
                          redis_key,
                          award_center_type,
                          timestamp=0):
    log.warn(
        'excite activity award. activity_id: {0}, timestamp: {1}, GROUP_BUY_AWRAD_TIME: {2}.'
        .format(activity_id, timestamp, GROUP_BUY_AWARD_TIME))

    _field = None
    _award_conf = None
    if GROUP_BUY_AWARD_TIME != timestamp:
        defer.returnValue(None)
    if activity_id != EXCITE_GROUP_BUY:
        defer.returnValue(None)
    _all_data = yield redis.hgetall(redis_key)
    if not _all_data:
        defer.returnValue(None)
    _group_buy_info = yield redis.hgetall(DICT_GROUP_BUY_INFO)
    _wlist = list(set(get_group_buy_count()))  #buy_num level
    _gdict = dict()
    #save group_buy activity buy_num
    for k, v in _group_buy_info.iteritems():
        _gdict[k] = loads(v)

    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _args_list = []
        for _index, (_count, _status) in enumerate(_data):
            if _count <= 0:
                break
            _award_ids = []
            for dex, i in enumerate(_status):
                if i == 1 or dex in _award_ids:
                    continue
                if _gdict[_index + 1] >= _wlist[_index] and i == 0:
                    _args_list.append([_index + 1, _wlist[_index + 1]])
                    _award_ids.append(dex)
        if len(_args_list) >= 1:
            yield g_AwardCenterMgr.new_award(
                _cid, award_center_type,
                [int(time()), activity_id, _args_list])

    yield redis.delete(redis_key)
    yield redis.delete(DICT_GROUP_BUY_INFO)
예제 #8
0
def get_current_personal_count(cid, package_id):
    if not DICT_PACKAGE_PERSONAL_COUNTER.has_key(package_id):
        _dict_cnt = yield redis.hgetall(HASH_PACKAGE_PERSONAL_COUNTER % package_id)
        DICT_PACKAGE_PERSONAL_COUNTER[package_id] = {int(k):int(v) for k, v in _dict_cnt.iteritems()}

    _dict_all_cnt = DICT_PACKAGE_PERSONAL_COUNTER[package_id]
    _cnt = _dict_all_cnt.get(cid, None)
    if _cnt is None:
        _cnt = 0
        _dict_all_cnt[cid] = _cnt

    returnValue(_cnt)
예제 #9
0
def mail_list(p, req):
    ''' 分页获取邮件列表 
    page_type: 1:全部; 2:好友; 3:系统; 4:战斗
    '''
    cid, [page_type, index] = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format(cid))
        defer.returnValue(CONNECTION_LOSE)

    user.notify_mail = False

    all_types = []
    now_time = int(time())
    mails_time = []  # for sort
    all_mails = []

    if page_type == MAIL_PAGE_ALL:
        all_types = [MAIL_PAGE_FRIEND, MAIL_PAGE_SYSTEM, MAIL_PAGE_BATTLE]
    else:
        all_types = [page_type]

    for _type in all_types:
        # 每个type 最多保存100条
        del_mail = []  # 已过期的邮件ID
        _all = yield redis.hgetall(HASH_MAIL_CONTENT % (_type, cid))
        for _field, _value in _all.iteritems():
            if _field == MAIL_PRIMARY_INC:
                continue
            _value = loads(_value)

            # 判断邮件是否过期
            if _value[1] + MAIL_VALID_SECONDS < now_time:
                del_mail.append(_field)
                continue
            # 根据时间点先后组织数据
            for _i, _time in enumerate(mails_time):
                if _value[1] > _time:
                    all_mails.insert(_i, _value)
                    break
            else:
                _i = len(mails_time)
                all_mails.append(_value)
            mails_time.insert(_i, _value[1])

        if del_mail:
            yield redis.hdel(HASH_MAIL_CONTENT % (_type, cid), *del_mail)

    defer.returnValue(
        (page_type, index, len(all_mails), all_mails[index:index + 10]))
예제 #10
0
def grant_group_buy_award(activity_id, redis_key, award_center_type, timestamp=0):
    log.warn('excite activity award. activity_id: {0}, timestamp: {1}, GROUP_BUY_AWRAD_TIME: {2}.'.format( activity_id, timestamp,
        GROUP_BUY_AWARD_TIME))

    _field = None
    _award_conf = None
    if GROUP_BUY_AWARD_TIME != timestamp:
        defer.returnValue( None )
    if activity_id != EXCITE_GROUP_BUY:
        defer.returnValue( None )
    _all_data = yield redis.hgetall( redis_key )
    if not _all_data:
        defer.returnValue( None )
    _group_buy_info = yield redis.hgetall( DICT_GROUP_BUY_INFO )
    _wlist = list(set(get_group_buy_count())) #buy_num level
    _gdict = dict()
    #save group_buy activity buy_num
    for k, v in _group_buy_info.iteritems():
        _gdict[k] = loads(v)

    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _args_list = []
        for _index, (_count, _status) in enumerate(_data):
            if _count <= 0:
                break
            _award_ids = []
            for dex, i in enumerate(_status):
                if i == 1 or dex in _award_ids:
                    continue
                if _gdict[_index+1] >= _wlist[_index] and i == 0:
                    _args_list.append([_index+1, _wlist[_index+1]])
                    _award_ids.append(dex)
        if len(_args_list) >= 1:
            yield g_AwardCenterMgr.new_award( _cid, award_center_type, [int(time()), activity_id, _args_list] )

    yield redis.delete( redis_key )
    yield redis.delete( DICT_GROUP_BUY_INFO )
예제 #11
0
def mail_list(p, req):
    ''' 分页获取邮件列表 
    page_type: 1:全部; 2:好友; 3:系统; 4:战斗
    '''
    cid, [page_type, index] = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( CONNECTION_LOSE )

    user.notify_mail = False
 
    all_types  = []
    now_time   = int(time())
    mails_time = [] # for sort
    all_mails  = []

    if page_type == MAIL_PAGE_ALL:
        all_types = [MAIL_PAGE_FRIEND, MAIL_PAGE_SYSTEM, MAIL_PAGE_BATTLE]
    else:
        all_types = [page_type]

    for _type in all_types:
        # 每个type 最多保存100条 
        del_mail   = [] # 已过期的邮件ID
        _all = yield redis.hgetall( HASH_MAIL_CONTENT % (_type, cid) )
        for _field, _value in _all.iteritems():
            if _field == MAIL_PRIMARY_INC:
                continue
            _value = loads(_value)

            # 判断邮件是否过期
            if _value[1] + MAIL_VALID_SECONDS < now_time:
                del_mail.append( _field )
                continue
            # 根据时间点先后组织数据
            for _i, _time in enumerate(mails_time):
                if _value[1] > _time:
                    all_mails.insert(_i, _value)
                    break
            else:
                _i = len(mails_time)
                all_mails.append( _value )
            mails_time.insert(_i, _value[1])

        if del_mail:
            yield redis.hdel( HASH_MAIL_CONTENT % (_type, cid), *del_mail )

    defer.returnValue( (page_type, index, len(all_mails), all_mails[index:index+10]) )
예제 #12
0
def grant_excite_activity_award(activity_id,
                                redis_key,
                                award_center_type,
                                timestamp=0):
    ''' 精彩活动结束时 定时发放未领的奖励到领奖中心 
    @param: activity_id-精彩活动ID
    @param: redis_key-精彩活动对应的redis_key
    @param: award_center_type-领奖中心奖励类型
    @param: timestamp-借用时间戳作为callLater的有效性验证
    '''
    log.warn(
        'excite activity award. activity_id: {0}, timestamp: {1}, ACTIVITY_AWARD_TIME: {2}.'
        .format(activity_id, timestamp,
                (PAY_ACTIVITY_AWARD_TIME, CONSUME_ACTIVITY_AWARD_TIME)))

    _field = None
    _award_conf = None
    # 判断是否是正确的callLater
    if activity_id == EXCITE_PAY_ACTIVITY:
        _field = 'TotalPay'
        _award_conf = get_pay_activity_conf()
        if PAY_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue(None)
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        _field = 'TotalConsume'
        _award_conf = get_consume_activity_conf()
        if CONSUME_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue(None)

    if not _award_conf:
        defer.returnValue(None)

    _all_data = yield redis.hgetall(redis_key)
    if not _all_data:
        defer.returnValue(None)
    # 进领奖中心
    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _award_ids = []
        for _award in _award_conf.itervalues():
            if _award['ID'] in _data[0] or _award['ID'] in _award_ids:
                continue
            if _award[_field] <= _data[1]:
                _award_ids.append(_award['ID'])
                yield g_AwardCenterMgr.new_award(
                    _cid, award_center_type,
                    [int(time()), activity_id, _award['ID']])
    # 删除旧的活动数据
    yield redis.delete(redis_key)
예제 #13
0
    def load_all_alliance(self):
        try:
            all_alliance_streams = yield redis.hgetall(HASH_ALLIANCE_INFO)

            for stream in all_alliance_streams.itervalues():
                _a = yield Alliance.load(stream)
                if not _a:
                    continue
                self.add_alliance(_a)

            _remain = get_reward_timestamp(23, 59, 59) - int(time())
            reactor.callLater(_remain, self.sync_alliance_rank)
        except Exception as e:
            reactor.callLater(1, self.load_all_alliance)
            print 'WARNING. Redis connection fail, callLater 1 second. e:', e
예제 #14
0
    def load_all_alliance( self ):
        try:
            all_alliance_streams = yield redis.hgetall( HASH_ALLIANCE_INFO )

            for stream in all_alliance_streams.itervalues():
                _a = yield Alliance.load( stream )
                if not _a:
                    continue
                self.add_alliance( _a )

            _remain = get_reward_timestamp(23, 59, 59) - int(time())
            reactor.callLater(_remain, self.sync_alliance_rank)
        except Exception as e:
            reactor.callLater(1, self.load_all_alliance)
            print 'WARNING. Redis connection fail, callLater 1 second. e:', e
예제 #15
0
def get_current_personal_count(cid, package_id):
    if not DICT_PACKAGE_PERSONAL_COUNTER.has_key(package_id):
        _dict_cnt = yield redis.hgetall(HASH_PACKAGE_PERSONAL_COUNTER %
                                        package_id)
        DICT_PACKAGE_PERSONAL_COUNTER[package_id] = {
            int(k): int(v)
            for k, v in _dict_cnt.iteritems()
        }

    _dict_all_cnt = DICT_PACKAGE_PERSONAL_COUNTER[package_id]
    _cnt = _dict_all_cnt.get(cid, None)
    if _cnt is None:
        _cnt = 0
        _dict_all_cnt[cid] = _cnt

    returnValue(_cnt)
예제 #16
0
def gm_search_character(cmd, ts, args, sign):
    res_err = {'result': 1, 'character_info': []}

    if len(args) != 1:
        res_err['result'] = GM_INVALID_ARGS
        defer.returnValue(res_err)

    _infos = []
    _target_nickname = args['nick_name']
    _all_datas = yield redis.hgetall(DICT_NICKNAME_REGISTERED)
    pattern = re.compile(_target_nickname)
    for _nickname, _cid in _all_datas.iteritems():
        if not _nickname:
            continue
        if isinstance(_nickname, unicode):
            pass
        elif isinstance(_nickname, str):
            pass
        elif isinstance(_nickname, int):
            _nickname = str(_nickname)
        else:
            log.info('type: {0}.'.format(type(_nickname)))
            continue

        match = pattern.search(_nickname)
        if not match:
            continue
        #else:
        #    log.info('match.group: {0}.'.format( match.group() ))
        #log.info('For Test. _nickname: {0}, _target_nickname: {1}.'.format( _nickname, _target_nickname ))
        _level, _online = 0, 0
        user = g_UserMgr.getUserByCid(_cid)
        if user:
            _level = user.info.get('level', 0)
            _online = 1

        _infos.append({
            'character_id': _cid,
            'nick_name': _nickname,
            'level': _level,
            'online': _online
        })

    res_err['character_info'] = _infos
    defer.returnValue(res_err)
예제 #17
0
    def get_award_center(self, user, get_award_type, award_id):
        '''
        @summary: 领奖
        @param  : get_award_type 1:单次领奖; 2:全部领取;
                  award_id : get_award_type为2时, 此字段无意义
        '''
        items_return = []  # 返回背包的道具信息
        awarded_ids = []  # 已领奖的award_ids
        if get_award_type == 1:  # 单次领奖
            _data = yield redis.hget(HASH_AWARD_CENTER % user.cid, award_id)
            if not _data:
                log.error('Can not find the award. cid:{0}.'.format(user.cid))
                defer.returnValue(REQUEST_LIMIT_ERROR)
            _data = loads(_data)
            if len(_data) != 3:
                log.error('redis data error. cid:{0}, _data:{1}.'.format(
                    user.cid, _data))
                defer.returnValue(UNKNOWN_ERROR)
            awarded_ids.append(_data[0])
            items_return = yield self.get_one_award(user, _data, items_return)

        elif get_award_type == 2:  # 全部领取
            _all_data = yield redis.hgetall(HASH_AWARD_CENTER % user.cid)
            if not _all_data:
                log.error('Can not find the award. cid:{0}.'.format(user.cid))
                defer.returnValue(REQUEST_LIMIT_ERROR)
            for _data in _all_data.itervalues():
                _data = loads(_data)
                if len(_data) != 3:
                    log.error('redis data error. cid:{0}, _data: {1}.'.format(
                        user.cid, _data))
                    continue
                awarded_ids.append(_data[0])
                items_return = yield self.get_one_award(
                    user, _data, items_return)

        if awarded_ids:
            yield redis.hdel(HASH_AWARD_CENTER % user.cid, *awarded_ids)
            #log.info('For Test. get_award_center. Del Redis Data. awarded_ids: {0}.'.format( awarded_ids ))

        defer.returnValue(items_return)
예제 #18
0
def grant_excite_activity_award(activity_id, redis_key, award_center_type, timestamp=0):
    ''' 精彩活动结束时 定时发放未领的奖励到领奖中心 
    @param: activity_id-精彩活动ID
    @param: redis_key-精彩活动对应的redis_key
    @param: award_center_type-领奖中心奖励类型
    @param: timestamp-借用时间戳作为callLater的有效性验证
    '''
    log.warn('excite activity award. activity_id: {0}, timestamp: {1}, ACTIVITY_AWARD_TIME: {2}.'.format( activity_id, timestamp, (PAY_ACTIVITY_AWARD_TIME,CONSUME_ACTIVITY_AWARD_TIME) ))

    _field = None
    _award_conf = None
    # 判断是否是正确的callLater
    if activity_id == EXCITE_PAY_ACTIVITY:
        _field = 'TotalPay'
        _award_conf = get_pay_activity_conf()
        if PAY_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue( None )
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        _field = 'TotalConsume'
        _award_conf = get_consume_activity_conf()
        if CONSUME_ACTIVITY_AWARD_TIME != timestamp:
            defer.returnValue( None )

    if not _award_conf:
        defer.returnValue( None )

    _all_data = yield redis.hgetall( redis_key )
    if not _all_data:
        defer.returnValue( None )
    # 进领奖中心 
    for _cid, _data in _all_data.iteritems():
        _data = loads(_data)
        _award_ids = []
        for _award in _award_conf.itervalues():
            if _award['ID'] in _data[0] or _award['ID'] in _award_ids:
                continue
            if _award[_field] <= _data[1]:
                _award_ids.append( _award['ID'] )
                yield g_AwardCenterMgr.new_award( _cid, award_center_type, [int(time()), activity_id, _award['ID']] )
    # 删除旧的活动数据
    yield redis.delete( redis_key )
예제 #19
0
def get_friend_douzhan_status(cid, add_douzhan=0):
    '''
    @param add_douzhan: 达成好感度成就后新增的领取斗战点次数
    '''
    left_count = GET_DOUZHAN_DAILY_LIMIT + add_douzhan
    gift_data  = []
    dt_now     = datetime.now()

    _all = yield redis.hgetall( HASH_FRIENDS_GIFT_DOUZHAN % cid )
    for _field, _value in _all.iteritems():
        if _field == FRIENDS_DOUZHAN_GET:
            last_time, left_count = loads(_value)
            dt_last = datetime.fromtimestamp( last_time )
            if dt_last.date() != dt_now.date():
                left_count = GET_DOUZHAN_DAILY_LIMIT + add_douzhan
                yield redis.hset( HASH_FRIENDS_GIFT_DOUZHAN % cid, FRIENDS_DOUZHAN_GET, dumps((int(time()), left_count)) )

        else:
            gift_data.append( loads(_value) )

    defer.returnValue( [left_count, gift_data] )
예제 #20
0
def friend_invite(p, req):
    ''' 向玩家发送好友邀请 '''
    cid, [target_cid, content] = req

    user = g_UserMgr.getUser( cid )
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( CONNECTION_LOSE )

    if cid == target_cid:
        defer.returnValue( USER_HAD_YOUR_FRIEND )

    # 已经是好友了
    if target_cid in user.friends:
        log.error('Target user has been your friend. cid: {0}, target_cid:{1}.'.format( cid, target_cid ))
        defer.returnValue( USER_HAD_YOUR_FRIEND )

    # 判断自己的好友人数
    if len(user.friends) >= MAX_FRIENDS_COUNT:
        log.error('User friends count has max. cid: {0}.'.format( cid ))
        defer.returnValue( FRIENDS_COUNT_SELF_ERROR )

    # 已经发送了好友邀请
    _key = HASH_MAIL_CONTENT % (MAIL_PAGE_FRIEND, target_cid)
    _all = yield redis.hgetall( _key )
    for _field, _value in _all.iteritems():
        if _field == MAIL_PRIMARY_INC:
            continue
        _value = loads(_value)
        if _value[3] != MAIL_FRIEND_1:
            continue
        if cid == _value[-1][0] and _value[-1][3] == 1:
            log.error('Target User has been invited. cid: {0}, target_cid: {1}.'.format( cid, target_cid ))
            defer.returnValue( INVITE_FRIEND_REPEAT )
    
    yield user.achievement_mgr.update_achievement_status(20, len(user.friends))
    # 发送邮件给target_cid
    ms_send('write_mail', (target_cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_1, [cid, user.lead_id, user.nick_name, 1, content]))

    defer.returnValue( NO_ERROR )
예제 #21
0
def gm_search_character(cmd, ts, args, sign):
    res_err = {'result': 1, 'character_info': []}

    if len(args) != 1:
        res_err['result'] = GM_INVALID_ARGS
        defer.returnValue( res_err )

    _infos = []
    _target_nickname = args['nick_name']
    _all_datas = yield redis.hgetall(DICT_NICKNAME_REGISTERED)
    pattern = re.compile(_target_nickname)
    for _nickname, _cid in _all_datas.iteritems():
        if not _nickname:
            continue
        if isinstance(_nickname, unicode):
            pass
        elif isinstance(_nickname, str):
            pass
        elif isinstance(_nickname, int):
            _nickname = str(_nickname)
        else:
            log.info('type: {0}.'.format( type(_nickname) ))
            continue

        match = pattern.search(_nickname)
        if not match:
            continue
        #else:
        #    log.info('match.group: {0}.'.format( match.group() ))
        #log.info('For Test. _nickname: {0}, _target_nickname: {1}.'.format( _nickname, _target_nickname ))
        _level, _online = 0, 0
        user = g_UserMgr.getUserByCid( _cid )
        if user:
            _level  = user.info.get('level', 0)
            _online = 1

        _infos.append( {'character_id': _cid, 'nick_name': _nickname, 'level': _level, 'online': _online} )
    
    res_err['character_info'] = _infos
    defer.returnValue( res_err )
예제 #22
0
    def get_group_buy_info(self):
        _infos = yield redis.hgetall(DICT_GROUP_BUY_INFO)
        if not _infos:
            _group_buy_info = {1: 0, 2: 0, 3: 0, 4: 0}  #buy_type:buy_num
            for buy_type in xrange(1, 5):
                yield redis.hset(DICT_GROUP_BUY_INFO, buy_type,
                                 dumps(_group_buy_info[buy_type]))
        else:
            _group_buy_info = dict()
            for k, v in _infos.iteritems():
                _group_buy_info[k] = loads(v)

        _res = []
        _ret = []
        for _buy_type, _bought_num in _group_buy_info.iteritems():
            _res.append([_buy_type, _bought_num])

        _stream = yield redis.hget(DICT_GROUP_BUY_PERSON_INFO,
                                   self.cid)  #[[buy_count, [status,2,3,4]],..]
        if _stream:
            try:
                _data = loads(_stream)
                if _data:
                    # [bought_count, [0,0,0,0]]
                    for _bought_count_info, _info in zip(_data, _res):
                        _info.append(_bought_count_info)
                        _ret.append(_info)
            except:
                log.exception()
        else:
            _value = [[0, [0, 0, 0, 0]]] * 4
            yield redis.hset(DICT_GROUP_BUY_PERSON_INFO, self.cid,
                             dumps(_value))
            for _info in _res:
                _info.append([0, [0, 0, 0, 0]])
                _ret.append(_info)
        defer.returnValue(_ret)