Example #1
0
def addMatchNotify(gameId, userId, matchName, matchDesc, matchIcon, signinFee,
                   timestamp, matchId, notifyType, gameType, matchIndex):
    '''notifyType[1正常2推荐]'''
    matchNotify = {
        'gameId': gameId,
        'gameType': gameType,
        'matchIndex': matchIndex,
        'userId': userId,
        'matchName': matchName,
        'matchDesc': matchDesc,
        'matchIcon': matchIcon,
        'signinFee': signinFee,
        'timestamp': int(timestamp),
        'notifyType': notifyType,
        'uuid': uuid.uuid1().get_hex(),
        'matchId': matchId
    }
    if ftlog.is_debug():
        ftlog.debug('addMatchNotify', 'userId=', userId, 'matchNotify=',
                    matchNotify)
    date = datetime.fromtimestamp(timestamp).strftime('%Y%m%d')
    daobase.executeRankCmd('HSET', notify_match_user_date_key % (userId, date),
                           matchId, strutil.dumps(matchNotify))
    daobase.executeRankCmd('SADD', notify_match_user_zset_key % userId, date)
    msg = MsgPack()
    msg.setCmd('hall')
    msg.setResult('action', 'addMatchNotify')
    msg.setResult('gameId', gameId)
    msg.setResult('userId', userId)
    msg.setResult('matchNotify', matchNotify)
    router.sendToUser(msg, userId)
Example #2
0
def clearAllMatchNotify(userId):
    dateList = daobase.executeRankCmd('SMEMBERS',
                                      notify_match_user_zset_key % userId)
    if dateList and len(dateList) > 0:
        for date in dateList:
            daobase.executeRankCmd('DEL',
                                   notify_match_user_date_key % (userId, date))
    return daobase.executeRankCmd('DEL', notify_match_user_zset_key % userId)
Example #3
0
    def end(self):
        self.endTimer.cancel()
        self._alive = False

        if self.argd['ntimeId'] == NOTIFY_TIME_TIMER_ID:
            daobase.executeRankCmd('HDEL',
                                   notify_timer_key % self.argd['hall'],
                                   self.uuid)
            ftlog.hinfo('HDEL.notify timer', self.argd)

        ftlog.hinfo('Notify.end', self.argd['uuid'])
Example #4
0
    def __buildRankData(self):
        now = time.time()
        if now - self.lastBuildTime < self.BUILD_RANKING_INTERVAL:
            return
        self.lastBuildtime = now

        results = {'roomId': self.bigRoomId}
        results['matchType'] = self.room.matchPlugin.match_room_confs[self.room.bigRoomId].get("matchType", "")
        results['ranks'] = []

        leftPlayers = [(userId, 0) for userId in
                       daobase.executeRankCmd("LRANGE", self.room.matchPlugin.rankingKey(self.bigRoomId), 0, -1)]  # 淘汰的
        if ftlog.is_debug():
            ftlog.debug("get leftPlayers", "|", leftPlayers, caller=self)
        playingPlayersWithScores = list(pairwise(
            daobase.executeRankCmd("ZRANGE", self.room.matchPlugin.playingRankingKey(self.bigRoomId), 0, -1,
                                   'WITHSCORES')))
        if ftlog.is_debug():
            ftlog.debug("get playingPlayersWithScores", "|", playingPlayersWithScores)

        allPlayers = list(reversed(leftPlayers + playingPlayersWithScores))  # 1, 2, ... 最后一名

        if ftlog.is_debug():
            ftlog.debug("get all players", "|", allPlayers)

        self.userRanking = {}
        self.ranks = []
        for i, (userId, tableChip) in enumerate(allPlayers):
            name, purl, photo = self.getUData(userId)
            rankItem = {
                'id': userId,
                'tableChip': tableChip,
                'name': name,
                'purl': purl,
                'head': photo,
                'rank': i + 1,
            }
            if results['matchType'] in ['hunter', 'snowball']:
                self.setHunterInfo(userId, rankItem)
            self.ranks.append(rankItem)
            self.userRanking[userId] = i

        results['totalPlayersNum'] = len(playingPlayersWithScores)
        results['pos'] = 1
        self.rankResults = results

        self.rankResultsForSend = strutil.cloneData(results)
        self.rankResultsForSend['ranks'] = strutil.cloneData(self.ranks[:30])  # 3.6 以前版本,发30个

        self.rankResultsForSend_3_6 = strutil.cloneData(results)
        blank = {'id': 0, 'tableChip': 0, 'name': '', 'purl': '', 'rank': 1}
        self.rankResultsForSend_3_6['ranks'] = strutil.cloneData([blank] + self.ranks[:30])  # 3.6 以后版本,发31个,第一个是自己
Example #5
0
def delHallNotifyInfo(ntimeId, uuid, hall, ntime):
    if ntimeId == NOTIFY_TIME_TIMER_ID:
        dtList = ntime.split('|')
        date = dtList[0]
        mtime = dtList[1]
        if date == getNowDateStr():
            if mtime > getNowTimeStr():
                argd = daobase.executeRankCmd('HGET', notify_timer_key % hall,
                                              uuid)
                if argd:
                    daobase.executeRankCmd('HSET', notify_todaydel_key, uuid,
                                           json.dumps(argd))

        return daobase.executeRankCmd('HDEL', notify_timer_key % hall, uuid)

    elif ntimeId in NOTIFY_TIME_REDIS_KEY_LIST:
        if ntimeId == getNowWeekdayStr() or ntimeId == NOTIFY_TIME_EVERYDAY_ID:
            if ntime > getNowTimeStr():
                argd = daobase.executeRankCmd('HGET',
                                              notify_key % (ntimeId, hall),
                                              uuid)
                if argd:
                    daobase.executeRankCmd('HSET', notify_todaydel_key, uuid,
                                           json.dumps(argd))

        return daobase.executeRankCmd('HDEL', notify_key % (ntimeId, hall),
                                      uuid)

    elif ntimeId == NOTIFY_TIME_ATONCE_ID:
        # 这个分支属于防御性的,因为查询接口没有提供查询立即消息的功能
        ftlog.hinfo('delHallNotifyInfo atonce', ntimeId, uuid, hall, ntime)
        return True

    ftlog.hinfo('delHallNotifyInfo error', ntimeId, uuid, hall, ntime)
    return False
Example #6
0
def clearExpireMatchNotify(userId):
    dateList = daobase.executeRankCmd('SMEMBERS',
                                      notify_match_user_zset_key % userId)
    if dateList and len(dateList) > 0:
        dateList.sort()
        nowDate = getNowDateStr()
        rmList = []
        for date in dateList:
            if date < nowDate:
                rmList.append(date)
                daobase.executeRankCmd(
                    'DEL', notify_match_user_date_key % (userId, date))
        if len(rmList) > 0:
            daobase.executeRankCmd('SREM', notify_match_user_zset_key % userId,
                                   *rmList)
Example #7
0
 def incrMatchScore(self, userId, score):
     '''
     Note: 比赛时间结束后,还会有牌桌未完结,这些牌桌完结后也需要记录成绩。
     '''
     ftlog.debug("<< |userId, self.bigRoomId, score:",
                 userId,
                 self.bigRoomId,
                 score,
                 caller=self)
     rankingKey = self.matchPlugin.rankingKey(self.bigRoomId)
     daobase.executeRankCmd('ZINCRBY', rankingKey, score, userId)
     # 设置比赛结果公布过期时间
     DEFAULT_RESULT_EXPIRE = 12 * 60 * 60
     resultExpire = self.matchConf.get("resultExpire",
                                       DEFAULT_RESULT_EXPIRE)
     daobase.executeRankCmd('EXPIRE', rankingKey, resultExpire)
Example #8
0
    def __onMatchEnd(self):
        mconf = self.matchPlugin.match_room_confs[self.bigRoomId]

        rankinglist = daobase.executeRankCmd("LRANGE", self.matchPlugin.rankingKey(self.bigRoomId), 0, -1)
        getName = lambda userId: userdata.getAttr(userId, 'name')
        rankingListWithName = [(i + 1, userId, getName(userId)) for i, userId in enumerate(reversed(rankinglist))]
        bireport.matchFinish(self.gameId, self.roomId,
                             mconf['start_time'].strftime('%Y-%m-%d_%H:%M:%S_') + str(self.roomId),
                             mconf['name'].replace('\n', ' '),
                             matchTypeId=mconf['match_id'],
                             endTimestamp=time.time(),
                             rewardChip=self.matchCounter['rewardChip'],
                             rewardCoupon=self.matchCounter['rewardCoupon'],
                             rankingList=rankingListWithName,
                             usersLeaveMatchCount=self.matchCounter['usersLeaveMatchCount'],
                             rebuyChip=self.matchCounter['rebuyChip'],
                             addonChip=self.matchCounter['addonChip'],
                             )

        # for check MTT gameEnd
        TYPluginCenter.event(TYPluginUtils.updateMsg(cmd='EV_MATCH_END', params={'room': self}), self.gameId)

        if ftlog.is_debug():
            ftlog.debug("len(self.scheduler.activeTableIds):", len(self.scheduler.activeTableIds), caller=self)

        # 回收决赛桌和异常牌桌
        remainActiveTables = strutil.cloneData(self.scheduler.activeTableIds)
        for activeTableId in remainActiveTables:
            self.scheduler._recycleTable(activeTableId)

        if mconf.get('day1EndConf'):
            self.matchPlugin.saveDay2Players(self)

        self.state = self.MTT_STATE_READY
Example #9
0
def getMatchNotifyList(userId):
    clearExpireMatchNotify(userId)
    matchNotifyList = []
    dateList = daobase.executeRankCmd('SMEMBERS',
                                      notify_match_user_zset_key % userId)
    if dateList and len(dateList) > 0:
        dateList.sort()
        for date in dateList:
            retMatchList = daobase.executeRankCmd(
                'HVALS', notify_match_user_date_key % (userId, date))
            if retMatchList and len(retMatchList) > 0:
                for retMatch in retMatchList:
                    try:
                        match = strutil.loads(retMatch)
                        matchNotifyList.append(match)
                    except:
                        ftlog.warn('getMatchNotifyList json loads error',
                                   'userId=', userId, 'match=', retMatch)
    if ftlog.is_debug():
        ftlog.debug('getMatchNotifyList matchNotifyList=', userId,
                    matchNotifyList)
    return matchNotifyList
Example #10
0
def getHallNotifyInfo(hall):
    retList = []
    # 定时
    notify_timerList = daobase.executeRankCmd('HGETALL',
                                              notify_timer_key % hall)
    if notify_timerList and len(notify_timerList) > 0:
        for i in xrange(len(notify_timerList) / 2):
            argd = json.loads(notify_timerList[i * 2 + 1])
            retList.append(argd)
    # 每日、周一到周日
    for n in NOTIFY_TIME_REDIS_KEY_LIST:
        notify_everydayList = daobase.executeRankCmd('HGETALL',
                                                     notify_key % (n, hall))
        if notify_everydayList and len(notify_everydayList) > 0:
            for i in xrange(len(notify_everydayList) / 2):
                argd = json.loads(notify_everydayList[i * 2 + 1])
                retList.append(argd)

    # 立即消息由于持续时间很短,所以暂时不提供查询功能
    # 可以通过daobase.executeRankCmd("HGETALL", notify_todayadd_key)筛选立即消息,当然还得判断时间有效性
    if ftlog.is_debug():
        ftlog.debug('getHallNotifyInfo hallx', hall, retList)
    return retList
Example #11
0
def update_notify_today_list():
    global notify_today_list
    notify_add = daobase.executeRankCmd('HGETALL', notify_todayadd_key)
    if notify_add and len(notify_add) > 0:
        for i in xrange(len(notify_add) / 2):
            uuid, notify = notify_add[i * 2], notify_add[i * 2 + 1]
            argd = json.loads(notify)
            ntimeId = argd['ntimeId']
            ntime = argd['ntime']
            if ntimeId == NOTIFY_TIME_ATONCE_ID:
                if uuid not in notify_today_list:
                    notify_today_list[uuid] = Notify(argd)
            elif ntimeId == NOTIFY_TIME_TIMER_ID:
                dtList = argd['ntime'].split('|')
                date = dtList[0]
                ntime = dtList[1]
                if date == getNowDateStr():
                    if ntime > getNowTimeStr():
                        if uuid not in notify_today_list:
                            notify_today_list[uuid] = Notify(argd)
            elif ntimeId == NOTIFY_TIME_EVERYDAY_ID:
                if ntime > getNowTimeStr():
                    if uuid not in notify_today_list:
                        notify_today_list[uuid] = Notify(argd)
            else:
                if ntimeId == getNowWeekdayStr():
                    if ntime > getNowTimeStr():
                        if uuid not in notify_today_list:
                            notify_today_list[uuid] = Notify(argd)

    notify_del = daobase.executeRankCmd('HGETALL', notify_todaydel_key)
    if notify_del and len(notify_del) > 0:
        for i in xrange(len(notify_del) / 2):
            uuid = notify_del[i * 2]
            if uuid in notify_today_list:
                if notify_today_list[uuid].argd['rmTag'] != 1:
                    notify_today_list[uuid].rmTag()
Example #12
0
    def doMatchEnd(self):
        ftlog.info("<< |roomId:", self.roomId, caller=self)

        # TODO: 向所有人发送 todotask,提示比赛已结束

        rankingKey = self.matchPlugin.rankingKey(self.bigRoomId)
        # 更新翅膀,发奖励
        userIds = daobase.executeRankCmd('ZREVRANGE', rankingKey, 0, -1)
        self.matchPlugin.rewardUsers(userIds, self)

        # 重新计算比赛时间
        self.matchPlugin.refreshMatchStartTime(
            self.bigRoomId, self.matchConf["openTime"].get("minutes", 60))
        endTimestamp = self.matchPlugin.match_room_confs[
            self.bigRoomId]["end_timestamp"]
        FTTimer(endTimestamp - int(time.time()) + 5, self._checkMatchEnd)
Example #13
0
    def getPlayingLen(self):
        """由于playing 列表有未知问题,改用enterMatchTotal - rankingLen来反推,并报异常方便查错。
        """
        # 这种方式比分别访问3次 redis 快3倍左右。访问3次redis需要将近1秒
        playingLen, rankingLen, enterMatchTotal = daobase.executeRankCmd("EVALSHA", self.getPlayinLenLuaSha, 0)

        if playingLen + rankingLen != enterMatchTotal:
            ftlog.error(getMethodName(), "playingLen + rankingLen != enterMatchTotal",
                        "|roomId, playingLen, rankingLen:", self.roomId, playingLen, rankingLen,
                        "|enterMatchTotal:", enterMatchTotal)

        if ftlog.is_debug():
            ftlog.info(">>", "|roomId, playingLen, rankingLen:", self.roomId, enterMatchTotal - rankingLen, rankingLen,
                       caller=self)

        return enterMatchTotal - rankingLen
Example #14
0
 def removeRankingList(self, rankingId, issueNumber):
     '''
     删除raking榜单
     '''
     rankingListKey = 'ranking.list:%s:%s' % (rankingId, issueNumber)
     daobase.executeRankCmd('del', rankingListKey)
Example #15
0
 def saveRankingStatusData(self, rankingId, data):
     '''
     保存ranking信息
     '''
     daobase.executeRankCmd('set', 'ranking.status:%s' % (rankingId), data)
Example #16
0
 def removeRankingStatus(self, rankingId):
     '''
     删除ranking信息
     '''
     daobase.executeRankCmd('del', 'ranking.status:%s' % (rankingId))
Example #17
0
 def loadRankingStatusData(self, rankingId):
     '''
     加载ranking信息
     '''
     return daobase.executeRankCmd('get', 'ranking.status:%s' % (rankingId))
Example #18
0
    def __leaveMatch(self, userId, tableId=0, needSendRewardTodoTask=True):

        playingLen, rankingLen, enterMatchTotal, isSuccess = daobase.executeRankCmd("EVALSHA", self.userLeaveLuaSha, 0,
                                                                                    userId)
        ftlog.hinfo("__leaveMatch remove user from playingRanking", "|roomId, userId, state", self.roomId, userId,
                    self.getStateStr(),
                    "|playingLen, rankingLen, enterMatchTotal, isSuccess", playingLen, rankingLen, enterMatchTotal,
                    isSuccess,
                    "|tableId, needSendRewardTodoTask", tableId, needSendRewardTodoTask, caller=self)

        # isSuccess 表示成功从 ranking 中删除。加这个检查是为了避免玩家被动离开的同时主动离开,导致二次发奖
        if not isSuccess:
            return

        if playingLen + rankingLen != enterMatchTotal:
            ftlog.error(getMethodName(), "playingLen + rankingLen != enterMatchTotal",
                        "|roomId, playingLen, rankingLen:", self.roomId, playingLen, rankingLen,
                        "|enterMatchTotal:", enterMatchTotal)

        ftlog.hinfo("__leaveMatch |roomId, playingLen, rankingLen:", self.roomId, enterMatchTotal - rankingLen,
                    rankingLen, caller=self)

        playingLen = enterMatchTotal - rankingLen

        if ftlog.is_debug():
            ftlog.debug("|roomId, playingLen:", self.roomId, playingLen, caller=self)
        func = functools.partial(self.ranking.sendToAll)
        FTTimer(1, func)

        if playingLen < 1:  # 第一名离桌
            return

        # 奖励2到n名
        rankingOrder = playingLen + 1
        self.matchPlugin.rewardWinner(None, self, userId, rankingOrder, self.matchPlugin.rankingKey(self.bigRoomId),
                                      self.matchCounter,
                                      tableId, needSendRewardTodoTask)

        TYPluginCenter.event(TYPluginUtils.updateMsg(cmd='EV_USER_MATCH_END', params={
            'userId': userId, 'room': self, 'rankingOrder': rankingOrder}), self.gameId)

        mconf = self.matchPlugin.match_room_confs[self.bigRoomId]
        day1EndConf = mconf.get('day1EndConf')
        if day1EndConf:
            endPlayerN = day1EndConf.get("endPlayerN", 1)
            if (self.state == self.MTT_STATE_QUALIFIER and playingLen <= endPlayerN
                and mconf['betConfIndex'] >= mconf.get("delaySigninBlindBetPoint", 0)):
                self.state = self.MTT_STATE_DAY1_END
                ftlog.hinfo("__leaveMatch turn to MTT_STATE_DAY1_END |roomId, playingLen, state:",
                            self.roomId, playingLen, self.getStateStr(), caller=self)
                self.scheduler.cancelLoop()
                self.matchPlugin.notifyDay1MatchEndWithPlayerN(self)
        else:
            if self.state == self.MTT_STATE_QUALIFIER and playingLen <= self.tableConf["maxSeatN"]:
                self.state = self.MTT_STATE_PREFINALS
                ftlog.hinfo("__leaveMatch turn to MTT_STATE_PREFINALS |roomId, playingLen, state:",
                            self.roomId, playingLen, self.getStateStr(), caller=self)
                self.scheduler.cancelLoop()

        if playingLen > 1:
            return

        # 奖励第一名
        userId = daobase.executeRankCmd("ZRANGE", self.matchPlugin.playingRankingKey(self.bigRoomId), -1, -1)[0]
        daobase.executeRankCmd("EVALSHA", self.userLeaveLuaSha, 0, userId)

        # 要让第一名leave,否则拆桌时会被加回队列,如果玩家强退并等到loc清除后上线,就会导致下一场比赛人数多出1人
        func = functools.partial(self._leave, userId, TYRoom.LEAVE_ROOM_REASON_MATCH_END, needSendRes=False)
        FTTimer(0, func)  # 异步执行,否则GT会死锁

        ftlog.hinfo("__leaveMatch remove user from playingRanking,", "|roomId, userId", self.roomId, userId,
                    caller=self)
        rankingOrder = 1
        self.matchPlugin.rewardWinner(None, self, userId, rankingOrder, self.matchPlugin.rankingKey(self.bigRoomId),
                                      self.matchCounter, tableId=0)

        TYPluginCenter.event(TYPluginUtils.updateMsg(cmd='EV_USER_MATCH_END', params={
            'userId': userId, 'room': self, 'rankingOrder': rankingOrder}), self.gameId)

        self.state = self.MTT_STATE_IDLE
        func2 = functools.partial(self.__onMatchEnd)
        FTTimer(0, func2)  # 异步执行,否则GT会死锁
Example #19
0
 def loadRankingStatusData(self, rankingId):
     '''
     加载ranking信息
     '''
     return daobase.executeRankCmd('get', 'ranking.status:%s' % (rankingId))
Example #20
0
 def removeRankingStatus(self, rankingId):
     '''
     删除ranking信息
     '''
     daobase.executeRankCmd('del', 'ranking.status:%s' % (rankingId))
Example #21
0
 def saveRankingStatusData(self, rankingId, data):
     '''
     保存ranking信息
     '''
     daobase.executeRankCmd('set', 'ranking.status:%s' % (rankingId), data)
Example #22
0
def initNotifyFromRedis():
    global notify_today_list
    notify_today_list = {}
    serverType = gdata.serverType()

    if serverType == gdata.SRV_TYPE_CENTER:
        # 清空今日通知Redis
        # 新通知
        daobase.executeRankCmd('DEL', notify_todayadd_key)
        # 新删除
        daobase.executeRankCmd('DEL', notify_todaydel_key)

        for hall in hallidList:
            # 定时
            notify_timerList = daobase.executeRankCmd('HGETALL',
                                                      notify_timer_key % hall)
            if notify_timerList and len(notify_timerList) > 0:
                hremList = []
                for i in xrange(len(notify_timerList) / 2):
                    uuid, notify_timer = notify_timerList[
                        i * 2], notify_timerList[i * 2 + 1]
                    argd = json.loads(notify_timer)
                    dtList = argd['ntime'].split('|')
                    date = dtList[0]
                    ntime = dtList[1]
                    if date == getNowDateStr():
                        if ntime <= getNowTimeStr():
                            hremList.append(uuid)
                    elif date < getNowDateStr():
                        hremList.append(uuid)

                if len(hremList) > 0:
                    daobase.executeRankCmd('HDEL', notify_timer_key % hall,
                                           hremList)

    elif serverType == gdata.SRV_TYPE_UTIL:
        for hall in hallidList:
            # 定时
            notify_timerList = daobase.executeRankCmd('HGETALL',
                                                      notify_timer_key % hall)
            if notify_timerList and len(notify_timerList) > 0:
                for i in xrange(len(notify_timerList) / 2):
                    uuid, notify_timer = notify_timerList[
                        i * 2], notify_timerList[i * 2 + 1]
                    argd = json.loads(notify_timer)
                    dtList = argd['ntime'].split('|')
                    date = dtList[0]
                    ntime = dtList[1]
                    if date == getNowDateStr():
                        if ntime > getNowTimeStr():
                            notify_today_list[argd['uuid']] = Notify(argd)

            # 每天
            notify_everydayList = daobase.executeRankCmd(
                'HGETALL', notify_key % ('0', hall))
            if notify_everydayList and len(notify_everydayList) > 0:
                for i in xrange(len(notify_everydayList) / 2):
                    argd = json.loads(notify_everydayList[i * 2 + 1])
                    if argd['ntime'] <= getNowTimeStr():
                        continue

                    notify_today_list[argd['uuid']] = Notify(argd)

            # 周几
            notify_weekdayList = daobase.executeRankCmd(
                'HGETALL', notify_key % (getNowWeekdayStr(), hall))
            if notify_weekdayList and len(notify_weekdayList) > 0:
                for i in xrange(len(notify_weekdayList) / 2):
                    argd = json.loads(notify_weekdayList[i * 2 + 1])
                    if argd['ntime'] <= getNowTimeStr():
                        continue

                    notify_today_list[argd['uuid']] = Notify(argd)

    for key in notify_today_list:
        ftlog.hinfo('_initialize.Notify:', key, notify_today_list[key])
Example #23
0
 def removeRankingList(self, rankingId, issueNumber):
     '''
     删除raking榜单
     '''
     rankingListKey = 'ranking.list:%s:%s' % (rankingId, issueNumber)
     daobase.executeRankCmd('del', rankingListKey)
Example #24
0
def addNotifyInfo(typeId,
                  ntimeId,
                  ntime,
                  iconAddr,
                  context,
                  passthrough,
                  platform,
                  buttonType,
                  hall,
                  gameId,
                  package,
                  userId,
                  timelimit,
                  mapArgs=None):
    '''
    typeId 发送类型 1公告通知 2消息通知 3系统推送 必须选一个,没有默认
    ntimeId 发送时间 -2立即、-1定时、0每天、1周一、2周二、3周三、4周四、5周五、6周六、7周日 必须选一个,没有默认
    ntime 时间12:35 如果是ntimeId-2立即 可以不填 ,ntimeId-1定时 20170822|12:35,其他的 ntimeId,必须填一个时间,没有默认
    iconAddr 路径 必须填,没有默认
    context 文本内容 存文本 不超过50字 必须填,没有默认
    passthrough 透传消息,json{todotask} 可以不填,默认为空字符串
    platform 1 ios、2 android 必须选一个,没有默认
    buttonType 按钮类型 1确定 2忽略+前往  不选 默认确定
    hall 不需要手动填写的,根据用户权限给分配, 例如:'hall6', 'hall30'
    gameId 插件gameId  比如斗地主大厅的'30'插件,  不选发送所有插件,不填就是空字符串
    package 多个clientId,以 | 分割 'clientId1|clientId2|' 例如'Android_4.56_tyGuest,weixinPay,tyAccount.yisdkpay,alipay.0-hall6.baidusearch.tu|
    Ios_4.56_tyGuest,weixinPay,tyAccount.yisdkpay,alipay.0-hall6.baidusearch.tu' 不填就是空字符串
    userId 不填发送给所有的用户 'userId1|userId2|' 例如 '123456|78923' 不填就是空字符串
    '''
    if not check(typeId, ntimeId, ntime, iconAddr, context, passthrough,
                 platform, buttonType, hall, gameId, package, userId,
                 timelimit):
        ftlog.hinfo('addNotifyInfo check error')
        return False

    argd = {
        'typeId': typeId,
        'ntimeId': ntimeId,
        'ntime': ntime,
        'iconAddr': iconAddr,
        'context': context,
        'passthrough': passthrough,
        'platform': platform,
        'buttonType': buttonType,
        'hall': hall,
        'gameId': gameId,
        'package': package,
        'userId': userId,
        'uuid': uuid.uuid1().get_hex(),
        'createTime': int(time.time()),
        'rmTag': 0,
        'timelimit': timelimit
    }

    if mapArgs:
        argd.update(mapArgs)

    ftlog.hinfo('addNotifyInfo mapargs, argd', mapArgs, argd)

    if ntimeId == NOTIFY_TIME_ATONCE_ID:
        daobase.executeRankCmd('HSET', notify_todayadd_key, argd['uuid'],
                               json.dumps(argd))
        ftlog.hinfo('addNotifyInfo atonce ntimeId -2', ntimeId, argd)
    elif ntimeId == NOTIFY_TIME_TIMER_ID:
        daobase.executeRankCmd('HSET', notify_timer_key % hall, argd['uuid'],
                               json.dumps(argd))
        ftlog.hinfo('addNotifyInfo timer ntimeId -1', ntimeId, argd)
        dtList = ntime.split('|')
        date = dtList[0]
        if date == getNowDateStr():
            daobase.executeRankCmd('HSET', notify_todayadd_key, argd['uuid'],
                                   json.dumps(argd))
            ftlog.hinfo('addNotifyInfo timeradd ntimeId -1', ntimeId, argd)

    elif ntimeId == NOTIFY_TIME_EVERYDAY_ID:
        daobase.executeRankCmd('HSET', notify_key % (ntimeId, hall),
                               argd['uuid'], json.dumps(argd))
        ftlog.hinfo('addNotifyInfo everyday ntimeId 0', ntimeId, argd)
        if ntime <= getNowTimeStr():
            ftlog.hinfo('notify everyday ntime over', typeId, ntimeId, ntime,
                        iconAddr, context, passthrough, platform, buttonType,
                        hall, gameId, package, userId)
        else:
            daobase.executeRankCmd('HSET', notify_todayadd_key, argd['uuid'],
                                   json.dumps(argd))
            ftlog.hinfo('addNotifyInfo everydayadd ntimeId 0', ntimeId, argd)
    else:
        daobase.executeRankCmd('HSET', notify_key % (ntimeId, hall),
                               argd['uuid'], json.dumps(argd))
        ftlog.hinfo('addNotifyInfo weekday ntimeId 1-7', ntimeId, argd)
        if ntimeId == getNowWeekdayStr():
            if ntime <= getNowTimeStr():
                ftlog.hinfo('notify weekday ntime over', typeId, ntimeId,
                            ntime, iconAddr, context, passthrough, platform,
                            buttonType, hall, gameId, package, userId)
            else:
                daobase.executeRankCmd('HSET', notify_todayadd_key,
                                       argd['uuid'], json.dumps(argd))
                ftlog.hinfo('addNotifyInfo weekdayadd ntimeId 1-7', ntimeId,
                            argd)

    return True
Example #25
0
    def __buildRankData(self):
        now = time.time()
        if now - self.lastBuildTime < self.BUILD_RANKING_INTERVAL:
            return
        self.lastBuildtime = now

        results = {'roomId': self.bigRoomId}
        results['matchType'] = self.room.matchPlugin.match_room_confs[
            self.room.bigRoomId].get("matchType", "")
        results['ranks'] = []

        leftPlayers = [(userId, 0) for userId in daobase.executeRankCmd(
            "LRANGE", self.room.matchPlugin.rankingKey(self.bigRoomId), 0, -1)
                       ]  # 淘汰的
        if ftlog.is_debug():
            ftlog.debug("get leftPlayers", "|", leftPlayers, caller=self)
        playingPlayersWithScores = list(
            pairwise(
                daobase.executeRankCmd(
                    "ZRANGE",
                    self.room.matchPlugin.playingRankingKey(self.bigRoomId), 0,
                    -1, 'WITHSCORES')))
        if ftlog.is_debug():
            ftlog.debug("get playingPlayersWithScores", "|",
                        playingPlayersWithScores)

        allPlayers = list(reversed(leftPlayers +
                                   playingPlayersWithScores))  # 1, 2, ... 最后一名

        if ftlog.is_debug():
            ftlog.debug("get all players", "|", allPlayers)

        self.userRanking = {}
        self.ranks = []
        for i, (userId, tableChip) in enumerate(allPlayers):
            name, purl, photo = self.getUData(userId)
            rankItem = {
                'id': userId,
                'tableChip': tableChip,
                'name': name,
                'purl': purl,
                'head': photo,
                'rank': i + 1,
            }
            if results['matchType'] in ['hunter', 'snowball']:
                self.setHunterInfo(userId, rankItem)
            self.ranks.append(rankItem)
            self.userRanking[userId] = i

        results['totalPlayersNum'] = len(playingPlayersWithScores)
        results['pos'] = 1
        self.rankResults = results

        self.rankResultsForSend = strutil.cloneData(results)
        self.rankResultsForSend['ranks'] = strutil.cloneData(
            self.ranks[:30])  # 3.6 以前版本,发30个

        self.rankResultsForSend_3_6 = strutil.cloneData(results)
        blank = {'id': 0, 'tableChip': 0, 'name': '', 'purl': '', 'rank': 1}
        self.rankResultsForSend_3_6['ranks'] = strutil.cloneData(
            [blank] + self.ranks[:30])  # 3.6 以后版本,发31个,第一个是自己