Example #1
0
 def __init__(self, player, fireRange, idleRange, leaveRange):
     self.player = player
     self.userId = player.userId
     self.player.table.clip_add(player.userId, player.seatId)
     ftlog.debug("__init__", player.userId, player.chip, player.clip)
     self.fireInterval = config.getGunLevelConf(self.nowGunLevel, self.player.table.gameMode).get("interval", 0.3)
     self.updateTimer = None
     self.updateTimer = FTLoopTimer(5, -1, self._update)
     self.updateTimer.start()
     self.fireTimer = None
     self.fireTargetPos = [0, 0]
     self.bulletId = 0
     # 空闲次数
     self.idleCount = 0
     # 开火次数
     self.fireCount = 0
     # 等待离开
     self.waitLeaveCount = 0
     # 表情
     self.exp = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
     self.fireRange = fireRange
     self.idleRange = idleRange
     self.leaveRange = leaveRange
     self.updateCount = 0
     self.needClear = False
     # 全是机器人的计数
     self.allRobotCount = 0
class RainbowFishGroup(object):
    """
    彩虹鱼鱼群
    """
    def __init__(self, table):
        self.table = table
        self._interval = 100            # 间隔
        self._totalTime = 0             # 总时间
        self._nextRainbowTimer = None	# 下一波彩虹鱼
        self._setRainbowTimer()

    def clearTimer(self):
        if self._nextRainbowTimer:
            self._nextRainbowTimer.cancel()
            self._nextRainbowTimer = None

    def _setRainbowTimer(self):
        """启动彩虹鱼定时器"""
        self.clearTimer()
        self._nextRainbowTimer = FTLoopTimer(self._interval, -1,  self._addRainbowFishGroup)
        self._nextRainbowTimer.start()

    def _addRainbowFishGroup(self):
        """添加彩虹鱼"""
        self._totalTime += self._interval
        if self._totalTime % 3 == 0:
            return
        rainbowGroupId = random.choice(self.table.runConfig.allRainbowGroupIds)
        if rainbowGroupId:
            if ftlog.is_debug():
                ftlog.debug("_addRainbowFishGroup", self.table.tableId, rainbowGroupId)
            self.table.insertFishGroup(rainbowGroupId)
 def catchTentacles(self, event):
     """
     捕获触手
     """
     if self._state == Octopus.ST_APPEARED:
         catch = event.catch
         fIds = [
             catchMap["fId"] for catchMap in catch
             if catchMap["reason"] == 0
         ]
         isCatch = False
         for _tentacle in self._tentacles:
             if _tentacle.state == Tentacle.ST_SWING and _tentacle.fishId in fIds:
                 isCatch = True
                 self.diedTentaclesCount[str(_tentacle.fishType)] += 1
                 _tentacle.catch()
         if ftlog.is_debug():
             ftlog.debug("catchTentacles", event.userId, fIds,
                         self.diedTentaclesCount)
         if isCatch:
             if self.diedTentaclesCount == self.tentacleConf[
                     "totalTentacleCount"]:
                 self._delayLeaveTimer = FTLoopTimer(
                     self.tentacleConf["delayLeaveTime"],
                     0,
                     self._doLeave,
                     isNow=True)
                 self._delayLeaveTimer.start()
             else:
                 self.playingOctopusPainFace()
 def _setTerrorTimer(self):
     """启动恐怖鱼鱼群定时器"""
     self.clearTimer()
     self._fishType, self._interval = self._randomFishTypeAndInterval()
     self._nextTerrorTimer = FTLoopTimer(self._interval, -1,
                                         self._addTerrorFishGroup)
     self._nextTerrorTimer.start()
Example #5
0
 def setUseEffectTimer(self, duration=6):
     """设置使用狂暴效果的定时器"""
     if duration <= 0:
         return
     self.clearUeTimer()
     self.useEffectTimer = FTLoopTimer(duration, 0, self.sendUseEffectState)
     self.useEffectTimer.start()
Example #6
0
    def doFTEnter(self, ftId, userId, seatId):
        ftlog.info("FishFriendTable.doFTEnter", "tableId=", self.tableId,
                   "ftId=", ftId, "seatId=", seatId)
        lang = util.getLanguage(userId)
        if ftId != self.ftId:
            raise TYBizException(
                1,
                config.getMultiLangTextConf("ID_INPUT_ROOMID_ERROR_INFO",
                                            lang=lang))

        player = self.getPlayer(userId)
        if player and player.userId:
            self.sendFriendDetails(userId)
        else:
            if self._expiresTimer:  # 重置桌子超时计时器
                self._expiresTimer.cancel()
                self._expiresTimer = None
            self._expiresTimer = FTLoopTimer(self._tableExpiresTime, 0,
                                             self._tableExpires)
            self._expiresTimer.start()
            self._doTableQuickStart(userId, seatId)  # 用户进入
            self.sendFriendDetails(userId)  # 发送对战详情信息
            if userId != self.ftTable.userId:  # 记录参与者Id
                self.otherId = userId
                fight_history.addOneHistory(userId, self.ftTable.userId,
                                            fight_history.HistoryType.Enter,
                                            self.ftId,
                                            self.ftTable.fee)  # 进入房间记录
        return 0
 def _setPlatterTimer(self):
     """启动大盘鱼群定时器"""
     self.clearTimer()
     self._fishType, self._interval = self._randomFishTypeAndInterval()
     self._nextPlatterTimer = FTLoopTimer(self._interval, -1,
                                          self._addPlatterFishGroup)
     self._nextPlatterTimer.start()
Example #8
0
 def sendCmpttTaskInfo(self):
     """
     发送夺宝赛任务倒计时信息
     """
     userIds = []
     for uid in self.table.getBroadcastUids():
         if util.isFinishAllNewbieTask(uid):
             userIds.append(uid)
     if self.sendInfoTimer:
         self.sendInfoTimer.cancel()
     if not userIds:
         return
     if self.state == 0:
         self.sendInfoTimer = FTLoopTimer(self.sendInfoTime, 0,
                                          self.sendCmpttTaskInfo)
         self.sendInfoTimer.start()
     else:
         return
     timeLeft = int(
         self.taskInterval) - int(time.time() - self.recordReloadTime)
     if timeLeft <= 0:
         return
     msg = MsgPack()
     msg.setCmd("cmptt_task")
     msg.setResult("gameId", FISH_GAMEID)
     msg.setResult("action", "info")
     msg.setResult("timeLeft", timeLeft)
     GameMsg.sendMsg(msg, userIds)
 def _addBoss(self, fishType, isSysTimerCall=True):
     """
     添加宝箱boss
     """
     if self._isBossShowTimeStage == -0x1:
         self._isBossShowTimeStage = 0
     if self._autofillTimer.get(fishType):
         self._autofillTimer[fishType].cancel()
         self._autofillTimer[fishType] = None
         # 处理冰冻自动填充时机延后逻辑.
         if self._group.get(
                 fishType) and not isSysTimerCall and self._group[
                     fishType].extendGroupTime > 0:
             self._autofillTimer[fishType] = FTLoopTimer(
                 self._group[fishType].extendGroupTime, 0, self._addBoss,
                 fishType, False)
             self._autofillTimer[fishType].start()
             self._group[fishType].extendGroupTime = 0
             return
     # boss超出最大存在时间后不再出现.
     if int(time.time()) >= self._startTS + self.boxConf["maxAliveTime"]:
         if fishType == self._bBossFishType:
             self._removeBossShowTimeStage(0x1)
         elif fishType == self._mBossFishType:
             self._removeBossShowTimeStage(0x10)
         else:
             self._removeBossShowTimeStage(0x100)
         return
     self._group[fishType] = None
     # 使用出生路径.
     if fishType not in self._hasBorned:
         self._hasBorned.append(fishType)
         _bossGroupIds = self.table.runConfig.allSuperBossBornGroupIds[
             fishType]
     elif self._isBossShowTimeStage & 0x11 != 0x11:  # bBoss或mBoss只有一个存在,则使用加速鱼阵.
         _bossGroupIds = self.table.runConfig.allSuperBossFastMoveGroupIds.get(
             fishType)
         if not _bossGroupIds:
             _bossGroupIds = self.table.runConfig.allSuperBossGroupIds[
                 fishType]
     else:
         _bossGroupIds = self.table.runConfig.allSuperBossGroupIds[fishType]
     if _bossGroupIds:
         _bossGroupId = random.choice(_bossGroupIds)
         self._group[fishType] = self.table.insertFishGroup(_bossGroupId)
         if self._group[fishType]:
             self._autofillTimer[fishType] = FTLoopTimer(
                 self._group[fishType].totalTime + 1, 0, self._addBoss,
                 fishType, False)
             self._autofillTimer[fishType].start()
             if fishType == self._bBossFishType:
                 self._addBossShowTimeStage(0x1)
             elif fishType == self._mBossFishType:
                 self._addBossShowTimeStage(0x10)
             else:
                 self._addBossShowTimeStage(0x100)
             return self._group[fishType]
     ftlog.error("superboss_fish_group.BoxFishGroup, error, tableId =",
                 self.table.tableId, fishType, self._hasBorned)
     return
 def __init__(self, table):
     self.table = table
     self._lastUtilAppearTime = int(time.time())  # 上一次添加所有人可见红包奖券出现的事件
     self.checkTimer = FTLoopTimer(10, -1, self._checkCondition)  # 检查条件
     self.checkTimer.start()
     self._clearUserCouponFishData()  # 清理用户奖券数据
     self._registerEvent()  # 注册事件
 def _addUserCouponFishGroupNew(self, groupId, userId, totalBullet):
     """
     添加个人可见的奖券鱼
     """
     player = self.table.getPlayer(userId)
     self._clearPlayerTimer(userId)
     if player:
         playerBullet = player.couponConsumeClip
         if playerBullet < totalBullet:
             timer = FTLoopTimer(10, 0, self._addUserCouponFishGroupNew,
                                 groupId, userId, totalBullet)
             timer.start()
             self._playerCouponTimerDict[userId] = timer
             if ftlog.is_debug():
                 ftlog.debug(
                     "_addUserCouponFishGroupNew, check later, tableId =",
                     self.table.tableId, "userId =", userId,
                     "playerBullet =", playerBullet, "totalBullet =",
                     totalBullet)
         else:
             player.resetCouponConsumeClip()
             if ftlog.is_debug():
                 ftlog.debug("_addUserCouponFishGroupNew, tabId =",
                             self.table.tableId, "userId =", userId,
                             "groupId =", groupId)
             self.table.insertFishGroup(groupId,
                                        userId=userId,
                                        sendUserId=userId)
             self._checkUserConditionNew(userId)
Example #12
0
 def _addCouponFishGroup(self, userId):
     """
     添加红包券鱼
     """
     if ftlog.is_debug():
         ftlog.debug("_addCouponFishGroup", userId, self.table.tableId)
     player = self.table.getPlayer(userId)
     catchCouponFishCount = gamedata.getGameAttrInt(
         userId, FISH_GAMEID, GameData.catchCouponFishCount)
     if player and player.taskSystemUser and player.taskSystemUser.curTask:
         if catchCouponFishCount < 10 or player.taskSystemUser.curTask.taskConfig[
                 "type"] == TaskType.CatchRedPacketFishNum:
             taskId = player.taskSystemUser.getCurMainTaskId()
             newbieFishGroupConf = config.getPublic("newbieFishGroupConf",
                                                    {})
             couponFishGroups = newbieFishGroupConf.get(
                 str(taskId), {}).get("couponFishGroups", [])
             data = self._playerCouponTimerDict.get(userId)
             if couponFishGroups and (not data
                                      or data[1].getTimeOut() <= 0):
                 group = self.table.insertFishGroup(
                     random.choice(couponFishGroups),
                     userId=userId,
                     sendUserId=userId)
                 timer = FTLoopTimer(group.totalTime, 0,
                                     self._addCouponFishGroup, userId)
                 timer.start()
                 self._playerCouponTimerDict[userId] = [group, timer]
 def _setNextGroupTimer(self):
     """启动倍率鱼定时器"""
     self.clearTimer()
     interval = random.randint(25, int((1 - self._tableRank) * 30 + 30))
     self._nextGroupTimer = FTLoopTimer(interval, 0,
                                        self._addMultipleFishGroup)
     self._nextGroupTimer.start()
Example #14
0
 def postTask(self, task):
     if self._state != Heartbeat.ST_STOP:
         self._postTaskList.append(task)
         if self._init and self._timer:
             self._timer.cancel()
             self._timer = FTLoopTimer(0, 0, self._onTimeout)
             self._timer.start()
Example #15
0
 def _setGrandPrixTimer(self):
     """设置大奖赛定时器"""
     self._idx = 0
     self.clearTimer()
     self._nextGrandPrixTimer = FTLoopTimer(self._interval, -1,
                                            self._addGrandPrixFishGroup)
     self._nextGrandPrixTimer.start()
Example #16
0
class FishPlayerBuffer(object):
    """回馈赛的buffer"""
    def __init__(self, player, bufferId):
        self.player = player
        self.bufferId = bufferId
        self._state = BUFFER_STATE.NOEFFECT
        self.startTime = 0
        self.bufferConf = config.getPlayerBufferConf(bufferId)
        self.checkTimer = FTLoopTimer(self.bufferConf["delayTime"], -1,
                                      self._bufferStart)
        self.checkTimer.start()

        self.sendMsgTimer = None

    def getBufferId(self):
        return self.bufferId

    def isStart(self):
        return self._state == BUFFER_STATE.START

    def _bufferStart(self):
        if self.checkTimer:
            self.checkTimer.cancel()
        self._state = BUFFER_STATE.START
        self.startTime = int(time.time())
        pass
 def switchDragonStage(self, isTimeout=False):
     """
     切换冰龙阶段
     @param isTimeout: 是否为超时切换
     """
     self.stage and self.stage.clearTimer()
     if self.stageTimer:
         self.stageTimer.cancel()
         self.stageTimer = None
     if not self.stage:
         # 创建龙吼阶段
         self.creatrDragonStage(RoarStage)
         # 龙吼阶段超时将切换至游动阶段
         self.stageTimer = FTLoopTimer(self.dragonConf["roar.stage.time"],
                                       0,
                                       self.switchDragonStage,
                                       isTimeout=True)
         self.stageTimer.start()
     elif isinstance(self.stage, RoarStage):
         # 龙吼阶段超时强制结束回合
         if isTimeout:
             self.stage.setRoundEndState(isNow=True)
         # 龙吼阶段结束切换为游动阶段
         switchStageTime = random.randint(
             *self.dragonConf["switch.stage.time"])
         self.stageTimer = FTLoopTimer(switchStageTime, 0,
                                       self.creatrDragonStage, SwimStage)
         self.stageTimer.start()
Example #18
0
 def _addNormalFishGroup(self):
     """
     add_group消息默认是下一个鱼阵开始前60s左右发送,每次调用add_group方法耗费时间一般为0.5s以内(包含对象创建和定时器延迟)
     长此以往会导致add_group消息在当前鱼阵结束后没有及时发送,需要修正时间
     """
     taskIds = []
     newbieFishGroupConf = config.getPublic("newbieFishGroupConf", {})
     for player in self.table.players:
         if player and player.taskSystemUser:
             taskIds.append(str(
                 player.taskSystemUser.getCurMainTaskId()))  # 获取当前主线任务Id
     taskIds.sort()
     if taskIds:
         taskId = taskIds[-1]
         if taskId in newbieFishGroupConf and int(taskId) > self._taskId:
             self._taskId = int(taskId)
             self._allNormalGroupIds = newbieFishGroupConf[str(taskId)].get(
                 "normalFishGroups", [])
             self._allMultipleGroupIds = newbieFishGroupConf[str(
                 taskId)].get("multipleFishGroups", [])
             self._allBombGroupIds = newbieFishGroupConf[str(taskId)].get(
                 "bombFishGroups", [])
             self._allRainbowGroupIds = newbieFishGroupConf[str(
                 taskId)].get("rainbowFishGroups", [])
     if ftlog.is_debug():
         ftlog.debug("_addNormalFishGroup->", taskIds, self._taskId,
                     self._allNormalGroupIds)
     randomGroupIds = list(
         set(self._allNormalGroupIds) - set(self._appearedNormalGroupIds))
     if not randomGroupIds:
         randomGroupIds = self._allNormalGroupIds
         self._appearedNormalGroupIds = []
     selectGroupIds = random.sample(randomGroupIds, self._generateNumOnce)
     self._appearedNormalGroupIds.extend(selectGroupIds)
     enterTime = self.table.getNextGroupEnterTime()
     correctValue = 0
     if enterTime > 0 > self.table.startTime + enterTime - time.time():
         correctValue = abs(self.table.startTime + enterTime - time.time())
     self.table.addNormalFishGroups(selectGroupIds)
     nextAddGroupInterval = round(
         self._getNextAddGroupInterval() - correctValue, 2)
     if nextAddGroupInterval < 1:
         nextAddGroupInterval = 1
     if self._normalFishGroupTimer:
         self._normalFishGroupTimer.cancel()
     self._normalFishGroupTimer = FTLoopTimer(nextAddGroupInterval, 0,
                                              self._nextNormalFishGroup)
     self._normalFishGroupTimer.start()
     self._nextMultipleFishGroup()
     self._nextBombFishGroup()
     self._nextRainbowFishGroup()
     if ftlog.is_debug():
         ftlog.debug("_addNormalFishGroup->nextAddGroupInterval =",
                     nextAddGroupInterval, "nextGroupEnterTimeInterval =",
                     self.table.startTime + enterTime - time.time(),
                     "tableId =", self.table.tableId,
                     "self.table.startTime =", self.table.startTime,
                     "enterTime =", enterTime, "nowTime =", time.time(),
                     "correctValue =", correctValue)
Example #19
0
 def _setBossTimer(self):
     """启动定时器"""
     if self._nextBossTimer:
         self._nextBossTimer.cancel()
         self._nextBossTimer = None
     self._nextBossTimer = FTLoopTimer(self._interval, -1,
                                       self._addBossFishGroup)
     self._nextBossTimer.start()
Example #20
0
def regPPSCounter(funCount):
    global _ppsTimer
    if callable(funCount):
        if _ppsTimer == None:
            _ppsTimer = FTLoopTimer(3, -1, _ppsCounter)
            _ppsTimer.start()
        if funCount not in _ppsFunCounts:
            _ppsFunCounts.append(funCount)
 def _newJoinTaskAfterTheStart(self, userId):
     """
     任务开始后加入任务
     """
     fun = self._funMap.get(self.currTask, None)
     if fun:
         timer = FTLoopTimer(1, 0, fun.newJoinTaskForAfterTheStart, userId)
         timer.start()
Example #22
0
 def delaySendUserTaskInfo(self, interval=0):
     """
     延时发送任务信息
     """
     if self.sendTaskInfoTimer:
         self.sendTaskInfoTimer.cancel()
     self.sendTaskInfoTimer = FTLoopTimer(interval, 0, self.sendUserTaskInfo)
     self.sendTaskInfoTimer.start()
Example #23
0
    def __init__(self, sportlottery):
        self.sportlottery = sportlottery

        self.timer = FTLoopTimer(10, -1, self._getHttpOdds)
        self.timer.start()

        if ftlog.is_debug():
            ftlog.debug('SportOdds', 'sportObj=', self.sportlottery.toDict())
Example #24
0
def regPPSCounter(funCount):
    global _ppsTimer
    if callable(funCount):
        if _ppsTimer == None:
            _ppsTimer = FTLoopTimer(3, -1, _ppsCounter)
            _ppsTimer.start()
        if funCount not in _ppsFunCounts:
            _ppsFunCounts.append(funCount)
 def _addAutoFillBoss(self, interval):
     """
     延时添加自动填充Boss
     """
     if self._autofillTimer:
         self._autofillTimer.cancel()
         self._autofillTimer = None
     self._autofillTimer = FTLoopTimer(interval, 0, self._addBossFishGroup)
     self._autofillTimer.start()
    def _addNormalFishGroups(self):
        """
        add_group消息默认是下一个鱼阵开始前60s左右发送,每次调用add_group方法耗费时间一般为0.5s以内(包含对象创建和定时器延迟)
        长此以往会导致add_group消息在当前鱼阵结束后没有及时发送,需要修正时间
        """
        selectGroupIds = []
        if self.table.typeName == config.FISH_ROBBERY:                  # 招财模式boss鱼潮
            if len(self.table.runConfig.allRobberyBossGroupIds):
                allRobberyBossGroupIds = self.fishes[self.fishes.keys()[self._appearIndex]]
                tideGroupIds = random.sample(allRobberyBossGroupIds, 1)
                selectGroupIds.extend(tideGroupIds)
                self._appearIndex += 1
                if self._appearIndex >= len(self.fishes):
                    self._appearIndex = 0
        else:
            if self._appearIndex >= len(self._appearTideMinute):
                self._appearIndex = 0
            currMinute = datetime.datetime.now().minute
            if currMinute in self._appearTideMinute[self._appearIndex] and not self.table.hasSuperBossFishGroup():
                tideGroupIds = []
                if len(self.table.runConfig.allTideGroupIds):       # 普通鱼潮
                    tideGroupIds = random.sample(self.table.runConfig.allTideGroupIds, 1)
                if len(self.table.runConfig.allActTideGroupIds):    # 活动鱼潮1
                    if self._isActivityTideAppear("atideAppearConf"):
                        tideGroupIds = random.sample(self.table.runConfig.allActTideGroupIds, 1)
                if len(self.table.runConfig.allActTide2GroupIds):   # 活动鱼潮2
                    if self._isActivityTideAppear("atide2AppearConf"):
                        tideGroupIds = random.sample(self.table.runConfig.allActTide2GroupIds, 1)
                selectGroupIds.extend(tideGroupIds)
                self._appearIndex += 1
                if ftlog.is_debug():
                    ftlog.debug("_addNormalFishGroups->addTideGroupId = ", tideGroupIds, self._appearIndex, self.table.tableId)
        if ftlog.is_debug():
            ftlog.debug("_addNormalFishGroups->selectGroupIds =", selectGroupIds, self._appearIndex, self.table.tableId)

        selectGroupIds.extend(random.sample(self.table.runConfig.allNormalGroupIds, self._generateNumOnce - len(selectGroupIds)))
        if ftlog.is_debug():
            ftlog.debug("self.table.normalFishGroups =", self.table.tableId, self.table.normalFishGroups)
        enterTime = self.table.getNextGroupEnterTime()
        correctValue = 0
        if enterTime > 0 > self.table.startTime + enterTime - time.time():
            correctValue = abs(self.table.startTime + enterTime - time.time()) + 30
        self.table.addNormalFishGroups(selectGroupIds)
        nextAddGroupInterval = round(self._getNextAddGroupInterval() - correctValue, 2)
        nextAddGroupInterval = max(nextAddGroupInterval, 1)         # 如果当前时间已经过了本该出鱼的时间,则指定下一秒立即出鱼
        self.clearTimer()
        self._nextGroupTimer = FTLoopTimer(nextAddGroupInterval, 0, self._nextGroup)
        self._nextGroupTimer.start()
        if ftlog.is_debug():
            ftlog.debug(
                "_addNormalFishGroups nextAddGroupInterval =", nextAddGroupInterval,
                "nextGroupEnterTimeInterval =", self.table.startTime + enterTime - time.time(),
                "tableId =", self.table.tableId,
                "nowTime =", time.time(),
                "correctValue =", correctValue,
                "selectGroupIds =", selectGroupIds
            )
Example #27
0
 def __init__(self, markParams, argl, argd):
     super(_FutureResultLocal, self).__init__()
     try:
         ftt = FTLoopTimer(0.01, 0, self._invokeLocal, markParams, argl, argd)
         ftt.start()
     except Exception, e:
         self._status = FutureResult.STATUS_ERROR
         self._exception = e
         ftlog.error()
Example #28
0
 def _initGR(self):
     # 获取所有的bigRoomId
     self._ftMap = OrderedDict()
     self._tableCtrl = TableController()
     self._tableManager = self._buildTableManager()
     self._idleFTTimer = FTLoopTimer(60, -1, self._releaseIdleFT)
     self._idleFTTimer.start()
     ftlog.info('FTRoom._initGR Succ', 'roomId=', self.roomId,
                'tableCount=', self._tableManager.allTableCount)
 def _doIdle(self):
     """
     空闲等待
     """
     self._state = Tentacle.ST_IDLE
     stageTime = self.getCurrentStateStageTime()
     interval = stageTime[1] - stageTime[0]
     self._idleTimer = FTLoopTimer(interval, 0, self._doSwing)
     self._idleTimer.start()
 def _addTideFishGroup(self):
     """
     添加鱼潮
     """
     tideGroupId = random.choice(self.table.runConfig.allTideGroupIds)
     group = self.table.insertFishGroup(tideGroupId)
     # 鱼潮出现后等3s出现鱼潮任务
     FTLoopTimer(3, 0, self._addTideTask, tideGroupId).start()
     # 鱼潮结束前重启鱼阵
     FTLoopTimer(group.totalTime - 6, 0, self._tideFishGroupLeave).start()
Example #31
0
 def initialize(self, serverType):
     if serverType == gdata.SRV_TYPE_CENTER:
         # 只在CT中执行刷新token的操作
         self.refreshTimer = FTLoopTimer(300, -1, self._refreshTokenIfNeed)
         self.refreshTimer.start()
         FTLoopTimer(0, 0, self._refreshTokenIfNeed).start()
     else:
         self.refreshTimer = FTLoopTimer(300, -1, self._reloadToken)
         self.refreshTimer.start()
         self._reloadToken()
Example #32
0
def _invokeRpcMethod(markParams, argl, argd):
    '''
    进程内其它方法调用RPC方法的代理方法
    '''
    rpc = markParams['rpc']
    rpcSrvType = markParams['rpcSrvType']
    groupIndex = markParams['groupIndex']
    future = markParams['future']
    groupVal = 0
    dstSid = None
    if rpcSrvType == RPC_FIRST_SERVERID:
        dstSid = argl[0]
    else:
        if groupIndex >= 0:
            groupVal = argl[groupIndex]
        if rpcSrvType == gdata.SRV_TYPE_UTIL:
            dstSid = _getRpcDstServerId(router._utilServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_ROOM:
            dstSid = getRpcDstRoomServerId(groupVal, 1)
        elif rpcSrvType == gdata.SRV_TYPE_TABLE:
            dstSid = getRpcDstRoomServerId(groupVal, 0)
        elif rpcSrvType == gdata.SRV_TYPE_CONN:
            dstSid = _getRpcDstServerId(router._connServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_HTTP:
            dstSid = _getRpcDstServerId(router._httpServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_ROBOT:
            dstSid = _getRpcDstServerId(router._robotServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_AGENT:
            dstSid = _getRpcDstServerId(router._agentServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_SDK_HTTP:
            dstSid = _getRpcDstServerId(router._sdkHttpServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_SDK_GATEWAY:
            dstSid = _getRpcDstServerId(router._gatewayHttpServer, groupVal)
        elif rpcSrvType == gdata.SRV_TYPE_CENTER:
            for dst, logics in gdata.centerServerLogics().items():
                if groupVal in logics:
                    dstSid = dst
                    break
            if not dstSid:
                dstSid = router._centerServer.sids[0]

    if not dstSid:
        raise RpcException('RpcException ' + rpc + '! can not location the target server, rpcSrvType=' + str(
            rpcSrvType) + ' groupVal=' + str(groupVal))

    rpcid = _getRpcId()
    if dstSid == gdata.serverId():
        if markParams['syncCall']:
            if future:
                # TODO: Future RPC CALL 1
                return _FutureResultLocal(markParams, argl, argd)
            else:
                ret = _invokeMethodLocked(markParams, argl, argd)
                return strutil.cloneData(ret)
        else:
            ftt = FTLoopTimer(0.01, 0, _invokeMethodLocked, markParams, argl, argd)
            ftt.start()
            return None

    mi = strutil.dumps({'cmd': _runenv._CMD_RPC_,
                        'rpc': rpc,
                        'argl': argl,
                        'argd': argd
                        })

    if markParams['syncCall']:
        if future:
            # TODO: Future RPC CALL 1
            return _FutureResultRemote(rpc, dstSid, mi, rpcid, str(groupVal), _runenv._RPC_TIME_OUT)
        else:
            try:
                jstr = wrapper.query(dstSid, mi, rpcid, str(groupVal), _runenv._RPC_TIME_OUT)
            except FTMsgPackException, e:
                raise e
            except Exception, e:
                ftlog.warn('RpcException msg=', mi)
                raise RpcException('RpcException ' + rpc + ' ! query remote false, ' + str(e))
            return _parseRpcResult(mi, jstr, rpc)