def curTimestemp(self, msg): if _DEBUG: debug('curTimestemp->', msg) mi = self.checker.check(msg) if mi.error: ftlog.error('curTimestemp the msg params error !', mi.error) else: game_life.doGameTimestemp(mi.userId) return 1
def cancelInst(serverId, roomId, masterRoomId, instId, reason): area = getMatchArea(roomId) if not area: ftlog.error('stage_match_remote.cancelInst serverId=', serverId, 'roomId=', roomId, 'masterRoomId=', masterRoomId, 'instId=', instId, 'reason=', reason, 'err=', 'NotMatchArea') return area.cancelInst(instId, reason)
def _processPostTaskList(self): if self._postTaskList: taskList = self._postTaskList self._postTaskList = [] for task in taskList: try: task() except: ftlog.error('MatchProcesser._processPostTaskList')
def doGameReady(self, msg): if _DEBUG: debug('doGameReady->', msg) mi = self.checkSaveMatchInfo.check(msg) if mi.error: ftlog.error('doGameReady the msg params error !', mi.error) else: _srvutil_handler.updateUtilMatchStatus(mi.matchId, mi.userId) return 1
def finishOrder(self, orderId, userId, finishState): order = self._loadOrder(orderId) if not order: ftlog.error('HallStoreSystem.finishOrder userId=', userId, 'orderId=', orderId, 'err=', 'OrderNotFound') return '没有找到该订单' if order.userId != userId: ftlog.error('HallStoreSystem.finishOrder userId=', userId, 'orderId=', orderId, 'productId=', order.productId, 'chargeInfo=', order.chargeInfo, 'orderUserId=', order.userId, 'orderProductId=', order.productId, 'realGameId=', order.realGameId, 'err=', 'DiffUser') return '订单用户不匹配' if order.state == TYOrder.STATE_DELIVERY: # 有可能是直购金币的单子,已经投递完毕后的,再次砖石变化通知 ftlog.info('HallStoreSystem.finishOrder orderId=', order.orderId, 'platformOrderId=', order.platformOrderId, 'userId=', order.userId, 'gameId=', order.gameId, 'productId', order.productId, 'count=', order.count, 'chargeInfo=', order.chargeInfo, 'errorCode=', order.errorCode, 'chip product already deliver ok') return 'ok' order.state = finishState order.updateTime = fttime.getCurrentTimestamp() error, oldState = self._orderDao.updateOrder(order, TYOrder.STATE_CREATE) if error != 0: ftlog.info('HallStoreSystem.finishOrder orderId=', order.orderId, 'platformOrderId=', order.platformOrderId, 'userId=', order.userId, 'gameId=', order.gameId, 'productId', order.productId, 'count=', order.count, 'chargeInfo=', order.chargeInfo, 'errorCode=', order.errorCode, 'oldState=', oldState) return '变更订单状态错误' else: ftlog.info('HallStoreSystem.finishOrder orderId=', order.orderId, 'platformOrderId=', order.platformOrderId, 'userId=', order.userId, 'gameId=', order.gameId, 'productId', order.productId, 'count=', order.count, 'chargeInfo=', order.chargeInfo, 'errorCode=', order.errorCode) return 'ok'
def _loadSubMemberStatus(userId): try: d = pluginCross.halldata.getHallDataList(userId, HallKeys.ATT_SUBMEMBER) subDT = _decodeDT(d.get('subTime', -1)) deliveryDT = _decodeDT(d.get('deliveryTime', -1)) expiresDT = _decodeDT(d.get('expiresTime', -1)) return SubMemberStatus(False, subDT, deliveryDT, None, expiresDT) except: ftlog.error() return SubMemberStatus(False, None, None, None, None)
def finalGroup(serverId, roomId, masterRoomId, groupId): _area, group = findGroup(roomId, groupId) if not group: ftlog.error('stage_match_remote.finalGroup serverId=', serverId, 'roomId=', roomId, 'masterRoomId=', masterRoomId, 'groupId=', groupId, 'err=', 'NotFoundGroup') return group.final() ftlog.info('stage_match_remote.finalGroup serverId=', serverId, 'roomId=', roomId, 'masterRoomId=', masterRoomId, 'groupId=', groupId)
def doRoomVipTableList(self, msg): if _DEBUG: debug('doRoomVipTableList->', msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('doRoomVipTableList the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] room.doGetVipTableList(mi.userId, mi.clientId) return 1
def needAutoCheckin(self, userId): try: if self.autoCheckinLimitVersion != -1: clientId = tysessiondata.getClientId(userId) _, clientVer, _ = tyconfig.parseClientId(clientId) if clientVer >= self.autoCheckinLimitVersion: return False except: ftlog.error('TYMemberCardItemKind.needAutoCheckin userId=', userId) return True
def getChoosedInfo(self, state): ''' 根据状态选择相应的数据 部分状态下需补充若干AI规则 ''' if not state: ftlog.error('MTableStateExtendInfo.getChoosedInfo state error!') if (state & MTableState.TABLE_STATE_CHI) and (state & MTableState.TABLE_STATE_GRABTING): return self.__extend[self.GRAB_CHI_TING][0] if (state & MTableState.TABLE_STATE_PENG) and (state & MTableState.TABLE_STATE_GRABTING): return self.__extend[self.GRAB_PENG_TING][0] if (state & MTableState.TABLE_STATE_GANG) and (state & MTableState.TABLE_STATE_GRABTING): return self.__extend[self.GRAB_GANG_TING][0] if (state & MTableState.TABLE_STATE_ZHAN) and (state & MTableState.TABLE_STATE_GRABTING): return self.__extend[self.GRAB_ZHAN_TING][0] if state & MTableState.TABLE_STATE_HU: return self.__extend[self.WIN][0] if state & MTableState.TABLE_STATE_TING: return self.getBestTingInfo() if state & MTableState.TABLE_STATE_GANG: ftlog.debug('MTableStateExtendInfo.getChoosedInfo gangs:', self.__extend[self.GANG] , ' choosed:', self.__extend[self.GANG][0]) return self.__extend[self.GANG][0] if state & MTableState.TABLE_STATE_PENG: return self.__extend[self.PENG][0] if state & MTableState.TABLE_STATE_CHI: return self.__extend[self.CHI][0] if state & MTableState.TABLE_STATE_QIANGGANG: return self.__extend[self.QIANG_GANG_HU][0] if state & MTableState.TABLE_STATE_QIANG_EXMAO: return self.__extend[self.QIANG_EXMAO][0] if state & MTableState.TABLE_STATE_QIANG_EXMAO_HU: return self.__extend[self.QIANG_EXMAO_HU][0] if state & MTableState.TABLE_STATE_FANGMAO: return self.extend[self.MAO][0] if state & MTableState.TABLE_STATE_BUFLOWER: return self.extend[self.BUFLOWER][0] if state & MTableState.TABLE_STATE_ABSENCE: return self.extend[self.ABSENCE][0]
def decodeDbData(self, data): try: self.unReadCount = data[0] for itemId in data[1]: self.itemDatas[itemId] = RedPoint.STATUS_READ for itemId in data[2]: self.itemDatas[itemId] = RedPoint.STATUS_UNREAD return self except: ftlog.error('RedPoint=', self, 'data=', data) return None
def doTableSit(self, msg): if _DEBUG: debug('doTableSit->', msg) mi = self.checker2.check(msg) if mi.error: ftlog.error('doTableSit the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doSit(msg, mi.userId, mi.seatId0, mi.clientId) return 1
def playerGiveUp(self, roomId, tableId, userId): """ 玩家放弃比赛 """ try: ftlog.info('PokerMatchTableController.playerGiveUp', 'userId=', userId) stage_match_table_remote.doGiveUp(roomId, tableId, userId) except: ftlog.error('PokerMatchTableController.playerGiveUp', 'userId=', userId)
def doTableCall(self, msg): if _DEBUG: debug('doTableCall->', msg) mi = self.checker3.check(msg) if mi.error: ftlog.error('doTableCall the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doTableCall(msg, mi.userId, mi.seatIdObserver, mi.action, mi.clientId) return 1
def autoProcessChangeTiles(self, seatId): ''' 自动处理换三张 ''' ftlog.debug('ActionHandler.autoProcessChangeTiles seatId:', seatId) player = self.table.player[seatId] if not player: ftlog.error('ActionHandler.autoProcessChangeTiles player not valid...') return self.consumeSmartOperateCount(player) self.table.processChangeTiles(seatId)
def doClientRoomList(self, msg): ''' 获取房间列表 ''' if _DEBUG: debug('doClientRoomList->', msg) mi = self.checkerRoomLlist.check(msg) if mi.error: ftlog.error('doClientRoomList the msg params error !', mi.error) else: game_ui.doRoomList(mi.userId, mi.gameId, mi.playMode1) return 1
def initStageMatch(self): ftlog.info('StageMatchRoomMixin.initStageMatch ...', 'bigRoomId=', self.bigRoomId, 'matchId=', self.matchId, 'roomId=', self.roomId) conf = StageMatchConf(self.gameId, self.matchId) conf.decodeFromDict(self.matchConf) conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 self.conf = conf self.bigmatchId = self.bigRoomId self.masterRoomId = self.getMasterRoomId() self.isMaster = self.roomId == self.masterRoomId tableManager = MatchTableManager(self.gameId, conf.tableSeatCount) shadowRoomIds = self.shadowRoomIds ftlog.info('StageMatchRoomMixin.initStageMatch', 'roomId=', self.roomId, 'shadowRoomIds=', list(shadowRoomIds)) for tableRoomId in shadowRoomIds: count = self.tableCount baseId = tableRoomId * 10000 ftlog.info('StageMatchRoomMixin.initStageMatch addTables', 'roomId=', self.roomId, 'tableRoomId=', tableRoomId, 'tableCount=', count, 'baseId=', baseId) tableManager.addTables(tableRoomId, baseId, count) tableManager.shuffleIdleTable() area, master = self.buildStageMatch() if tyglobal.mode() == tyglobal.RUN_MODE_ONLINE: # TODO 线上模式检测,上线前需谨慎检查 playerCapacity = int(tableManager.allTableCount * tableManager.tableSeatCount * 0.9) if playerCapacity <= conf.startConf.userMaxCountPerMatch: ftlog.error('StageMatchRoomMixin.initStageMatch', 'allTableCount=', tableManager.allTableCount, 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'userMaxCount=', conf.startConf.userMaxCount, 'confUserMaxCountPerMatch=', conf.startConf.userMaxCountPerMatch, 'err=', 'NotEnoughTable') assert (playerCapacity > conf.startConf.userMaxCountPerMatch) area.tableManager = tableManager self.matchArea = area self.matchMaster = master if master: master.start() area.start()
def doTableManage(self, msg): # TODO 转换为RPC模式 if _DEBUG: debug('doTableManage->', msg) mi = self.checker3.check(msg) if mi.error: ftlog.error('doTableManage the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doTableManage(msg, mi.action) return 1
def save(self, gameId, status): """ 保存赛事状态 """ try: d = {'seq': status.seq, 'startTime': status.startTime} jstr = json.dumps(d) basedao.saveMatchStatus(gameId, status.matchId, jstr) except: ftlog.error('StageMatchStatusDaoRedis.save', 'matchId=', status.matchId, 'seq=', status.seq, 'startTime=', status.startTime)
def doClientGameLeave(self, msg): ''' 离开游戏 ''' if _DEBUG: debug('doClientGameLeave->', msg) mi = self.checker.check(msg) if mi.error: ftlog.error('doClientGameLeave the msg params error !', mi.error) else: game_life.doGameLeave(mi.userId, mi.clientId) return 1
def querySNS(api, params, sign=False): code = 200 try: if _DEBUG: debug('querySNS->', api, params) code, page = tyadapter.queryAdapter(_ADAPTER_SNS, params, {}, api) if _DEBUG: debug('querySNS->', api, code, page) return ftstr.loads(page) except: ftlog.error() return {'error': code}
def getTableStates(cls, playMode): """发牌器获取工厂 输入参数: playMode - 玩法 返回值: 对应玩法的牌桌状态 """ if playMode == MPlayMode.HAERBIN: return MTableStateHaerbin() elif playMode == MPlayMode.MUDANJIANG: return MTableStateMudanjiang() elif playMode == MPlayMode.XUEZHANDAODI: return MTableStateXuezhan() elif playMode == MPlayMode.XUELIUCHENGHE: return MTableStateXueliu() elif playMode == MPlayMode.JIXI: return MTableStateJixi() elif playMode == MPlayMode.PINGDU: return MTableStatePingDu() elif playMode == MPlayMode.PINGDU258: return MTableStatePingDu() elif playMode == MPlayMode.WEIHAI: return MTableStateWeihai() elif playMode == MPlayMode.BAICHENG: return MTableStateBaicheng() elif playMode == MPlayMode.PANJIN: return MTableStatePanjin() elif playMode == MPlayMode.DANDONG: return MTableStateDandong() elif playMode == MPlayMode.WUHU: return MTableStateWuHu() elif playMode == MPlayMode.HUAINING: return MTableStateHuaiNing() elif playMode == MPlayMode.YANTAI: return MTableStateYantai() elif playMode == MPlayMode.CHAOHU: return MTableStateChaoHu() elif playMode == MPlayMode.JINAN: return MTableStateJinan() elif playMode == MPlayMode.HEXIAN: return MTableStateHeXian() elif playMode == MPlayMode.WUWEI \ or playMode == MPlayMode.HANSHAN: return MTableStateWuWei() elif playMode == MPlayMode.SANXIAN: return MTableStateSanXian() elif playMode == MPlayMode.JIPINGHU: return MTableStateJiPingHu() ftlog.error('TableStateFactory.getTableStates error, playMode:', playMode) return None
def doWinlose(roomId, tableId, info): ftlog.info('stage_match_remote.doWinlose roomId=', roomId, 'msg=', info) _area = getMatchArea(roomId) if not _area: ftlog.error('stage_match_remote.doWinlose ', 'roomId=', roomId, 'err=', 'NotFoundArea') return groupId = info.get('groupId') ccrc = info.get('ccrc') seatWinloses = info.get('seatWinloses') # TODO find groupId by tableId _area.tableWinlose(groupId, tableId, ccrc, seatWinloses)
def handleTableCallGrabHuGang(self, userId, seatId, message): """处理抢杠胡""" actionId = self.getActionIdFromMessage(message) if actionId == self.table.actionID: winTile = message.getParam('tile', None) if winTile: self.table.gameWin(seatId, winTile, True) else: ftlog.error("handleTableCallGrabHuGang winTile is None") else: ftlog.info('handleTableCallGrabHuGang message:', message, ' but actionID is wrong, actionIDInTable:', self.table.actionID, ' actionIDInMsg:', actionId)
def getJdAddress(proviceId, cityId, countyId): try: if proviceId: resp = tyrpcgdss.getJdCity(proviceId) elif cityId: resp = tyrpcgdss.getJdCounty(cityId) elif countyId: resp = tyrpcgdss.getJdTown(countyId) else: resp = tyrpcgdss.getJdProvice() return resp except: ftlog.error('getJdAddress', proviceId, cityId, countyId) return {}
def doMatchQuickStart(self, msg): ftlog.info('StageMatchRoomMixin._do_room__quick_start') assert (self.roomId == msg.getParam('roomId')) userId = msg.getParam('userId') tableId = msg.getParam('tableId') roomId = msg.getParam('roomId') gameId = msg.getParam('gameId') ftlog.info('StageMatchRoomMixin._do_room__quick_start', 'userId=', userId, 'tableId=', tableId, 'roomId=', roomId, 'gameId=', gameId, 'confTableId=', self.conf.tableId) player = self.matchArea.findPlayer(userId) if player is None: ftlog.warn('StageMatchRoomMixin._do_room__quick_start', 'userId=', userId, 'tableId=', tableId, 'roomId=', roomId, 'gameId=', gameId, 'err=', 'NotFoundPlayer') try: # 可能是之前在gt中的tableId unlockUserForMatch(userId, self.roomId, tableId) except: ftlog.error('StageMatchRoomMixin._do_room__quick_start', 'userId=', userId, 'tableId=', tableId, 'roomId=', roomId, 'gameId=', gameId) reason = TYRoom.ENTER_ROOM_REASON_INNER_ERROR info = u'在线状态错误或其他系统内部错误' self._sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, 0, info) return # 确认是在房间掉线 if tableId == self.conf.tableId: # 玩家在队列里时断线重连 reason = TYRoom.ENTER_ROOM_REASON_OK self._sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, self.conf.tableId) # 如果用户已经被分组则发送等待信息 if player.group: self._sendMatchStatas(player.userId) self._sendMatchRanks(player.userId) self._sendDesc(player.userId) self.matchArea.playerNotifier.notifyMatchWait(player, 1) else: # 玩家在牌桌上断线重连,游戏的UT补齐下面的参数 extParams = msg.getKey('params') # 开放给用户的扩展参数 clientId = msg.getParam("clientId") # clientId shadowRoomId = msg.getParam("shadowRoomId") # GT的房间ID self._sendMatchStatas(player.userId) self._sendMatchRanks(player.userId) self._sendDesc(player.userId)
def _onTimeout(self): try: self._processPostTaskList() newInterval = self._handler() if newInterval is not None: self._interval = newInterval self._processPostTaskList() except: self._interval = 1 ftlog.error('MatchProcesser._onTimeout', self._handler) raise finally: if self._state == self.ST_START: self._timer = ftcore.runOnceDelay(self._interval, self._onTimeout)
def notifyMatchUpdate(self, userId): """ 通知比赛更新. 比赛前,报名人数更新 比赛中,参数人数更新 """ try: if ftlog.is_debug(): ftlog.debug('PokerMatchPlayerNotifier.notifyMatchUpdate', 'userId=', userId) self._notifyMatchUpdate(userId) except: ftlog.error('PokerMatchPlayerNotifier.notifyMatchUpdate', 'userId=', userId)
def createGroup(serverId, roomId, masterRoomId, instId, matchingId, groupId, groupName, stageIndex, isGrouping, totalPlayerCount, startStageIndex): area = getMatchArea(roomId) if not area: ftlog.error('stage_match_remote.createGroup serverId=', serverId, 'roomId=', roomId, 'masterRoomId=', masterRoomId, 'instId=', instId, 'matchingId=', matchingId, 'groupId=', groupId, 'stageIndex=', stageIndex, 'isGrouping=', isGrouping, 'totalPlayerCount=', totalPlayerCount, 'err=', 'NotMatchArea') return area.createGroup(instId, matchingId, groupId, groupName, stageIndex, isGrouping, totalPlayerCount, startStageIndex)
def instStart(serverId, roomId, masterRoomId, instId): area = getMatchArea(roomId) if not area: ftlog.error('stage_match_remote.instStart serverId=', serverId, 'roomId=', roomId, 'masterRoomId=', masterRoomId, 'instId=', instId, 'err=', 'NotFoundMatch') return if not area.curInst or area.curInst.instId != instId: ftlog.error('stage_match_remote.instStart serverId=', serverId, 'roomId=', roomId, 'masterRoomId=', masterRoomId, 'instId=', instId, 'curInstId=', area.curInst.instId if area.curInst else None, 'err=', 'DiffInstId') return area.curInst.start()