def onSitOk(self, userId, idleSeatId, result): '''坐下条件成功后的处理 ''' if ftlog.is_debug(): ftlog.debug('onSitOk << |userId, tableId, seatId:', userId, self.tableId, idleSeatId, "|observers:", self.observers, caller=self) # 设置玩家坐在座位上 seat = self.table.seats[idleSeatId - 1] seat.userId = userId seat.setWaitingState() if ftlog.is_debug(): ftlog.debug("|seats:", self.table.seats, caller=self) if userId in self.table.observers: del self.table.observers[userId] onlinedata.removeOnlineLoc(userId, self.roomId, self.tableId) # 设置玩家的在线状态 if ftlog.is_debug(): ftlog.debug("before addOnlineLoc. |tableId, onlineSeatId:", self.tableId, onlinedata.getOnlineLocSeatId(userId, self.roomId, self.tableId), caller=self) onlinedata.addOnlineLoc(userId, self.roomId, self.tableId, idleSeatId) if ftlog.is_debug(): ftlog.debug("after addOnlineLoc. |tableId, onlineSeatId:", self.tableId, onlinedata.getOnlineLocSeatId(userId, self.roomId, self.tableId), caller=self) result["seatId"] = idleSeatId result["reason"] = TYRoom.ENTER_ROOM_REASON_OK ftlog.hinfo('onSitOk >> |userId, tableId, seatId:', userId, self.tableId, idleSeatId, "|observers:", self.observers, caller=self)
def resumeItemFromTable(userId, gameId, itemId, count, roomId, tableId, bigRoomId): """退还房卡,加锁操作""" ftlog.debug('user_remote resumeItemFromTable userId:', userId , ' gameId:', gameId , ' itemId:', itemId , ' count:', count , ' roomId:', roomId , ' tableId:', tableId , ' bigRoomId:', bigRoomId ) lseatId = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) ftlog.debug('user_remote resumeItemFromTable lseatId:', lseatId) if lseatId < 0: ftlog.info('user_remote resumeItemFromTable loc not match, do not resume item. userId:', userId , ' gameId:', gameId , ' itemId:', itemId , ' count:', count , ' roomId:', roomId , ' tableId:', tableId , ' seatId:', lseatId) return MajiangItem.addUserItemByKindId(userId , gameId , itemId , count , 'MAJIANG_FANGKA_RETURN_BACK' , bigRoomId)
def clearInvalidObservers(self): '''一段防御性代码,防止本桌上一局的旁观者未被及时清理,下一局开局时换到了别的桌子,但收到本桌的协议 ''' invalidObservers = [] for userId in self.observers: onlineSeatId = onlinedata.getOnlineLocSeatId(userId, self.roomId, self.tableId) if onlineSeatId == 0: # Note: 断线的旁观玩家不做清理,table._doClearPlayers会处理 ftlog.warn(self._baseLogStr('invalid observer found', userId), '|locList:', onlinedata.getOnlineLocList(userId), caller=self) invalidObservers.append(userId) for userId in invalidObservers: del self.observers[userId]
def doQuickStart(self, msg): assert self.roomId == msg.getParam("roomId") userId = msg.getParam("userId") shadowRoomId = msg.getParam("shadowRoomId") tableId = msg.getParam("tableId") clientId = msg.getParam("clientId") ftlog.hinfo("doQuickStart <<", "|userId, clientId, roomId, shadowRoomId, tableId:", userId, clientId, self.roomId, shadowRoomId, tableId) # msg = TYPluginCenter.event(TYPluginUtils.updateMsg(cmd='EV_QUICK_START', params=TYPluginUtils.mkdict( # userId=userId, roomId=self.roomId), result={}), self.gameId) # # if msg.getResult("reason") != None: # info = u'玩家需要验证' # self.sendQuickStartRes(self.gameId, userId, msg.getResult("reason"), self.bigRoomId, 0, info) # return if tableId == 0: isOk, reason = self.doEnter(userId) elif tableId == self.roomId * 10000: if userId in self._roomUsers: isOk = True # 玩家在队列里时断线重连 reason = TYRoom.ENTER_ROOM_REASON_OK else: # 服务器重启造成玩家已经不在房间对象里了 onlinedata.removeOnlineLoc(userId, self.roomId, tableId) isOk = False reason = TYRoom.ENTER_ROOM_REASON_CONFLICT else: # 防御性代码,处理快速开始online错乱 onlineSeat = onlinedata.getOnlineLocSeatId(userId, shadowRoomId, tableId) if onlineSeat == 0: # 断线重连过程中玩家因为超时、金币不足或比赛淘汰等原因已被踢出房间 isOk = False reason = TYRoom.ENTER_ROOM_REASON_CONFLICT ftlog.warn("doQuickStart conflict!", "|userId, onlineLocList:", userId, onlinedata.getOnlineLocList(userId), "|shadowRoomId, tableId:", shadowRoomId, tableId) else: ftlog.error("doQuickStart conflict!", "|onlineSeat:", onlineSeat) if onlineSeat == gdata.roomIdDefineMap()[shadowRoomId].configure['tableConf']['maxSeatN'] + 1: # 牌桌里旁观的玩家断线重连,请求转给GT self.sendTableCallObserveReq(userId, shadowRoomId, tableId, clientId) elif onlineSeat > 0: # 牌桌里坐着的玩家断线重连,请求转给GT self.querySitReq(userId, shadowRoomId, tableId, clientId) return if isOk: self._onQuickStartOk(userId) elif reason == TYRoom.ENTER_ROOM_REASON_CONFLICT: info = u'玩家已经在游戏中,状态冲突' self.sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, 0, info) else: self.sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, 0, '')
def onSitOk(self, userId, idleSeatId, result): '''坐下条件成功后的处理 Return: player:新空座位上的player ''' ftlog.hinfo('onSitOk << |userId, tableId, seatId:', userId, self.tableId, idleSeatId, "|observers:", self.observers, caller=self) # 设置玩家坐在座位上, 为了支持并发坐下,此设置需要在异步操作前完成!!! seat = self.table.seats[idleSeatId - 1] seat.userId = userId seat.setWaitingState() if ftlog.is_debug(): ftlog.debug("|seats:", self.table.seats, caller=self) if userId in self.table.observers: del self.table.observers[userId] onlinedata.removeOnlineLoc(userId, self.roomId, self.tableId) # 设置玩家的在线状态 if ftlog.is_debug(): ftlog.debug("before addOnlineLoc. |tableId, onlineSeatId:", self.tableId, onlinedata.getOnlineLocSeatId(userId, self.roomId, self.tableId), caller=self) onlinedata.addOnlineLoc(userId, self.roomId, self.tableId, idleSeatId) if ftlog.is_debug(): ftlog.debug("after addOnlineLoc. |tableId, onlineSeatId:", self.tableId, onlinedata.getOnlineLocSeatId(userId, self.roomId, self.tableId), caller=self) # 记录当前座位的userId, 以便对玩家的金币做恢复处理 self.table.recordSeatUserId(idleSeatId, userId) result["seatId"] = idleSeatId result["reason"] = TYRoom.ENTER_ROOM_REASON_OK ftlog.hinfo('onSitOk >> |userId, tableId, seatId:', userId, self.tableId, idleSeatId, "|observers:", self.observers, caller=self)
def resumeItemFromTable(userId, gameId, itemId, count, roomId, tableId, bigRoomId): """退还房卡,加锁操作""" ftlog.debug('user_remote resumeItemFromTable userId:', userId, ' gameId:', gameId, ' itemId:', itemId, ' count:', count, ' roomId:', roomId, ' tableId:', tableId, ' bigRoomId:', bigRoomId) lseatId = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) ftlog.debug('user_remote resumeItemFromTable lseatId:', lseatId) if lseatId < 0: ftlog.info( 'user_remote resumeItemFromTable loc not match, do not resume item. userId:', userId, ' gameId:', gameId, ' itemId:', itemId, ' count:', count, ' roomId:', roomId, ' tableId:', tableId, ' seatId:', lseatId) return MajiangItem.addUserItemByKindId(userId, gameId, itemId, count, 'MAJIANG_FANGKA_RETURN_BACK', bigRoomId)
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, clientId, kindId): """UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR """ assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 if ftlog.is_debug(): ftlog.debug("onCmdQuickStart->", userId, "msg =", msg, "roomId =", roomId, "tableId =", tableId, "clientId =", clientId) isRobot = userId < config.ROBOT_MAX_USER_ID if not isRobot and not util.isUsableClientVersion(userId): cls.onQuickStartFailed(cls.ENTER_ROOM_REASON_VERSION_DISABLE, userId, clientId, roomId) return # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): locList = onlinedata.getOnlineLocList(userId) if ftlog.is_debug(): ftlog.debug("onCmdQuickStart->getOnlineLocList->", userId, locList) try: for lRoomId, lTableId, lSeatId in locList: roomGameId = strutil.getGameIdFromInstanceRoomId(lRoomId) if roomGameId == FISH_GAMEID: roomId = lRoomId tableId = lTableId ftlog.info( "onCmdQuickStart->reconnect roomId, tableId->", userId, roomId, tableId) else: cls.onQuickStartFailed( cls.ENTER_ROOM_REASON_STATE_ERROR, userId, clientId, roomId) return break except: ftlog.warn("onCmdQuickStart->error", userId, roomId, tableId) redState = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.redState) if isRobot is False and redState == 0: ctrlRoomId = config.getCommonValueByKey("newbieRoomId") chosenTableId = 0 shadowRoomId = None if gdata.getBigRoomId(roomId) == gdata.getBigRoomId( ctrlRoomId) and tableId: chosenTableId = tableId shadowRoomId = tableId / 10000 TYRoomMixin.queryRoomQuickStartReq( msg, ctrlRoomId, chosenTableId, shadowRoomId=shadowRoomId) # 请求转给GR return if roomId == 0: # 玩家点击快速开始 chosenRoomId, reason = cls._chooseRoom(userId, gameId) ftlog.info("onCmdQuickStart->chosenRoomId", chosenRoomId, "userId =", userId, "reason =", reason) if reason == cls.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: cls.onQuickStartFailed(reason, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 bigRoomId = gdata.getBigRoomId(roomId) if bigRoomId == 0: cls.onQuickStartFailed(cls.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return ctrlRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrlRoomIds[userId % len(ctrlRoomIds)] reason = cls.canQuickEnterRoom(userId, gameId, ctrlRoomId, kindId) if reason == cls.ENTER_ROOM_REASON_OK: roomConf = gdata.roomIdDefineMap()[roomId].configure fee = roomConf.get("fee_%s" % kindId, {}) or roomConf.get( "fee", {}) rewards = fee.get("rewards", []) if fee: _consume = [{"name": fee["kindId"], "count": fee["count"]}] ret = util.consumeItems(userId, _consume, "ROOM_GAME_FEE") if ret and rewards: util.addRewards(userId, rewards, "BI_NFISH_VOUCHER_REWARDS", kindId) TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT else: cls.onQuickStartFailed(reason, userId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: TYRoomMixin.querySitReq(userId, roomId, tableId, clientId, {"seatId": onlineSeat}) # 玩家断线重连,请求转给GT else: # 玩家选择了桌子 shadowRoomId = tableId / 10000 ctrlRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq( msg, ctrlRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def createTableQuickStart(cls, msg, itemParams, userId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的create_table请求 Args: msg cmd : create_table if roomId == 0: 表示玩家创建房间,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", playMode, caller=cls) isReconnect = False gameId = msg.getResult('gameId') # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, gameId) ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts( lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: roomId = lroomId tableId = ltableId isReconnect = True ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if (not isReconnect) and roomId > 0 and tableId > 0: reason = cls._canQuickEnterCreateRoom(userId, gameId, roomId) if reason != TYRoom.ENTER_ROOM_REASON_OK: cls._onEnterCreateRoomFailed(reason, userId, gameId, clientId, roomId) return tempShadowRoomId = 0 if roomId == 0: # 第一个玩家创建房间牌桌 chosenRoomId, checkResult = cls._chooseCreateRoom( userId, gameId, playMode) ftlog.info("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: #得到房间ID,找合适的tableId roomDef = gdata.roomIdDefineMap()[chosenRoomId] shadowRoomIds = roomDef.shadowRoomIds if shadowRoomIds: for shadowRoomId in shadowRoomIds: tableId = table_rpc.getTableByRoomId(shadowRoomId) if isinstance(tableId, int) and tableId > 0: tempShadowRoomId = shadowRoomId break shadowRoomId = tableId / 10000 if shadowRoomId == tempShadowRoomId: # 验证 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq( msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR return else: cls._onEnterCreateRoomFailed(checkResult, userId, gameId, clientId, roomId) return else: cls._onEnterCreateRoomFailed(checkResult, userId, gameId, clientId, roomId) return else: onlineSeat = onlinedata.getOnlineLocSeatId(userId, gameId, roomId, tableId) if onlineSeat: extParam = {} extParam['seatId'] = onlineSeat moParams = msg.getKey('params') for k, v in moParams.items(): if not k in extParam: extParam[k] = v ftlog.debug('extParam=', extParam) TYRoomMixin.querySitReq(userId, roomId, tableId, clientId, extParam) # 玩家断线重连,请求转给GT return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return # 玩家选择了桌子,进桌 shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 ftlog.debug("MajiangQuickStartV4_0.onCmdQuickStart clientId:", clientId, " userId:", userId, " roomId:", roomId, " tableId:", tableId, " gameId:", gameId, " playMode:", playMode) isCreate = False if roomId > 0: isCreate = cls.isFriendRoom(roomId) isReconnect = False # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) ftlog.debug('MajiangQuickStartV4_0.onCmdQuickStart checkUserLoc:', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts( lgameId, lroomId, ltableId, lseatId) if isCreate and (lroomId == 0) and (ltableId == 0): # 好友桌的快速开始必须有loc,没有loc则进桌失败 ftlog.debug( 'MajiangQuickStartV4_0.onCmdQuickStart room is friendTable, loc is 0, means, table is dissolved...' ) cls._onEnterRoomFailed( msg, TYRoom.ENTER_ROOM_REASON_FRIEND_DISSOLVE, userId, clientId, roomId) return if lgameId == gameId and lroomId > 0: roomId = lroomId tableId = ltableId isReconnect = True ftlog.debug( 'MajiangQuickStartV4_0.onCmdQuickStart old client roomId:', roomId, ' tableId:', tableId, caller=cls) if (not isReconnect) and roomId > 0 and tableId > 0: reason = cls._canQuickEnterRoom(userId, gameId, roomId, 1) if reason != TYRoom.ENTER_ROOM_REASON_OK: cls._onEnterRoomFailed(msg, reason, userId, gameId, clientId, roomId) return if roomId == 0: # 玩家点击快速开始 chosenRoomId, checkResult = cls._chooseRoom( userId, gameId, playMode) ftlog.info( "MajiangQuickStartV4_0.onCmdQuickStart after choose room userId:", userId, " chosenRoomId:", chosenRoomId, " checkResult:", checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: #找到合适的房间 根据roomId找到合适的table TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: candidateRoomIds = cls._getCandidateRoomIds(gameId, playMode) if candidateRoomIds: rid = candidateRoomIds[0] msg.setParam('candidateRoomId', rid) cls._onEnterRoomFailed(msg, checkResult, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 bigRoomId = gdata.getBigRoomId(roomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, gameId, clientId, roomId) return ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] reason = cls._canQuickEnterRoom(userId, gameId, ctrlRoomId, 1) if reason == TYRoom.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT else: cls._onEnterRoomFailed(msg, reason, userId, gameId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: extParam = {} extParam['seatId'] = onlineSeat moParams = msg.getKey('params') for k, v in moParams.items(): if not k in extParam: extParam[k] = v ftlog.debug('extParam=', extParam) TYRoomMixin.querySitReq(userId, roomId, tableId, clientId, extParam) # 玩家断线重连,请求转给GT else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq( msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def createTableQuickStart(cls, msg, itemParams, userId, roomId, tableId, playMode, clientId): """ UT server中处理来自客户端的create_table请求 Args: msg cmd : create_table if roomId == 0: 表示玩家创建房间,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR """ assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", playMode, caller=cls) isReconnect = False gameId = msg.getResult('gameId') # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, gameId) ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: roomId = lroomId tableId = ltableId isReconnect = True ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if (not isReconnect) and roomId > 0 and tableId > 0: reason = cls._canQuickEnterCreateRoom(userId, gameId, roomId) if reason != TYRoom.ENTER_ROOM_REASON_OK: cls._onEnterCreateRoomFailed(reason, userId, gameId, clientId, roomId) return tempShadowRoomId = 0 if roomId == 0: # 第一个玩家创建房间牌桌 chosenRoomId, checkResult = cls._chooseCreateRoom(userId, gameId, playMode) ftlog.info("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: # 得到房间ID,找合适的tableId roomDef = gdata.roomIdDefineMap()[chosenRoomId] shadowRoomIds = roomDef.shadowRoomIds if shadowRoomIds: for shadowRoomId in shadowRoomIds: tableId = table_rpc.getTableByRoomId(shadowRoomId) if isinstance(tableId, int) and tableId > 0: tempShadowRoomId = shadowRoomId break shadowRoomId = tableId / 10000 if shadowRoomId == tempShadowRoomId: # 验证 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR return else: cls._onEnterCreateRoomFailed(checkResult, userId, gameId, clientId, roomId) return else: cls._onEnterCreateRoomFailed(checkResult, userId, gameId, clientId, roomId) return else: onlineSeat = onlinedata.getOnlineLocSeatId(userId, gameId, roomId, tableId) if onlineSeat: extParam = {} extParam['seatId'] = onlineSeat moParams = msg.getKey('params') for k, v in moParams.items(): if not k in extParam: extParam[k] = v ftlog.debug('extParam=', extParam) TYRoomMixin.querySitReq(userId, roomId, tableId, clientId, extParam) # 玩家断线重连,请求转给GT return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return # 玩家选择了桌子,进桌 shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", gameId, playMode, caller=cls) isReconnect = False # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: roomId = lroomId tableId = ltableId isReconnect = True ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if (not isReconnect) and roomId > 0 and tableId > 0: reason = cls._canQuickEnterRoom(userId, gameId, roomId, 1) if reason != TYRoom.ENTER_ROOM_REASON_OK: cls._onEnterRoomFailed(msg, reason, userId, gameId, clientId, roomId) return if roomId == 0: # 玩家点击快速开始 chosenRoomId, checkResult = cls._chooseRoom(userId, gameId, playMode) ftlog.info("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: # 找到合适的房间 根据roomId找到合适的table TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: candidateRoomIds = cls._getCandidateRoomIds(gameId, playMode) if candidateRoomIds: rid = candidateRoomIds[0] msg.setParam('candidateRoomId', rid) cls._onEnterRoomFailed(msg, checkResult, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 bigRoomId = gdata.getBigRoomId(roomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, gameId, clientId, roomId) return ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] reason = cls._canQuickEnterRoom(userId, gameId, ctrlRoomId, 1) if reason == TYRoom.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT else: cls._onEnterRoomFailed(msg, reason, userId, gameId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: extParam = {} extParam['seatId'] = onlineSeat moParams = msg.getKey('params') for k, v in moParams.items(): if not k in extParam: extParam[k] = v ftlog.debug('extParam=', extParam) TYRoomMixin.querySitReq(userId, roomId, tableId, clientId, extParam) # 玩家断线重连,请求转给GT else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def _quickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 mixId = msg.getParam('mixId', '') _, version, _ = strutil.parseClientId(clientId) if ftlog.is_debug(): ftlog.debug("DizhuQuickStart._quickStart: clientId=", clientId, "userId=", userId, "roomId=", roomId, "tableId=", tableId, "mixId=", mixId, "version=", version, "type:", type(version), "playMode=", playMode) if playMode == "match": playMode = dizhuconf.PLAYMODE_123 if ftlog.is_debug(): ftlog.debug("DizhuQuickStart << |clientId:", clientId, "mixId:", mixId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", gameId, playMode, caller=cls) bigRoomId = gdata.getBigRoomId(roomId) if ftlog.is_debug(): ftlog.debug('DizhuQuickStart bigRoomId:', bigRoomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if strutil.getGameIdFromBigRoomId(bigRoomId) != gameId: cls._onEnterRoomFailed(msg, ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 if roomId != bigRoomId: ctrlRoomId = gdata.roomIdDefineMap()[roomId].parentId or roomId queryRoomId = roomId else: ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] queryRoomId = ctrlRoomId buyin = msg.getParam("buyin", 0) # 兼容 pc innerTable = msg.getParam("innerTable", 0) # innerTable 区分不同版本弹窗 if ftlog.is_debug(): ftlog.debug('DizhuQuickStart._quickStart', 'buyin=', buyin, 'innerTable=', innerTable, 'mixId=', mixId) if buyin: innerTable = 1 roomdef = gdata.roomIdDefineMap()[ctrlRoomId] roomConf = roomdef.configure # 免费场重起maxCoin配置 maxCoin = roomConf.get('maxCoin', 0) userChip = userchip.getChip(userId) if maxCoin > 0 and userChip >= maxCoin and innerTable == 0: cls._onEnterRoomFailed(msg, ENTER_ROOM_REASON_GREATER_MAX, userId, clientId, roomId) return # 混房的话从大到小选择一个mixId if roomConf.get('isMix') and not mixId: _, _, mixId = cls._chooseRoom(userId, [ctrlRoomId]) if mixId: msg.setParam('mixId', mixId) else: msg.setParam('mixId', roomConf.get('mixConf')[0].get('mixId')) if innerTable == 0: cls._onEnterRoomFailed(msg, ENTER_ROOM_REASON_LESS_MIN, userId, clientId, roomId) else: mixConf = cls.getMixConf( roomConf, roomConf.get('mixConf')[0].get('mixId')) new_table_remote.processLoseRoundOver( DIZHU_GAMEID, userId, clientId, mixConf.get('roomId'), minCoin=mixConf.get('minCoin')) return reasonType, reason = cls._canQuickEnterRoom(userId, ctrlRoomId, innerTable, mixId) if reason == ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, queryRoomId, 0) # 请求转给GR或GT else: if reasonType == ENTER_ROOM_REASON_TYPE_NORMAL: if reason == ENTER_ROOM_REASON_NOT_OPEN and innerTable == 1: if ftlog.is_debug(): ftlog.debug( 'DizhuQuickStart._quickStart not open userId=', userId, 'roomId=', ctrlRoomId, 'msg=', msg, 'playmode=', playMode) # 直接踢出房间 mp = MsgPack() mp.setCmd('room') mp.setParam('action', 'leave') mp.setParam('reason', TYRoom.LEAVE_ROOM_REASON_ACTIVE) mp.setParam('gameId', gameId) mp.setParam('roomId', roomId) mp.setParam('userId', userId) router.sendRoomServer(mp, roomId) return if reason == ENTER_ROOM_REASON_LESS_MIN or reason == ENTER_ROOM_REASON_GREATER_MAX: if innerTable == 1: ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] if roomdef.configure.get('isMix', 0): continueLuckyGift = cls.getMixConf( roomdef.configure, mixId).get('continueLuckyGift', 0) continueLuckyVer = cls.getMixConf( roomdef.configure, mixId).get('continueLuckyVer', 0) else: continueLuckyGift = roomdef.configure.get( 'continueLuckyGift', 0) continueLuckyVer = roomdef.configure.get( 'continueLuckyVer', 0) dizhuVersion = SessionDizhuVersion.getVersionNumber( userId) if continueLuckyGift and dizhuVersion >= continueLuckyVer: # 发送转运礼包 if ftlog.is_debug(): ftlog.debug( 'DizhuQuickStart._quickStart _less_min userId=', userId, 'roomId=', ctrlRoomId, 'msg=', msg, 'playmode=', playMode, 'continueLuckyGift=', continueLuckyGift, 'continueLuckyVer=', continueLuckyVer, 'dizhuVersion=', dizhuVersion) if mixId and roomConf.get('isMix'): mixConf = cls.getMixConf(roomConf, mixId) new_table_remote.processLoseRoundOver( DIZHU_GAMEID, userId, clientId, mixConf.get('roomId'), minCoin=mixConf.get('minCoin')) else: new_table_remote.processLoseRoundOver( DIZHU_GAMEID, userId, clientId, roomId) else: roomDef = gdata.roomIdDefineMap()[ctrlRoomId] playMode = roomDef.configure.get('playMode', None) if ftlog.is_debug(): ftlog.debug( 'DizhuQuickStart._quickStart _less_min userId=', userId, 'roomId=', ctrlRoomId, 'msg=', msg, 'playmode=', playMode) msgpack = MsgPack() msgpack.setCmd("quick_start") msgpack.setParam("userId", userId) msgpack.setParam("gameId", gameId) msgpack.setParam("clientId", clientId) msgpack.setParam("innerTable", 1) msgpack.setParam("apiver", msg.getParam("apiver", 3.7)) cls.onCmdQuickStart(msgpack, userId, gameId, 0, 0, playMode, clientId) if ftlog.is_debug(): ftlog.debug( 'DizhuQuickStart._quickStart reenter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msgpack=', msgpack.pack()) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._sendTodoTaskToUserWithTip(userId, reason) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: # 牌桌里坐着的玩家断线重连,请求转给GT # TYRoomMixin.querySitReq(userId, roomId, tableId, clientId) # GT人多时会有超时异常 TYRoomMixin.sendSitReq(userId, roomId, tableId, clientId) else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR return
def doQuickStart(self, msg): assert self.roomId == msg.getParam("roomId") userId = msg.getParam("userId") shadowRoomId = msg.getParam("shadowRoomId") tableId = msg.getParam("tableId") clientId = msg.getParam("clientId") ftlog.hinfo("doQuickStart <<", "|userId, clientId, roomId, shadowRoomId, tableId:", userId, clientId, self.roomId, shadowRoomId, tableId) msg = TYPluginCenter.event( TYPluginUtils.updateMsg(cmd='EV_QUICK_START', params=TYPluginUtils.mkdict( userId=userId, roomId=self.roomId), result={}), self.gameId) if msg.getResult("reason") != None: info = u'玩家需要验证' self.sendQuickStartRes(self.gameId, userId, msg.getResult("reason"), self.bigRoomId, 0, info) return if tableId == 0: isOk, reason = self.doEnter(userId) elif tableId == self.roomId * 10000: if userId in self._roomUsers: isOk = True # 玩家在队列里时断线重连 reason = TYRoom.ENTER_ROOM_REASON_OK else: # 服务器重启造成玩家已经不在房间对象里了 onlinedata.removeOnlineLoc(userId, self.roomId, tableId) isOk = False reason = TYRoom.ENTER_ROOM_REASON_CONFLICT else: # 防御性代码,处理快速开始online错乱 onlineSeat = onlinedata.getOnlineLocSeatId(userId, shadowRoomId, tableId) if onlineSeat == 0: # 断线重连过程中玩家因为超时、金币不足或比赛淘汰等原因已被踢出房间 isOk = False reason = TYRoom.ENTER_ROOM_REASON_CONFLICT ftlog.warn("doQuickStart conflict!", "|userId, onlineLocList:", userId, onlinedata.getOnlineLocList(userId), "|shadowRoomId, tableId:", shadowRoomId, tableId) else: ftlog.error("doQuickStart conflict!", "|onlineSeat:", onlineSeat) if onlineSeat == gdata.roomIdDefineMap( )[shadowRoomId].configure['tableConf']['maxSeatN'] + 1: # 牌桌里旁观的玩家断线重连,请求转给GT self.sendTableCallObserveReq(userId, shadowRoomId, tableId, clientId) elif onlineSeat > 0: # 牌桌里坐着的玩家断线重连,请求转给GT self.querySitReq(userId, shadowRoomId, tableId, clientId) return if isOk: self._onQuickStartOk(userId) elif reason == TYRoom.ENTER_ROOM_REASON_CONFLICT: info = u'玩家已经在游戏中,状态冲突' self.sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, 0, info) else: self.sendQuickStartRes(self.gameId, userId, reason, self.bigRoomId, 0, '')
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 if ftlog.is_debug(): ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", gameId, playMode, caller=cls) # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) if ftlog.is_debug(): ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: ftlog.debug('onCmdQuickStart re-connected |userId, loc:', userId, loc, '|roomId, tableId:', roomId, tableId, caller=cls) roomId = lroomId tableId = ltableId msg.setParam('isReConnected', True) if ftlog.is_debug(): ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if roomId == 0: # 玩家点击快速开始 chosenRoomId, checkResult = cls._chooseRoom(userId, gameId, playMode) ftlog.debug("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: candidateRoomIds = cls._getCandidateRoomIds(gameId, playMode) if candidateRoomIds: rid = candidateRoomIds[0] msg.setParam('candidateRoomId', rid) cls._onEnterRoomFailed(msg, checkResult, userId, clientId, roomId) return bigRoomId = gdata.getBigRoomId(roomId) ftlog.debug('bigRoomId:', bigRoomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if strutil.getGameIdFromBigRoomId(bigRoomId) != gameId: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 if gameId == 6 and roomId != bigRoomId: ctrlRoomId = gdata.roomIdDefineMap()[roomId].parentId queryRoomId = roomId else: ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] queryRoomId = ctrlRoomId reason = cls._canQuickEnterRoom(userId, gameId, ctrlRoomId, 1) if reason == TYRoom.ENTER_ROOM_REASON_OK: if gameId == 6: TYRoomMixin.queryRoomQuickStartReq(msg, queryRoomId, 0) # 请求转给GR或GT else: TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT elif reason == TYRoom.ENTER_ROOM_REASON_LESS_MIN or reason == TYRoom.ENTER_ROOM_REASON_GREATER_MAX: if gameId == 6: innerTable = msg.getParam("innerTable", 0) # innerTable 区分不同版本弹窗 if innerTable == 1: roomDef = gdata.roomIdDefineMap()[ctrlRoomId] playMode = roomDef.configure.get('playMode', None) if ftlog.is_debug(): ftlog.debug('enter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msg=', msg, 'playmode=', playMode) msgpack = MsgPack() msgpack.setCmd("quick_start") msgpack.setParam("userId", userId) msgpack.setParam("gameId", gameId) msgpack.setParam("clientId", clientId) msgpack.setParam("innerTable", 1) msgpack.setParam("apiver", msg.getParam("apiver", 3.7)) cls.onCmdQuickStart(msgpack, userId, gameId, 0, 0, playMode, clientId) if ftlog.is_debug(): ftlog.debug('reenter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msgpack=', msgpack.pack()) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: if onlineSeat == gdata.roomIdDefineMap()[roomId].configure['tableConf']['maxSeatN'] + 1: # 牌桌里旁观的玩家断线重连,请求转给GT TYRoomMixin.sendTableCallObserveReq(userId, roomId, tableId, clientId) else: # 牌桌里坐着的玩家断线重连,请求转给GT # TYRoomMixin.querySitReq(userId, roomId, tableId, clientId) # GT人多时会有超时异常 TYRoomMixin.sendSitReq(userId, roomId, tableId, clientId) else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq(msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def onCmdQuickStart(cls, msg, userId, gameId, roomId, tableId, playMode, clientId): '''UT server中处理来自客户端的quick_start请求 Args: msg cmd : quick_start if roomId == 0: 表示快速开始,服务器为玩家选择房间,然后将请求转给GR if roomId > 0 and tableId == 0 : 表示玩家选择了房间,将请求转给GR if roomId > 0 and tableId == roomId * 10000 : 表示玩家在队列里断线重连,将请求转给GR if roomId > 0 and tableId > 0: if onlineSeatId > 0: 表示玩家在牌桌里断线重连,将请求转给GT else: 表示玩家选择了桌子,将请求转给GR ''' assert isinstance(userId, int) and userId > 0 assert isinstance(roomId, int) and roomId >= 0 assert isinstance(tableId, int) and tableId >= 0 if ftlog.is_debug(): ftlog.debug("<< |clientId:", clientId, "|userId, roomId, tableId:", userId, roomId, tableId, "|gameId, playMode:", gameId, playMode, caller=cls) # 单开, 无论何时quick_start进入都检查loc if not pokerconf.isOpenMoreTable(clientId): loc = onlinedata.checkUserLoc(userId, clientId, gameId) if ftlog.is_debug(): ftlog.debug('old client, checkUserLoc->', loc, caller=cls) if isinstance(loc, basestring): lgameId, lroomId, ltableId, lseatId = loc.split('.') lgameId, lroomId, ltableId, lseatId = strutil.parseInts( lgameId, lroomId, ltableId, lseatId) if lgameId == gameId and lroomId > 0: ftlog.debug('onCmdQuickStart re-connected |userId, loc:', userId, loc, '|roomId, tableId:', roomId, tableId, caller=cls) roomId = lroomId tableId = ltableId msg.setParam('isReConnected', True) if ftlog.is_debug(): ftlog.debug('old client, reset roomId, tableId->', roomId, tableId, caller=cls) if roomId == 0: # 玩家点击快速开始 chosenRoomId, checkResult = cls._chooseRoom( userId, gameId, playMode) ftlog.debug("after choose room", "|userId, chosenRoomId, checkResult:", userId, chosenRoomId, checkResult, caller=cls) if checkResult == TYRoom.ENTER_ROOM_REASON_OK: TYRoomMixin.queryRoomQuickStartReq(msg, chosenRoomId, 0) # 请求转给GR else: candidateRoomIds = cls._getCandidateRoomIds(gameId, playMode) if candidateRoomIds: rid = candidateRoomIds[0] msg.setParam('candidateRoomId', rid) cls._onEnterRoomFailed(msg, checkResult, userId, clientId, roomId) return bigRoomId = gdata.getBigRoomId(roomId) ftlog.debug('bigRoomId:', bigRoomId) if bigRoomId == 0: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if strutil.getGameIdFromBigRoomId(bigRoomId) != gameId: cls._onEnterRoomFailed(msg, TYRoom.ENTER_ROOM_REASON_ROOM_ID_ERROR, userId, clientId, roomId) return if tableId == 0: # 玩家只选择了房间 if gameId == 6 and roomId != bigRoomId: ctrlRoomId = gdata.roomIdDefineMap()[roomId].parentId or roomId queryRoomId = roomId else: ctrRoomIds = gdata.bigRoomidsMap()[bigRoomId] ctrlRoomId = ctrRoomIds[userId % len(ctrRoomIds)] queryRoomId = ctrlRoomId reason = cls._canQuickEnterRoom(userId, gameId, ctrlRoomId, 1) if reason == TYRoom.ENTER_ROOM_REASON_OK: if gameId == 6: TYRoomMixin.queryRoomQuickStartReq(msg, queryRoomId, 0) # 请求转给GR或GT else: TYRoomMixin.queryRoomQuickStartReq(msg, ctrlRoomId, 0) # 请求转给GR或GT elif reason == TYRoom.ENTER_ROOM_REASON_LESS_MIN or reason == TYRoom.ENTER_ROOM_REASON_GREATER_MAX: if gameId == 6: innerTable = msg.getParam("innerTable", 0) # innerTable 区分不同版本弹窗 if innerTable == 1: roomDef = gdata.roomIdDefineMap()[ctrlRoomId] playMode = roomDef.configure.get('playMode', None) if ftlog.is_debug(): ftlog.debug('enter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msg=', msg, 'playmode=', playMode) msgpack = MsgPack() msgpack.setCmd("quick_start") msgpack.setParam("userId", userId) msgpack.setParam("gameId", gameId) msgpack.setParam("clientId", clientId) msgpack.setParam("innerTable", 1) msgpack.setParam("apiver", msg.getParam("apiver", 3.7)) # 驱动 cls.onCmdQuickStart(msgpack, userId, gameId, 0, 0, playMode, clientId) if ftlog.is_debug(): ftlog.debug('reenter_less_min userId=', userId, 'roomId=', ctrlRoomId, 'msgpack=', msgpack.pack()) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) else: cls._onEnterRoomFailed(msg, reason, userId, clientId, roomId) return if tableId == roomId * 10000: # 玩家在队列里断线重连 4400150010001 TYRoomMixin.queryRoomQuickStartReq(msg, roomId, tableId) # 请求转给GR return onlineSeat = onlinedata.getOnlineLocSeatId(userId, roomId, tableId) if onlineSeat: if onlineSeat == gdata.roomIdDefineMap( )[roomId].configure['tableConf']['maxSeatN'] + 1: # 牌桌里旁观的玩家断线重连,请求转给GT TYRoomMixin.sendTableCallObserveReq(userId, roomId, tableId, clientId) else: # 牌桌里坐着的玩家断线重连,请求转给GT # TYRoomMixin.querySitReq(userId, roomId, tableId, clientId) # GT人多时会有超时异常 TYRoomMixin.sendSitReq(userId, roomId, tableId, clientId) else: # 玩家选择了桌子, shadowRoomId = tableId / 10000 ctrRoomId = gdata.roomIdDefineMap()[shadowRoomId].parentId TYRoomMixin.queryRoomQuickStartReq( msg, ctrRoomId, tableId, shadowRoomId=shadowRoomId) # 请求转给GR
def _getValidIdleSeatId(self, userId, seatIndex, result): '''通用坐下合法性检查函数 Returns idleSeatId: >0 : 为新玩家找到合适座位,需要继续处理 <0 : 断线重连 0 : 坐下失败 ''' clientId = sessiondata.getClientId(userId) onlineSeatId = onlinedata.getOnlineLocSeatId(userId, self.table.roomId, self.table.tableId) if onlineSeatId and onlineSeatId <= self.maxSeatN: # 断线重连, Note:旁观的人坐下此处不能返回负数,否则无法入座 ftlog.hinfo('re-sit ok. |userId, tableId, seatId:', userId, self.tableId, onlineSeatId, caller=self) result["seatId"] = onlineSeatId result["reason"] = TYRoom.ENTER_ROOM_REASON_OK self.sendQuickStartRes(userId, clientId, result) return -onlineSeatId isOk, reason = self._checkSitCondition(userId) if not isOk: result["isOK"] = False result["reason"] = reason self.sendQuickStartRes(userId, clientId, result) return 0 # 按指定座位坐下,如果座位上有人则随机分配座位。 if seatIndex >= 0 and seatIndex < self.maxSeatN: if self.seats[seatIndex].isEmptySeat(): return seatIndex + 1 else: ftlog.warn("seatIndex >=0 but not self.seats[seatIndex].isEmptySeat()", "|userId, roomId, tableId, seatIndex:", userId, self.table.roomId, self.table.tableId, seatIndex, caller=self) idleSeatId = self.findIdleSeat(userId) if idleSeatId < 0: # 断线重连机制出错了?? # 已经在座位上坐下, 返回成功消息和桌子信息 ftlog.warn("idleSeatId < 0", "|userId, roomId, tableId, idleSeatId:", userId, self.table.roomId, self.table.tableId, idleSeatId, caller=self) result["seatId"] = abs(idleSeatId) result["reason"] = TYRoom.ENTER_ROOM_REASON_OK self.sendQuickStartRes(userId, clientId, result) return idleSeatId if idleSeatId == 0: # 座位已经满了, 返回失败消息 ftlog.warn("idleSeatId == 0", "|userId, roomId, tableId, idleSeatId:", userId, self.table.roomId, self.table.tableId, idleSeatId, caller=self) result["isOK"] = False result["reason"] = TYRoom.ENTER_ROOM_REASON_TABLE_FULL if userId not in self.observers: # 玩家从旁观状态点坐下排队,不下发quick_start self.sendQuickStartRes(userId, clientId, result) return 0 return idleSeatId
def getValidIdleSeatId(self, userId, seatIndex, result): '''通用坐下合法性检查函数 Returns idleSeatId: >0 : 为新玩家找到合适座位,需要继续处理 <0 : 断线重连 0 : 坐下失败 ''' clientId = sessiondata.getClientId(userId) onlineSeatId = onlinedata.getOnlineLocSeatId(userId, self.table.roomId, self.table.tableId) if onlineSeatId and onlineSeatId <= self.maxSeatN: # 断线重连, Note:旁观的人坐下此处不能返回负数,否则无法入座 ftlog.hinfo('re-sit ok. |userId, tableId, seatId:', userId, self.tableId, onlineSeatId, caller=self) result["seatId"] = onlineSeatId result["reason"] = TYRoom.ENTER_ROOM_REASON_OK self.sendQuickStartRes(userId, clientId, result) return -onlineSeatId isOk, reason = self._checkSitCondition(userId) if not isOk: result["isOK"] = False result["reason"] = reason # if reason == TYRoom.ENTER_ROOM_REASON_TABLE_FULL and userId in self.observers: #玩家从旁观状态点坐下排队,不下发quick_start if reason == TYRoom.ENTER_ROOM_REASON_TABLE_FULL: pass else: self.sendQuickStartRes(userId, clientId, result) return 0 # 按指定座位坐下,如果座位上有人则随机分配座位。 if seatIndex >= 0 and seatIndex < self.maxSeatN: if self.seats[seatIndex].isEmptySeat(): return seatIndex + 1 else: ftlog.warn("seatIndex >=0 but not self.seats[seatIndex].isEmptySeat()", "|userId, roomId, tableId, seatIndex:", userId, self.table.roomId, self.table.tableId, seatIndex, caller=self) idleSeatId = self.findIdleSeat(userId) if idleSeatId < 0: # 断线重连机制出错了?? # 已经在座位上坐下, 返回成功消息和桌子信息 ftlog.warn("idleSeatId < 0", "|userId, roomId, tableId, idleSeatId:", userId, self.table.roomId, self.table.tableId, idleSeatId, caller=self) result["seatId"] = abs(idleSeatId) result["reason"] = TYRoom.ENTER_ROOM_REASON_OK self.sendQuickStartRes(userId, clientId, result) return idleSeatId if idleSeatId == 0: # 座位已经满了, 返回失败消息 ftlog.warn("idleSeatId == 0", "|userId, roomId, tableId, idleSeatId:", userId, self.table.roomId, self.table.tableId, idleSeatId, caller=self) result["isOK"] = False result["reason"] = TYRoom.ENTER_ROOM_REASON_TABLE_FULL if userId not in self.observers: # 玩家从旁观状态点坐下排队,不下发quick_start self.sendQuickStartRes(userId, clientId, result) return 0 # 为了支持并发坐下,findIdleSeat后不应该有异步操作 # 座位冲突检查 # lastUserId = self.table.getLastSeatUserId(idleSeatId) # if lastUserId and lastUserId != userId : # ftlog.error(getMethodName(), 'seat Userid is not clean up !! tid=', self.table.tableId, # 'seatId=', idleSeatId, 'olduid=', lastUserId, 'newuid=', userId) # result["isOK"] = False # result["reason"] = TYRoom.ENTER_ROOM_REASON_INNER_ERROR # self.sendQuickStartRes(userId, clientId, result) # return 0 return idleSeatId