Exemple #1
0
def _getCycleInfo(cycleType):
    """
    获取循环的周期信息
    :param cycleType:
    :return:
    """
    assert (cycleType in (CYCLE_TYPE_DAY, CYCLE_TYPE_WEEK, CYCLE_TYPE_MONTH,
                          CYCLE_TYPE_MONTH_REMAIN_TIME))
    if cycleType == CYCLE_TYPE_DAY:
        curCycle = timestamp.formatTimeDayInt()
        expire = 86400  # 1天后自动过期
        cycleName = 'day'
    elif cycleType == CYCLE_TYPE_WEEK:
        curCycle = timestamp.formatTimeWeekInt()
        expire = 604800  # 86400 * 7 7天后自动过期
        cycleName = 'week'
    elif cycleType == CYCLE_TYPE_MONTH:
        curCycle = timestamp.formatTimeMonthInt()
        expire = 2678400  # 86400 * 31 31天后自动过期
        cycleName = 'month'
    elif cycleType == CYCLE_TYPE_MONTH_REMAIN_TIME:
        curCycle = timestamp.formatTimeMonthInt()
        now_t = datetime.now()
        cur_year = now_t.year
        cur_month = now_t.month
        cur_day = now_t.day
        cur_hour = now_t.hour
        cur_minute = now_t.minute
        total_days = calendar.monthrange(cur_year, cur_month)[1]
        remain_days = total_days - cur_day
        expire = remain_days * 86400 + (24 - cur_hour) * 3600 + (
            60 - cur_minute) * 60  # 计算本月剩余时间,精确到分
        cycleName = 'month_remain_time'

    return cycleName, curCycle, expire
Exemple #2
0
 def isFirstWin(self, isWin):
     if not isWin:
         return False
     import poker.util.timestamp as pktimestamp
     today = pktimestamp.formatTimeDayInt()
     isFirstWin = self._datas.get('firstWin', {}).get(str(today), 0)
     if not isFirstWin:
         return True
     return False
Exemple #3
0
    def incrShareCount(self, ct=None):
        if ct == None:
            ct = datetime.now()

        # 不是同一天,则清零当天分享次数
        cday = pktimestamp.formatTimeDayInt(ct)
        if self.shareDay != cday:
            self.shareDay = cday
            self.shareCounter = 0
        self.shareCounter += 1
Exemple #4
0
def _getCycleInfo(cycleType):
    assert (cycleType in (CYCLE_TYPE_DAY, CYCLE_TYPE_WEEK, CYCLE_TYPE_MONTH))
    if cycleType == CYCLE_TYPE_DAY:
        curCycle = timestamp.formatTimeDayInt()
        expire = 86400  # 1天后自动过期
        cycleName = 'day'
    elif cycleType == CYCLE_TYPE_WEEK:
        curCycle = timestamp.formatTimeWeekInt()
        expire = 604800  # 86400 * 7 7天后自动过期
        cycleName = 'week'
    elif cycleType == CYCLE_TYPE_MONTH:
        curCycle = timestamp.formatTimeMonthInt()
        expire = 2678400  # 86400 * 31 31天后自动过期
        cycleName = 'month'
    return cycleName, curCycle, expire
Exemple #5
0
    def sendWinloseRes(self, result):
        details = self.buildResultDetails(result)
        mp = self.buildWinloseRes(result, details, 1)
        # 免费场开关
        freeFeeSwitch = self.table.room.roomConf.get('freeFeeSwitch', 0)
        mp.setResult('free', freeFeeSwitch)
        from dizhu.game import TGDizhu
        from dizhu.entity.common.events import ActiveEvent
        crossPlayCount = configure.getGameJson(DIZHU_GAMEID, 'wx.cross',
                                               {}).get('crossPlayCount', 10)
        crossDelaySeconds = configure.getGameJson(DIZHU_GAMEID, 'wx.cross',
                                                  {}).get(
                                                      'crossDelaySeconds', 10)
        authPlayCount = configure.getGameJson(DIZHU_GAMEID, 'authorization',
                                              {}).get('authPlayCount', 5)
        rewards = configure.getGameJson(DIZHU_GAMEID, 'authorization',
                                        {}).get('rewards', {})
        for index, seat in enumerate(self.table.seats):
            isKickOutCoin = 0

            # 每次进来需要重新初始化
            realSeats = []
            seatIndexes = []
            for i, seatDetails in enumerate(details.get('seatDetails', [])):
                copyDetail = copy.copy(seatDetails)
                realSeats.append(copyDetail)
                seatIndexes.append(i)
                mp.setResult('seat%s' % (i + 1), copyDetail)
            seatIndexes.remove(index)

            if self.table.room.roomConf.get('zeroSumFlag', 0) == 1:
                currentBaseScore = result.gameRound.baseScores[index]
                for seatIndex in seatIndexes:
                    otherBaseScore = result.gameRound.baseScores[seatIndex]
                    realSeats[seatIndex][0] = int(
                        float(currentBaseScore) / otherBaseScore *
                        realSeats[seatIndex][0])
                    realSeats[seatIndex][1] = int(
                        float(currentBaseScore) / otherBaseScore *
                        realSeats[seatIndex][1])
            else:
                # 显示以当前seat为基准做假数据
                dizhuIndex = mp.getResult('stat').get('dizhu')
                currentSeat = realSeats[index]
                windoubles = mp.getResult('windoubles')
                currentBaseScore = self.table.gameRound.baseScores[index]
                currentIsDizhu = dizhuIndex == index + 1
                dizhuwin = mp.getResult('dizhuwin')
                realDeltas = [realSeat[0] for realSeat in realSeats]
                if ftlog.is_debug():
                    ftlog.debug(
                        'DizhuTableProtoMix.sendWinloseRes realDeltas=',
                        realDeltas, 'userId=', seat.player.userId, 'mixId=',
                        seat.player.mixConf.get('mixId'), 'index=', index)

                if len(realDeltas) == 2:
                    for index2, realSeat in enumerate(realSeats):
                        if index != index2:
                            realSeat[0] = abs(currentSeat[0]) * (
                                realSeat[0] / abs(realSeat[0]))
                else:
                    if realDeltas.count(0) == 0:
                        for index2, realSeat in enumerate(realSeats):
                            if index != index2:
                                if currentIsDizhu:
                                    realSeat[0] = abs(currentSeat[0] / 2) * (
                                        realSeat[0] / abs(realSeat[0]))
                                else:
                                    if dizhuIndex == index2 + 1:
                                        realSeat[0] = abs(
                                            currentSeat[0] * 2) * (
                                                realSeat[0] / abs(realSeat[0]))
                                    else:
                                        realSeat[0] = abs(currentSeat[0]) * (
                                            realSeat[0] / abs(realSeat[0]))

                    elif realDeltas.count(0) == 1:  # 一个人托管
                        for index2, realSeat in enumerate(realSeats):
                            if index != index2:
                                if currentIsDizhu:  # 地主肯定有值
                                    if realSeat[0] != 0:
                                        if dizhuwin:
                                            realSeat[0] = abs(
                                                currentSeat[0]) * (
                                                    realSeat[0] /
                                                    abs(realSeat[0]))
                                        else:
                                            realSeat[0] = abs(
                                                currentSeat[0] /
                                                2) * (realSeat[0] /
                                                      abs(realSeat[0]))
                                else:
                                    if currentSeat[0] == 0:
                                        if dizhuIndex == index2 + 1:
                                            realSeat[0] = abs(
                                                windoubles * 2 *
                                                currentBaseScore) * (
                                                    realSeat[0] /
                                                    abs(realSeat[0]))
                                        else:
                                            if dizhuwin:
                                                realSeat[0] = abs(
                                                    windoubles * 2 *
                                                    currentBaseScore) * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                                            else:
                                                realSeat[0] = abs(
                                                    windoubles *
                                                    currentBaseScore) * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                                    else:
                                        if dizhuIndex == index2 + 1:
                                            if dizhuwin:
                                                realSeat[0] = abs(
                                                    currentSeat[0]) * 1 * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                                            else:
                                                realSeat[0] = abs(
                                                    currentSeat[0]) * 2 * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                    else:
                        for index2, realSeat in enumerate(realSeats):
                            if realSeat[0]:
                                realSeat[0] = abs(
                                    windoubles * 2 * currentBaseScore) * (
                                        realSeat[0] / abs(realSeat[0]))

                if ftlog.is_debug():
                    fakeDeltas = []
                    for i, seatDetails in enumerate(
                            details.get('seatDetails', [])):
                        fakeDeltas.append(mp.getResult('seat%s' % (i + 1))[0])
                    ftlog.debug(
                        'DizhuTableProtoMix.sendWinloseRes fakeDeltas=',
                        fakeDeltas, 'userId=', seat.player.userId, 'mixId=',
                        seat.player.mixConf.get('mixId'), 'index=', index)

            if seat.player and not seat.isGiveup:
                ssts = result.seatStatements

                # 是否达到踢出值
                isLowerKickOutCoin = True if ssts[
                    index].final < seat.player.mixConf.get('kickOutCoin',
                                                           0) else False

                # 不踢出
                if isLowerKickOutCoin and seat.player.chip < seat.player.mixConf.get(
                        'buyinchip', 0):
                    isKickOutCoin = 1

                mp.setResult('kickOutCoinTip', '')
                if isLowerKickOutCoin and seat.player.chip >= seat.player.mixConf.get(
                        'buyinchip', 0):
                    mp.setResult(
                        'kickOutCoinTip', '点击继续,将自动将您\n桌面金币补充至%s。\n继续努力吧!' %
                        seat.player.mixConf.get('buyinchip'))

                # 是否达到踢出值
                mp.setResult('isKickOutCoin', isKickOutCoin)
                # 破产埋点Id
                kickOutBurialId = seat.player.mixConf.get('kickOutBurialId')
                mp.setResult('kickOutBurialId', kickOutBurialId)
                # 首败分享埋点
                mp.rmResult('firstLoseBurialId')
                if seat.player.isFirstLose(ssts[index].isWin):
                    firstLoseBurialId = self.table.room.roomConf.get(
                        'firstLoseBurialId')
                    mp.setResult('firstLoseBurialId', firstLoseBurialId)

                # 是否展示交叉导流
                dailyPlayCount = new_table_remote.doGetUserDailyPlayCount(
                    seat.userId, DIZHU_GAMEID)
                mp.setResult('dailyPlay', dailyPlayCount)
                mp.rmResult('showCross')
                mp.setResult('showCross', dailyPlayCount > crossPlayCount)
                mp.setResult('crossDelaySeconds', crossDelaySeconds)
                if ftlog.is_debug():
                    ftlog.debug('sendWinloseRes userId=', seat.userId,
                                'dailyPlayCount=', dailyPlayCount,
                                'showCross=', dailyPlayCount > crossPlayCount,
                                'crossDelaySeconds=', crossDelaySeconds)
                if dailyPlayCount == 3:
                    TGDizhu.getEventBus().publishEvent(
                        ActiveEvent(6, seat.userId, 'playTimes3'))

                mp.rmResult('auth')
                if dailyPlayCount == authPlayCount:
                    mp.setResult('auth', {'auth': 1, 'rewards': rewards})

                # 服务费字段
                mp.setResult('room_fee',
                             ssts[index].fee + ssts[index].fixedFee)

                # 每日首胜
                if seat.player.isFirstWin(ssts[index].isWin):
                    from dizhu.game import TGDizhu
                    from dizhu.entity.common.events import ActiveEvent
                    import poker.util.timestamp as pktimestamp
                    TGDizhu.getEventBus().publishEvent(
                        ActiveEvent(6, seat.userId, 'dailyFirstWin'))
                    today = pktimestamp.formatTimeDayInt()
                    firstWin = {str(today): 1}
                    gamedata.setGameAttrs(seat.userId, DIZHU_GAMEID,
                                          ['firstWin'],
                                          [strutil.dumps(firstWin)])
                router.sendToUser(mp, seat.userId)
Exemple #6
0
def _getFriendGameInfo(userId, gameIds, for_level_info, for_winchip, for_online_info=1):
    uid = int(userId)
    datas = {}
    gid, rid, tid, sid = 0, 0, 0, 0
    state = daoconst.OFFLINE
    if for_online_info:
        loclist = onlinedata.getOnlineLocList(uid)
        state = onlinedata.getOnlineState(uid)
        if len(loclist) > 0:
            _rid, _tid, _sid = loclist[0]
            # gid表示用户在哪个游戏中
            gid = strutil.getGameIdFromInstanceRoomId(_rid)
            # 检查是否可加入游戏
            if TYGame(gid).canJoinGame(userId, _rid, _tid, _sid):
                # rid/tid/sid表示用户所在的游戏是否可加入游戏
                # 分享出来的都是可以加入游戏的牌桌信息
                rid = _rid
                tid = _tid
                sid = _sid
            if ftlog.is_debug():
                ftlog.debug('getFriendGameInfo userId:', userId, ' gameId:', gid, ' roomId:', _rid, ' tableId:', _tid,
                            ' seatId:', _sid, ' can not join game....')
        if state == daoconst.OFFLINE:
            offline_time = gamedata.getGameAttr(uid, HALL_GAMEID, 'offlineTime')
            if not offline_time:  # 取不到离线时间,取上线时间
                offline_time = userdata.getAttr(uid, 'authorTime')
            if offline_time:
                offline_time = pktimestamp.parseTimeMs(offline_time)
                delta = datetime.now() - offline_time
                delta = delta.days * 24 * 60 + delta.seconds / 60  # 分钟数
            else:  # 异常情况
                delta = 24 * 60
            datas['offline_time'] = delta if delta > 0 else 1
        if rid > 0:
            try:
                room = gdata.roomIdDefineMap().get(rid, None)
                if room:
                    datas['room_name'] = room.configure['name']
            except:
                ftlog.error()
    # 构造回传给SDK的游戏数据
    datas.update({'uid': uid, 'gid': gid, 'rid': rid, 'tid': tid, 'sid': sid, 'state': state})

    if for_level_info:
        datas['level_game_id'] = 0
        datas['level'] = 0
        datas['level_pic'] = ''
        try:
            for gameId in gameIds:
                if gameId not in gdata.games():
                    continue
                dashifen_info = gdata.games()[gameId].getDaShiFen(uid, '')
                if dashifen_info:
                    level = dashifen_info['level']
                    if level > 0 and level > datas['level']:
                        datas['level_game_id'] = gameId
                        datas['level'] = level
                        level_pic = dashifen_info.get('picbig')
                        datas['level_pic'] = level_pic if level_pic else dashifen_info.get('pic')
        except:
            ftlog.error()

    if for_winchip:
        datas['winchip'] = 0
        datas['winchips'] = 0
        try:
            for gameId in gameIds:
                winchips, todaychips = gamedata.getGameAttrs(userId, gameId, ['winchips', 'todaychips'], False)
                winchips = strutil.parseInts(winchips)
                yest_winchip = 0
                todaychips = strutil.loads(todaychips, ignoreException=True)
                if todaychips and 'today' in todaychips and 'chips' in todaychips and 'last' in todaychips:
                    if pktimestamp.formatTimeDayInt() == todaychips['today']:
                        yest_winchip = todaychips['last']
                    elif pktimestamp.formatTimeYesterDayInt() == todaychips['today']:
                        yest_winchip = todaychips['chips']
                datas['winchip'] += yest_winchip
                datas['winchips'] += winchips
        except:
            ftlog.error()
    return datas
Exemple #7
0
    def sendWinloseRes(self, result):
        details = self.buildResultDetails(result)
        mp = self.buildWinloseRes(result, details, 1)
        # 免费场开关
        freeFeeSwitch = self.table.room.roomConf.get('freeFeeSwitch', 0)
        mp.setResult('free', freeFeeSwitch)
        from dizhu.game import TGDizhu
        from dizhu.entity.common.events import ActiveEvent
        crossPlayCount = configure.getGameJson(DIZHU_GAMEID, 'wx.cross', {}).get('crossPlayCount', 10)
        crossDelaySeconds = configure.getGameJson(DIZHU_GAMEID, 'wx.cross', {}).get('crossDelaySeconds', 10)
        authPlayCount = configure.getGameJson(DIZHU_GAMEID, 'authorization', {}).get('authPlayCount', 5)
        rewards = configure.getGameJson(DIZHU_GAMEID, 'authorization', {}).get('rewards', {})
        for index, seat in enumerate(self.table.seats):
            isKickOutCoin = 0
            if seat.player and not seat.isGiveup:
                if self.table.room.roomConf.get('isAI') and seat.player.isAI:
                    continue
                ssts = result.seatStatements
                # 是否达到踢出值
                isLowerKickOutCoin = True if ssts[index].final < self.table.room.roomConf.get('kickOutCoin', 0) else False

                # 不踢出
                if isLowerKickOutCoin and seat.player.chip < self.table.room.roomConf['buyinchip']:
                    isKickOutCoin = 1

                # 点击继续的提醒
                mp.rmResult('kickOutCoinTip')
                if isLowerKickOutCoin and seat.player.chip >= self.table.room.roomConf['buyinchip']:
                    mp.setResult('kickOutCoinTip', details.get('kickOutCoinTip'))

                # 是否达到踢出值
                mp.setResult('isKickOutCoin', isKickOutCoin)
                # 破产埋点Id
                kickOutBurialId = self.table.room.roomConf.get('kickOutBurialId')
                mp.setResult('kickOutBurialId', kickOutBurialId)
                # 首败分享埋点
                mp.rmResult('firstLoseBurialId')
                if seat.player.isFirstLose(ssts[index].isWin):
                    firstLoseBurialId = self.table.room.roomConf.get('firstLoseBurialId')
                    mp.setResult('firstLoseBurialId', firstLoseBurialId)

                # 是否展示交叉导流
                dailyPlayCount = new_table_remote.doGetUserDailyPlayCount(seat.userId, DIZHU_GAMEID)
                mp.setResult('dailyPlay', dailyPlayCount)
                mp.rmResult('showCross')
                mp.setResult('showCross', dailyPlayCount > crossPlayCount)
                mp.setResult('crossDelaySeconds', crossDelaySeconds)

                if dailyPlayCount == 3:
                    TGDizhu.getEventBus().publishEvent(ActiveEvent(6, seat.userId, 'playTimes3'))

                mp.rmResult('auth')
                if dailyPlayCount == authPlayCount:
                    mp.setResult('auth', {'auth': 1, 'rewards': rewards})

                # 服务费字段
                mp.setResult('room_fee', ssts[index].fee + ssts[index].fixedFee)

                # 每日首胜
                if seat.player.isFirstWin(ssts[index].isWin):
                    from dizhu.game import TGDizhu
                    from dizhu.entity.common.events import ActiveEvent
                    import poker.util.timestamp as pktimestamp
                    TGDizhu.getEventBus().publishEvent(ActiveEvent(6, seat.userId, 'dailyFirstWin'))
                    today = pktimestamp.formatTimeDayInt()
                    firstWin = {str(today): 1}
                    gamedata.setGameAttrs(seat.userId, DIZHU_GAMEID, ['firstWin'], [strutil.dumps(firstWin)])

                if ftlog.is_debug():
                    ftlog.debug('sendWinloseRes userId=', seat.userId,
                                'dailyPlayCount=', dailyPlayCount,
                                'showCross=', dailyPlayCount > crossPlayCount,
                                'crossDelaySeconds=', crossDelaySeconds,
                                'msg=', mp)
                router.sendToUser(mp, seat.userId)
Exemple #8
0
    def sendWinloseRes(self, result):
        details = self.buildResultDetails(result)
        mp = self.buildWinloseRes(result, details, 1)
        from dizhu.game import TGDizhu
        from dizhu.entity.common.events import ActiveEvent
        crossPlayCount = configure.getGameJson(DIZHU_GAMEID, 'wx.cross', {}).get('crossPlayCount', 10)
        crossDelaySeconds = configure.getGameJson(DIZHU_GAMEID, 'wx.cross', {}).get('crossDelaySeconds', 10)
        authPlayCount = configure.getGameJson(DIZHU_GAMEID, 'authorization', {}).get('authPlayCount', 5)
        rewards = configure.getGameJson(DIZHU_GAMEID, 'authorization', {}).get('rewards', {})
        for index, seat in enumerate(self.table.seats):
            if seat.player and not seat.isGiveup:

                ssts = result.seatStatements

                # 分享时的二维码等信息
                mp.setResult('share', commconf.getNewShareInfoByCondiction(self.gameId, seat.player.clientId, 'winstreak'))

                # 是否达到踢出值
                mp.setResult('isKickOutCoin', 0)

                # 服务费字段
                mp.setResult('room_fee', ssts[index].fee + ssts[index].fixedFee)

                mp.rmResult('segmentInfo')
                mp.setResult('segmentInfo', details['segmentInfos'][index])

                mp.rmResult('gameWinReward')
                if details['rewardInfos'][index]:
                    mp.setResult('gameWinReward', details['rewardInfos'][index])
                # 判断复活条件
                mp.rmResult('recover')
                recover = details['recoverInfos'][index]
                if recover:
                    mp.setResult('recover', recover)

                # 连胜任务信息
                mp.rmResult('winStreakInfo')
                mp.setResult('winStreakInfo', details['winStreakRewardInfos'][index])

                # 连胜宝箱
                mp.rmResult('treasureChestInfo')
                mp.setResult('treasureChestInfo', details['treasureChestInfos'][index])

                # 是否展示交叉导流
                dailyPlayCount = new_table_remote.doGetUserDailyPlayCount(seat.userId, DIZHU_GAMEID)
                mp.setResult('dailyPlay', dailyPlayCount)
                mp.rmResult('showCross')
                mp.setResult('showCross', dailyPlayCount > crossPlayCount)
                mp.setResult('crossDelaySeconds', crossDelaySeconds)
                if ftlog.is_debug():
                    ftlog.debug('sendWinloseRes userId=', seat.userId,
                                'dailyPlayCount=', dailyPlayCount,
                                'showCross=', dailyPlayCount > crossPlayCount,
                                'crossDelaySeconds=', crossDelaySeconds)

                if dailyPlayCount == 3:
                    TGDizhu.getEventBus().publishEvent(ActiveEvent(6, seat.userId, 'playTimes3'))

                mp.rmResult('auth')
                if dailyPlayCount == authPlayCount:
                    mp.setResult('auth', {'auth': 1, 'rewards': rewards})

                # 每日首胜
                if seat.player.isFirstWin(ssts[index].isWin):
                    from dizhu.game import TGDizhu
                    from dizhu.entity.common.events import ActiveEvent
                    import poker.util.timestamp as pktimestamp
                    TGDizhu.getEventBus().publishEvent(ActiveEvent(6, seat.userId, 'dailyFirstWin'))
                    today = pktimestamp.formatTimeDayInt()
                    firstWin = {str(today): 1}
                    gamedata.setGameAttrs(seat.userId, DIZHU_GAMEID, ['firstWin'], [strutil.dumps(firstWin)])

                if ftlog.is_debug():
                    ftlog.debug('DizhuTableProtoSegment.sendWinloseRes userId=', seat.userId,
                                'mp=', mp._ht)
                router.sendToUser(mp, seat.userId)
Exemple #9
0
def _getFriendGameInfo(userId,
                       gameIds,
                       for_level_info,
                       for_winchip,
                       for_online_info=1):
    uid = int(userId)
    datas = {}
    gid, rid, tid, sid = 0, 0, 0, 0
    state = daoconst.OFFLINE
    if for_online_info:
        loclist = onlinedata.getOnlineLocList(uid)
        state = onlinedata.getOnlineState(uid)
        if len(loclist) > 0:
            _rid, _tid, _sid = loclist[0]
            # gid表示用户在哪个游戏中
            gid = strutil.getGameIdFromInstanceRoomId(_rid)
            # 检查是否可加入游戏
            if TYGame(gid).canJoinGame(userId, _rid, _tid, _sid):
                # rid/tid/sid表示用户所在的游戏是否可加入游戏
                # 分享出来的都是可以加入游戏的牌桌信息
                rid = _rid
                tid = _tid
                sid = _sid
            if ftlog.is_debug():
                ftlog.debug('getFriendGameInfo userId:', userId, ' gameId:',
                            gid, ' roomId:', _rid, ' tableId:', _tid,
                            ' seatId:', _sid, ' can not join game....')
        if state == daoconst.OFFLINE:
            offline_time = gamedata.getGameAttr(uid, HALL_GAMEID,
                                                'offlineTime')
            if not offline_time:  # 取不到离线时间,取上线时间
                offline_time = userdata.getAttr(uid, 'authorTime')
            if offline_time:
                offline_time = pktimestamp.parseTimeMs(offline_time)
                delta = datetime.now() - offline_time
                delta = delta.days * 24 * 60 + delta.seconds / 60  # 分钟数
            else:  # 异常情况
                delta = 24 * 60
            datas['offline_time'] = delta if delta > 0 else 1
        if rid > 0:
            try:
                room = gdata.roomIdDefineMap().get(rid, None)
                if room:
                    datas['room_name'] = room.configure['name']
            except:
                ftlog.error()
    # 构造回传给SDK的游戏数据
    datas.update({
        'uid': uid,
        'gid': gid,
        'rid': rid,
        'tid': tid,
        'sid': sid,
        'state': state
    })

    if for_level_info:
        datas['level_game_id'] = 0
        datas['level'] = 0
        datas['level_pic'] = ''
        try:
            for gameId in gameIds:
                if gameId not in gdata.games():
                    continue
                dashifen_info = gdata.games()[gameId].getDaShiFen(uid, '')
                if dashifen_info:
                    level = dashifen_info['level']
                    if level > 0 and level > datas['level']:
                        datas['level_game_id'] = gameId
                        datas['level'] = level
                        level_pic = dashifen_info.get('picbig')
                        datas[
                            'level_pic'] = level_pic if level_pic else dashifen_info.get(
                                'pic')
        except:
            ftlog.error()

    if for_winchip:
        datas['winchip'] = 0
        datas['winchips'] = 0
        try:
            for gameId in gameIds:
                winchips, todaychips = gamedata.getGameAttrs(
                    userId, gameId, ['winchips', 'todaychips'], False)
                winchips = strutil.parseInts(winchips)
                yest_winchip = 0
                todaychips = strutil.loads(todaychips, ignoreException=True)
                if todaychips and 'today' in todaychips and 'chips' in todaychips and 'last' in todaychips:
                    if pktimestamp.formatTimeDayInt() == todaychips['today']:
                        yest_winchip = todaychips['last']
                    elif pktimestamp.formatTimeYesterDayInt(
                    ) == todaychips['today']:
                        yest_winchip = todaychips['chips']
                datas['winchip'] += yest_winchip
                datas['winchips'] += winchips
        except:
            ftlog.error()
    return datas
Exemple #10
0
def _calRankInfoData(userId, seatDeltaChip, winslam, windoubles):
    ftlog.debug('calRankInfoData->', userId, seatDeltaChip, winslam,
                windoubles)
    # 每周,城市赢金榜
    if seatDeltaChip > 0 and dizhuconf.isUseTuyouRanking():  # 陌陌使用自己的排行榜
        city_code = sessiondata.getCityZip(userId)
        city_index = city_locator.ZIP_CODE_INDEX.get(city_code, 1)
        rankingId = 110006100 + city_index
        hallranking.rankingSystem.setUserScore(str(rankingId), userId,
                                               seatDeltaChip)

    # 更新gamedata中的各种max和累积值
    winchips, losechips, maxwinchip, weekchips, winrate, maxweekdoubles, slams, todaychips = gamedata.getGameAttrs(
        userId, DIZHU_GAMEID, [
            'winchips', 'losechips', 'maxwinchip', 'weekchips', 'winrate',
            'maxweekdoubles', 'slams', 'todaychips'
        ], False)
    ftlog.debug('calRankInfoData->', winchips, losechips, maxwinchip,
                weekchips, winrate, maxweekdoubles, slams)
    winchips, losechips, maxwinchip, maxweekdoubles, slams = strutil.parseInts(
        winchips, losechips, maxwinchip, maxweekdoubles, slams)
    updatekeys = []
    updatevalues = []

    # 计算累计的输赢金币
    if seatDeltaChip > 0:
        winchips = winchips + seatDeltaChip
        updatekeys.append('winchips')
        updatevalues.append(winchips)
    else:
        losechips = losechips + seatDeltaChip
        updatekeys.append('losechips')
        updatevalues.append(losechips)

    # 计算增加最大的赢取金币数
    if seatDeltaChip > maxwinchip:
        updatekeys.append('maxwinchip')
        updatevalues.append(seatDeltaChip)

    # 计算增加每星期的累计赢取、输掉的金币数
    weekchips = strutil.loads(weekchips, ignoreException=True)
    if weekchips == None or len(weekchips) != 2 or (
            not 'week' in weekchips) or (not 'chips' in weekchips):
        weekchips = {'week': -1, 'chips': 0}
    weekOfYear = pktimestamp.formatTimeWeekInt()
    if weekOfYear != weekchips['week']:
        weekchips = {'week': weekOfYear, 'chips': seatDeltaChip}
    else:
        weekchips['chips'] = weekchips['chips'] + seatDeltaChip
    updatekeys.append('weekchips')
    updatevalues.append(strutil.dumps(weekchips))

    # 计算增加每星期的累计赢取的金币数
    if seatDeltaChip > 0:
        todaychips = strutil.loads(todaychips, ignoreException=True)
        if todaychips == None or len(todaychips) != 3 \
            or (not 'today' in todaychips) or (not 'chips' in todaychips) or (not 'last' in todaychips) :
            todaychips = {'today': -1, 'chips': 0, 'last': 0}
        today = pktimestamp.formatTimeDayInt()
        if today != todaychips['today']:
            yesterdaychips = 0
            if todaychips['today'] == pktimestamp.formatTimeYesterDayInt():
                yesterdaychips = todaychips['chips']
            todaychips = {
                'today': today,
                'chips': seatDeltaChip,
                'last': yesterdaychips
            }
        else:
            todaychips['chips'] = todaychips['chips'] + seatDeltaChip
        updatekeys.append('todaychips')
        updatevalues.append(strutil.dumps(todaychips))

    # 计算marsscore
    winchipsDelta = int(winchips) - int(losechips)
    winrate = strutil.loads(winrate,
                            ignoreException=True,
                            execptionValue={'wt': 0})
    wintimes = int(winrate.get('wt', 0))
    marsscore = winchipsDelta * 0.6 + wintimes * 200 * 0.4
    if marsscore > 0:
        updatekeys.append('marsscore')
        updatevalues.append(marsscore)

    # 计算slams和maxweekdoubles
    if seatDeltaChip > 0:
        if winslam:
            updatekeys.append('slams')
            updatevalues.append(slams + 1)

        if maxweekdoubles < windoubles:
            updatekeys.append('maxweekdoubles')
            updatevalues.append(windoubles)

    if len(updatekeys) > 0:
        gamedata.setGameAttrs(userId, DIZHU_GAMEID, updatekeys, updatevalues)
    return 1
Exemple #11
0
 def getTodaySharedCount(self):
     ''' 今天分享的次数 '''
     cday = pktimestamp.formatTimeDayInt(None)
     if self.shareDay == cday:
         return self.shareCounter if self.shareCounter > 0 else 0
     return 0
Exemple #12
0
 def hasTodayShared(self):
     ''' 今天是否已经分享过 '''
     cday = pktimestamp.formatTimeDayInt(None)
     return (self.shareDay == cday) and (self.shareCounter > 0)