Exemplo n.º 1
0
    def onChargeNotify(cls, event):
        '''
        充值监听,监听并更新排行和redis记录的RMB,过期不会监听
        '''
        userId = event.userId

        ftlog.debug("DumplingHandler.onChargeNotify: "
                    "userId=", userId, "isOutdate=", DumplingsUtil.isOutdate())

        if DumplingsUtil.isOutdate():
            return

        clientGameId = strutil.getGameIdFromHallClientId(event.clientId)
        if clientGameId not in [6, 7]:
            return

        DumplingsUtil.updateRankingStatus(userId)  # 若排行榜重置,则重置积分记录

        rediskey = DumplingsUtil.getRedisKey()
        jsondict = Redis.readJson(userId, rediskey)

        rmb_count = 0
        if jsondict:
            rmb_count = jsondict.get("rmb", 0)
        rmb_count = rmb_count + (event.rmbs or 0)

        jsondict['rmb'] = rmb_count
        Redis.writeJson(userId, rediskey, jsondict)

        DumplingsUtil.updateRankScore(userId, event.timestamp)
        ftlog.debug("DumplingHandler.onChargeNotify: userId=", userId,
                    "event=", event, "jsondict=", jsondict)
Exemplo n.º 2
0
    def onSkillScoreIncrease(cls, event):
        '''
        大师分增加监听,监听并更新排行,过期不会监听
        '''
        userId = event.userId

        ftlog.debug("DumplingHandler.onSkillScoreIncrease: "
                    "userId=", userId, "isOutdate=", DumplingsUtil.isOutdate())
        if DumplingsUtil.isOutdate():
            return
        DumplingsUtil.updateRankingStatus(userId)  # 若排行榜重置,则重置积分记录

        incr = event.newScore - event.oldScore
        rediskey = DumplingsUtil.getRedisKey()
        jsondict = Redis.readJson(userId, rediskey)

        dashifen_count = 0
        if jsondict:
            dashifen_count = jsondict.get("dashifen", 0)
        dashifen_count = dashifen_count + (incr or 0)

        jsondict['dashifen'] = dashifen_count
        Redis.writeJson(userId, rediskey, jsondict)

        DumplingsUtil.updateRankScore(userId, event.timestamp)
        ftlog.debug("DumplingHandler.onSkillScoreIncrease: "
                    "userId=", userId, "event=", event)
Exemplo n.º 3
0
 def setUserActivityData(cls, bankId, userId, data):
     '''
     存储玩家活动记录数据,存储在db7/db8中的gamedata:6:userId中
     '''
     conf = ConfigDatabase.getServerConfig(bankId)
     activity_start = conf.get('start')
     key = cls.getGamedataKey(bankId,
                              Tool.datetimeFromString(activity_start))
     Redis.writeJson(userId, key, data)
Exemplo n.º 4
0
 def markGet(self, userId, datetime, assets):
     '''
     记录领取红包
     :param datetime: 标记的领取红包的时间点
     '''
     rediskey = self.getRedisKey()
     dictobj = Redis.readJson(userId, rediskey)
     key = "get.%s" % str(datetime)
     Tool.dictSet(dictobj, key, assets)
     Redis.writeJson(userId, rediskey, dictobj)
     ftlog.debug("DataWrapper.makeGet: userId=", userId, "key=", key,
                 "datetime=", str(datetime), "dictobj=", dictobj)
Exemplo n.º 5
0
    def updateRankingStatus(cls, userId):
        '''
        查看是否
        [redis gametable]
        {
            'rankissue' : '20160125',
            'dashifen':10,
            'rmb':11
        }
        '''
        key = cls.getRedisKey()
        user_props = Redis.readJson(userId, key)

        rankingId = cls.getRankingId()
        ftlog.debug("DumplingsUtil.updateRankingStatus", "userId=", userId,
                    "rankingId=", rankingId)
        if not rankingId:
            return

        rankingIssueNumber = user_props.get('rankissue')
        currentRankingIssueNumber = cls.getCurrentRankingIssueNumber()
        ftlog.debug("DumplingsUtil.updateRankingStatus", "userId=", userId,
                    "currentRankingIssueNumber=", currentRankingIssueNumber,
                    "rankingIssueNumber=", rankingIssueNumber, "equal=",
                    currentRankingIssueNumber == rankingIssueNumber)
        if not currentRankingIssueNumber or currentRankingIssueNumber == rankingIssueNumber:
            return

        user_props['rankissue'] = currentRankingIssueNumber
        userRankingInfo = hallranking.rankingSystem._rankingDao.getUserRankWithScore(
            rankingId, currentRankingIssueNumber, userId)
        rankNumber = -1
        if userRankingInfo and userRankingInfo[0] != None:
            rankNumber = userRankingInfo[0] + 1
        # history_dict = user_props.get('history', {})
        # history_dict[currentRankingIssueNumber] = {
        #     'dashifen':user_props.get('dashifen', 0),
        #     'rmb': user_props.get('rmb', 0),
        #     'rankNumber': rankNumber
        # }

        ## online logging
        ftlog.info("DdzDumplings.Ranking.Number,", "userId ", userId,
                   "issueNumber ", str(currentRankingIssueNumber),
                   "rankNumber " + str(rankNumber),
                   "dashifen " + str(user_props.get('dashifen', 0)),
                   "rmb " + str(user_props.get('rmb', 0)))
        ## 重置数据
        user_props['dashifen'] = 0
        user_props['rmb'] = 0
        Redis.writeJson(userId, key, user_props)
        ftlog.debug("DumplingsUtil.updateRankingStatus: "
                    "userId=", userId, "user_props=", user_props)
Exemplo n.º 6
0
def sendUserVipBenefits(userId, roomId, minRoomLevel, sendCount, chip):
    if minRoomLevel < 1 or sendCount <= 0:
        return False

    ## room level limit
    bigroomId = gdata.getBigRoomId(roomId)
    roomconf = gdata.getRoomConfigure(bigroomId)
    if not roomconf:
        return False
    roomlevel = roomconf.get('roomLevel', 1)
    if roomlevel < minRoomLevel:
        ftlog.debug('sendUserVipBenefits: roomlevel', 'userId=', userId,
                    'roomlevel=', roomlevel, 'minRoomLevel=', minRoomLevel)
        return False

    ## send number limit
    rediskey = 'vip.benefits'
    data = Redis.readJson(userId, rediskey)
    timestamp = data.get('timestamp', 0)
    counter = data.get('counter', 0)

    now = datetime.datetime.now()
    last = datetime.datetime.fromtimestamp(timestamp)
    if last.year != now.year or last.month != now.month or last.day != now.day:
        counter = 0

    if counter >= sendCount:
        ftlog.debug('sendUserVipBenefits: sendCount', 'userId=', userId,
                    'sendCount=', sendCount, 'counter=', counter)
        return False

    data['counter'] = counter + 1
    data['timestamp'] = Tool.datetimeToTimestamp(now)

    Redis.writeJson(userId, rediskey, data)
    UserInfo.incrChip(userId, 6, chip, 'BENEFITS_VIP_SEND')

    ftlog.debug('sendUserVipBenefits:', 'userId=', userId, 'counter=',
                data['counter'], 'chip=', chip)
    return True
Exemplo n.º 7
0
    def _creditTypeSendRewardsIfNeed(cls, userId):
        '''
        积分发奖类型,当积分达到发奖值后,自动发奖(仅供积分发奖类型使用:"rewardsType": "credit")
        '''
        actconf = DumplingsUtil.getActivityConf()
        isRanking = Tool.dictGet(actconf, 'config.activate.rewardsType',
                                 'credit') == 'ranking'
        if isRanking:
            return
        rediskey = cls.getRedisKey()
        mail = Tool.dictGet(actconf, 'config.activate.mail')
        reward = Tool.dictGet(actconf, 'config.activate.credit.rewards')
        jsondict = Redis.readJson(userId, rediskey)

        helper = CreditRewardHelper(userId, reward)
        reachedlist = helper.getReachedConfList()  # 达到发奖条件的所有奖励配置的list
        getlist = jsondict.get('getlist',
                               [])  # 已经领取的奖励list,使用score字段记录,score字段值不可重复

        for item in reachedlist:
            for assets in item.get('items'):
                if item['score'] not in getlist:
                    getlist.append(item['score'])
                    ranking_num = cls.getRankingWithUserId(userId)
                    mailstr = strutil.replaceParams(mail, {
                        'assets': item.get('desc'),
                        'ranking_num': ranking_num
                    })
                    UserBag.sendAssetsToUser(6, userId, assets,
                                             'DDZ_ACT_DUMPLINGS', mailstr)

        # 记录奖励已经领取
        jsondict['getlist'] = getlist
        Redis.writeJson(userId, rediskey, jsondict)
        ftlog.debug("DumplingsUtil.creditTypeSendRewardsIfNeed: userId=",
                    userId, "jsondict=", jsondict)
Exemplo n.º 8
0
 def resetCounting(cls, userId):
     '''
     重置计时器到当前时间
     '''
     data = {'timestamp': Tool.datetimeToTimestamp(datetime.now())}
     Redis.writeJson(userId, cls.countingTimerUniqueKey, data)