Beispiel #1
0
 def doEnter(self, userId):
     isOk, reason = self._enter(userId)
     if isOk:
         TYPluginCenter.event(
             TYPluginUtils.updateMsg(
                 cmd='EV_ENTER_ROOM',
                 params=TYPluginUtils.mkdict(userId=userId,
                                             roomId=self.roomId)),
             self.gameId)
     return isOk, reason
Beispiel #2
0
    def doLeave(self, userId, msg):

        ftlog.hinfo("doLeave |userId, msg:", userId, msg, caller=self)

        reason = msg.getParam("reason", TYRoom.LEAVE_ROOM_REASON_ACTIVE)
        assert isinstance(reason, int)
        needSendRes = msg.getParam("needSendRes", True)
        assert isinstance(needSendRes, bool)
        clientRoomId = msg.getParam("clientRoomId", self.roomId)
        assert isinstance(clientRoomId, int)

        if not self._leave(userId, reason, needSendRes):
            reason = TYRoom.LEAVE_ROOM_REASON_FORBIT

        TYPluginCenter.event(
            TYPluginUtils.updateMsg(cmd='EV_LEAVE_ROOM',
                                    params=TYPluginUtils.mkdict(
                                        userId=userId,
                                        roomId=self.roomId,
                                        reason=reason)), self.gameId)

        msgRes = MsgPack()
        if not pokerconf.isOpenMoreTable(sessiondata.getClientId(userId)):
            msgRes.setCmd("room_leave")
        else:
            msgRes.setCmd("room")
            msgRes.setResult("action", "leave")

        msgRes.setResult("reason", reason)
        msgRes.setResult("gameId", self.gameId)
        msgRes.setResult(
            "roomId",
            clientRoomId)  # 处理结果返回给客户端时,部分游戏(例如德州、三顺)需要判断返回的roomId是否与本地一致
        msgRes.setResult("userId", userId)

        if needSendRes or TYPlayer.isRobot(userId):  # 需要通知机器人stop
            router.sendToUser(msgRes, userId)
Beispiel #3
0
    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, '')
Beispiel #4
0
    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, '')
Beispiel #5
0
    def _doSit(self, msg, userId, seatId, clientId):
        '''
        玩家操作, 尝试在当前的某个座位上坐下
        '''
        if ftlog.is_debug():
            ftlog.info("_doSit << |tableId, userId, seatId:", self.tableId, userId, seatId, caller=self)

        if ftlog.is_debug():
            locList = onlinedata.getOnlineLocList(userId)
            ftlog.debug(self._baseLogStr("<<", userId), "|locList:", locList, caller=self)

        result = {"isOK": True, "userId": userId, "gameId": self.gameId, "roomId": self.bigRoomId,
                  "tableId": self.tableId}

        idleSeatId = self._getValidIdleSeatId(userId, seatId - 1, result)

        if idleSeatId < 0:
            # self.room.sendTableClothRes(self.gameId, userId, self.tableType, self.tableTheme)
            self.sendTableInfoRes(result["seatId"], userId)
            self._onReSit(userId, -idleSeatId, clientId)
            return result

        if idleSeatId == 0:
            return result

        # rid, tid, sid = getOnlineLoc(userId, self.gameId)

        # 为了支持并发坐下,self.getValidIdleSeatId()到此函数执行前,不应该有异步操作
        self.onSitOk(userId, idleSeatId, result)

        # if rid == 0: #旁观坐下时rid!=0
        #     TYPluginCenter.event(TYPluginUtils.updateMsg(cmd='EV_USER_FIRST_SIT', params={
        #                 'table': self, 'userId': userId}), self.gameId)

        player = self.players[idleSeatId - 1]
        self._playerSit(player)

        self.sendQuickStartRes(userId, clientId, result)
        self.sendTableInfoRes(result["seatId"], userId)

        # 发送 newUser 消息, 客户端通过该协议显示新玩家
        mpNewUserRes = self.createMsgPackRes("newUser")
        playerInfo = player.getInfo()
        mpNewUserRes.updateResult(playerInfo)
        self.sendToAllTableUser(mpNewUserRes, exclude=[userId])

        # 扩展事件.
        TYPluginCenter.event(TYPluginUtils.updateMsg(cmd=PluginEvents.EV_AFTER_SITDOWN, params=TYPluginUtils.mkdict(
            table=self, userId=userId, player=player)), self.gameId)

        if ftlog.is_debug():
            ftlog.debug(self._baseLogStr(">>", userId), "|locList:", onlinedata.getOnlineLocList(userId), caller=self)

        ftlog.hinfo("_doSit >> get new seat, |tableId, userId, seatId:",
                    self.tableId, userId, player.seatId, caller=self)
        return result
Beispiel #6
0
    def getInfo(self):
        item = {}
        item["seatId"] = self.seatIndex  # 德州客户端 seatId 从0开始 !
        item["userId"] = self.userId
        if self.userId == 0:
            return item
        # user信息
        if gdata.mode() == gdata.RUN_MODE_ONLINE:
            item["name"] = self.name
        else:
            item["name"] = '%s_%s_%s' % (self.userId, self.seatIndex, self.name)
        item["purl"] = self.purl
        item["sex"] = self.sex
        item["ip"] = sessiondata.getClientIp(self.userId)  # 需要实时更新ip数据
        # 牌桌筹码信息
        item["chips"] = self.tableChips
        item["state"] = self.state
        # game信息
        # 统计信息
        # 手牌信息
        # 状态信息
        item["managed"] = self.isManaged

        # 以插件形式来填充palyerInfo数据
        TYPluginCenter.event(TYPluginUtils.updateMsg(cmd=PluginEvents.EV_GET_PLAYER_INFO, params=TYPluginUtils.mkdict(
            table=self.table, userId=self.userId, player=self, playerInfo=item)),
                             self.table.gameId)

        return item
Beispiel #7
0
    def end(self, extParam):
        '''一局结束'''
        if ftlog.is_debug():
            ftlog.debug("<< |userId=", self.userId, "roomId=", self.table.roomId, " tableId=", self.table.tableId,
                        caller=self)

        msg = TYPluginUtils.updateMsg(cmd=PluginEvents.EV_PLAYER_GAME_FRAME_END, params=TYPluginUtils.mkdict(
            table=self.table, player=self, extParam=extParam))
        TYPluginCenter.event(msg, self.table.gameId)
Beispiel #8
0
    def start(self):
        '''一局开始'''
        if ftlog.is_debug():
            ftlog.debug("<< |userId=", self.userId, "roomId=", self.table.roomId, " tableId=", self.table.tableId,
                        caller=self)
        self.setPlaying()

        msg = TYPluginUtils.updateMsg(cmd=PluginEvents.EV_PLAYER_GAME_FRAME_START, params=TYPluginUtils.mkdict(
            table=self.table, player=self))
        TYPluginCenter.event(msg, self.table.gameId)