Ejemplo n.º 1
0
 def setup(self, interval, action, msgPackParams, cancelLastTimer=True):
     '''
     启动计时器
     interval 倒计时的时间, 单位: 秒
     action table_call命令下(params中)的action值
     msgPackParams 传递的其他的参数数据集合dict, 可以在doTableCall中的msg中使用msg.getParam(key)来取得其中的参数
     '''
     if self._fttimer and cancelLastTimer:
         self._fttimer.cancel()
     self._interval = interval
     userId = msgPackParams.get('userId', 0)
     clientId = msgPackParams.get('clientId', None)
     assert (isinstance(userId, int))
     assert (isinstance(action, (unicode, str)))
     if clientId != None:
         assert (isinstance(clientId, (unicode, str)))
     msg = MsgPack()
     msg.updateParam(msgPackParams)
     msg.setCmdAction('table_call', action)
     msg.setParam('gameId', self._table.gameId)
     msg.setParam('roomId', self._table.roomId)
     msg.setParam('tableId', self._table.tableId)
     msg.setParam('userId', userId)
     msg.setParam('clientId', clientId)
     self._fttimer = FTTimer(interval, self._onTimeOut, msg, pack=msg)
Ejemplo n.º 2
0
    def _dealGrabTing(self, msg):
        chiTile = msg.getResult("chi")
        pengTile = msg.getResult("peng")
        if chiTile:
            chiStyle = msg.getResult("style")
            self.tileManager.set_chi(chiTile, chiStyle)
        else:
            self._setPeng(pengTile)

        ting_infos = msg.getResult("ting_action")
        playTile = ting_infos[0][0]
        self._delTile(playTile)
        message = MsgPack()
        message.setCmdAction('table_call', 'play')
        message.setParam("tile", playTile)
        message.setParam('ting', 1)
        message.setParam('userId', self.userId)
        message.setParam('gameId', self.gameId)
        message.setParam('clientId', self.clientId)
        message.setParam('roomId', self.roomId)
        message.setParam('tableId', self.tableId)
        message.setParam('seatId', self.seatId)
        message.setParam('action_id', msg.getResult("action_id"))
        self.writeMsg(message)
        return
Ejemplo n.º 3
0
 def setup(self, interval, action, msgPackParams, cancelLastTimer=True):
     '''
     启动计时器
     interval 倒计时的时间, 单位: 秒
     action table_call命令下(params中)的action值
     msgPackParams 传递的其他的参数数据集合dict, 可以在doTableCall中的msg中使用msg.getParam(key)来取得其中的参数
     '''
     if self._fttimer and cancelLastTimer:
         self._fttimer.cancel()
     self._interval = interval
     userId = msgPackParams.get('userId', 0)
     clientId = msgPackParams.get('clientId', None)
     assert (isinstance(userId, int))
     assert (isinstance(action, (unicode, str)))
     if clientId != None:
         assert (isinstance(clientId, (unicode, str)))
     msg = MsgPack()
     msg.updateParam(msgPackParams)
     msg.setCmdAction('table_call', action)
     msg.setParam('gameId', self._table.gameId)
     msg.setParam('roomId', self._table.roomId)
     msg.setParam('tableId', self._table.tableId)
     msg.setParam('userId', userId)
     msg.setParam('clientId', clientId)
     self._fttimer = FTTimer(interval, self._onTimeOut, msg)
Ejemplo n.º 4
0
    def powerTest(self, userId):
        ftlog.debug('MJAdmin.powerTest userId:', userId)
        roomId, checkResult = MajiangCreateTable._chooseCreateRoom(
            userId, GAMEID, 'queshou', 3)
        ftlog.debug('MajiangCreateTable._chooseCreateRoom roomId:', roomId,
                    ' checkResult:', checkResult)
        msg = MsgPack()
        msg.setCmdAction("room", "create_table")
        msg.setParam("roomId", roomId)
        msg.setParam("gameId", GAMEID)
        msg.setParam("userId", userId)
        msg.setParam(
            "itemParams", {
                "sanQiBian": 1,
                "playerType": 3,
                "cardCount": 1,
                "chunJia": 0,
                "guaDaFeng": 0,
                "hongZhongBao": 0
            })
        msg.setParam('needFangka', 0)
        ftlog.debug(
            'MajiangCreateTable._chooseCreateRoom send message to room:', msg)

        router.sendRoomServer(msg, roomId)
        return {'info': 'ok', 'code': 0}
Ejemplo n.º 5
0
 def _dealChiPeng(self, msg):
     tile = msg.getResult("tile")
     style = msg.getResult("style")
     cmd = msg.getCmd()
     if cmd == "chi":
         self.tileManager.set_chi(tile,style)
     else:
         self._setPeng(tile)
     result = msg.getKey('result') 
     message = MsgPack() 
     if "ting_action" in result:
         tingAction = result.get("ting_action")
         message.setCmdAction('table_call', 'play')
         playTile = tingAction[0][0]
         message.setParam("tile", playTile)
         message.setParam('ting', 1)
     else:
         message.setCmdAction('table_call', 'play')
         playTile = self._playAsTrustee()
         message.setParam("tile", playTile) 
     self._delTile(playTile)
     message.setParam('userId', self.userId)
     message.setParam('gameId', self.gameId)
     message.setParam('clientId', self.clientId)
     message.setParam('roomId', self.roomId)
     message.setParam('tableId', self.tableId)         
     message.setParam('seatId', self.seatId)
     message.setParam('action_id', msg.getResult("action_id"))
     self.writeMsg(message)
     return            
Ejemplo n.º 6
0
 def _dealGrabTing(self, msg):
     chiTile = msg.getResult("chi")
     pengTile = msg.getResult("peng")
     if chiTile:
         chiStyle = msg.getResult("style")
         self.tileManager.set_chi(chiTile, chiStyle)
     else:
         self._setPeng(pengTile)
         
     ting_infos = msg.getResult("ting_action")
     playTile = ting_infos[0][0]
     self._delTile(playTile)
     message = MsgPack() 
     message.setCmdAction('table_call', 'play')
     message.setParam("tile", playTile)
     message.setParam('ting', 1)
     message.setParam('userId', self.userId)
     message.setParam('gameId', self.gameId)
     message.setParam('clientId', self.clientId)
     message.setParam('roomId', self.roomId)
     message.setParam('tableId', self.tableId)         
     message.setParam('seatId', self.seatId)
     message.setParam('action_id', msg.getResult("action_id"))
     self.writeMsg(message)
     return  
Ejemplo n.º 7
0
 def _dealChiPeng(self, msg):
     tile = msg.getResult("tile")
     style = msg.getResult("style")
     cmd = msg.getCmd()
     if cmd == "chi":
         self.tileManager.set_chi(tile, style)
     else:
         self._setPeng(tile)
     result = msg.getKey('result')
     message = MsgPack()
     if "ting_action" in result:
         tingAction = result.get("ting_action")
         message.setCmdAction('table_call', 'play')
         playTile = tingAction[0][0]
         message.setParam("tile", playTile)
         message.setParam('ting', 1)
     else:
         message.setCmdAction('table_call', 'play')
         playTile = self._playAsTrustee()
         message.setParam("tile", playTile)
     self._delTile(playTile)
     message.setParam('userId', self.userId)
     message.setParam('gameId', self.gameId)
     message.setParam('clientId', self.clientId)
     message.setParam('roomId', self.roomId)
     message.setParam('tableId', self.tableId)
     message.setParam('seatId', self.seatId)
     message.setParam('action_id', msg.getResult("action_id"))
     self.writeMsg(message)
     return
Ejemplo n.º 8
0
 def onMsgTableBegin(self):
     roomTypeName = gdata.roomIdDefineMap()[
         self.roomId].configure['typeName']
     if roomTypeName == "majiang_bigmatch":
         moSigninMatch = MsgPack()
         moSigninMatch.setCmdAction('room', 'signin')
         moSigninMatch.setParam('userId', self.userId)
         moSigninMatch.setParam('gameId', self.gameId)
         moSigninMatch.setParam('clientId', self.clientId)
         moSigninMatch.setParam('roomId', self.roomId)
         self.writeMsg(moSigninMatch)
         self.isMatch = True
     else:
         ftlog.debug('send quick Start !!!')
         self.adjustChip()
         mo = MsgPack()
         mo.setCmdAction('game', 'quick_start')
         mo.setParam('userId', self.userId)
         mo.setParam('gameId', self.gameId)
         mo.setParam('clientId', self.clientId)
         mo.setParam('roomId', self.roomId)
         mo.setParam('tableId', self.tableId)
         self.writeMsg(mo)
         self.isMatch = False
     return
Ejemplo n.º 9
0
 def _signinMtt(self):
     ftlog.debug('<<', caller=self)
     mo = MsgPack()
     mo.setCmdAction('room', 'signin')
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', self.bigRoomId)
     self.writeMsg(mo)
Ejemplo n.º 10
0
 def _signinMtt(self):
     ftlog.debug('<<', caller=self)
     mo = MsgPack()
     mo.setCmdAction('room', 'signin')
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', self.bigRoomId)
     self.writeMsg(mo)
Ejemplo n.º 11
0
    def onMsgTablePlay(self, msg):
        ftlog.debug('|snsId, userId, seatId:', self.snsId, self.userId, self.seatId, 'msg->', msg, caller=self)
        cmd = msg.getCmd()
        if cmd == 'quick_start':
            roomId = msg.getResult('roomId')
            tableId = msg.getResult('tableId')
            roomTypeName = gdata.getRoomConfigure(roomId)['typeName']
            # if roomTypeName in (rooms.tyRoomConst.ROOM_TYPE_NAME_NORMAL,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_QUEUE,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_SNG,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_MTT,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_HUNDREDS,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_DTG) :
            #     if tableId == 0: # 进入队列的返回,忽略
            #         return
            #     else:
            #         self.tableId = tableId

            seatId = msg.getResult('seatId', 0)
            self.seatId = seatId - 1
            if tableId == self.tableId and seatId > 0:
                ftlog.debug('QuickStart', self.snsId, 'OK !', roomId, tableId, seatId)
            else:
                # 快速开始失败
                ftlog.error('QuickStart', self.snsId, self.roomId, self.tableId, msg)
                self.stop()

        action = msg.getResult('action')
        if (cmd == 'table' and action == 'info') or cmd == 'tableInfo':
            self.tableInfoResult = msg.getKey('result')

        if cmd == 'standup':
            userId = msg.getResult('userId')
            reason = msg.getResult('reason')
            if userId == self.userId and reason != TYRoom.LEAVE_ROOM_REASON_CHANGE_TABLE:
                mo = MsgPack()
                mo.setCmdAction('room', 'leave')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', self.gameId)
                mo.setParam('clientId', self.clientId)
                mo.setParam('roomId', self.bigRoomId)
                self.writeMsg(mo)

        if (cmd == 'room' and action == 'leave') or cmd == 'room_leave':
            self.stop()

        if cmd == 'table_call':
            if action == 'game_start':
                ftlog.debug("table_call game_start |msg:", msg, caller=self)
                self.gameStartResult = msg.getKey('result')
                return

            elif action == 'game_win':
                ftlog.debug("table_call game_win |msg:", msg, caller=self)
                self.sendReadyReq(msg)
                return
Ejemplo n.º 12
0
 def sendReadyReq(self, msg):
     mo = MsgPack()
     mo.setCmdAction('table_call', "ready")
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', msg.getResult("roomId"))
     mo.setParam('tableId', self.tableId)
     mo.setParam('seatId', self.seatId)
     self.writeDelayMsg(2, mo)
Ejemplo n.º 13
0
 def sendReadyReq(self, msg):
     mo = MsgPack()
     mo.setCmdAction('table_call', "ready")
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', msg.getResult("roomId"))
     mo.setParam('tableId', self.tableId)
     mo.setParam('seatId', self.seatId)
     self.writeDelayMsg(2, mo)
Ejemplo n.º 14
0
 def _enterRoom(self):
     ftlog.debug('<<', caller=self)
     self.adjustChip()
     onlinedata.cleanOnlineLoc(self.userId)
     mo = MsgPack()
     mo.setCmdAction('game', 'quick_start')
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', self.bigRoomId)
     self.writeMsg(mo)
Ejemplo n.º 15
0
 def _enterRoom(self):
     ftlog.debug('<<', caller=self)
     self.adjustChip()
     onlinedata.cleanOnlineLoc(self.userId)
     mo = MsgPack()
     mo.setCmdAction('game', 'quick_start')
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', self.bigRoomId)
     self.writeMsg(mo)
Ejemplo n.º 16
0
 def doRobotDetailInfo(self, gameId):
     '''
     查询机器人管理器的详细信息
     '''
     rmgr = TYGame(gameId).getRobotManager()
     datas = {}
     if rmgr:
         msg = runcmd.getMsgPack()
         datas = rmgr.getRobotDetail(msg)
     if router.isQuery():
         mo = MsgPack()
         mo.setCmdAction('robotmgr', 'detail')
         mo.setResult('detail', datas)
         router.responseQurery(mo)
Ejemplo n.º 17
0
    def powerTest(self, userId):
        ftlog.debug('MJAdmin.powerTest userId:', userId)
        roomId, checkResult = MajiangCreateTable._chooseCreateRoom(userId, GAMEID, 'luosihu', 3)
        ftlog.debug('MajiangCreateTable._chooseCreateRoom roomId:', roomId, ' checkResult:', checkResult)
        msg = MsgPack()
        msg.setCmdAction("room", "create_table")
        msg.setParam("roomId", roomId)
        msg.setParam("gameId", GAMEID)
        msg.setParam("userId", userId)
        msg.setParam("itemParams", {"sanQiBian":1,"playerType":3,"cardCount":1,"chunJia":0,"guaDaFeng":0,"hongZhongBao":0})
        msg.setParam('needFangka', 0)
        ftlog.debug('MajiangCreateTable._chooseCreateRoom send message to room:', msg)

        router.sendRoomServer(msg, roomId)
        return {'info': 'ok', 'code': 0}
Ejemplo n.º 18
0
    def onMsgLogin(self, msg):
        ftlog.debug('RobotUser.onMsgLogin snsId=', self.snsId, 'msg->', msg)
        cmd = msg.getCmd()

        if cmd == '_tcp_closed_':
            self.stop()
            return 1

        if cmd == '_tcp_conneted_':
            if self.checkState(CMD_TCP_CONNECTED):
                mo = MsgPack()
                mo.setCmd('bind_user')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', 9999)
                mo.setParam('clientId', self.clientId)
                self.writeMsg(mo)
            return 1

        if cmd == 'user_info':  # bind_user 命令返回结果
            if self.checkState(CMD_BIND_USER):
                mo = MsgPack()
                mo.setCmdAction('game', 'enter')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', 9999)
                mo.setParam('clientId', self.clientId)
                self.writeMsg(mo)
            return 1

        # game#enter 9999 命令返回结果
        if cmd == 'game_data' and msg.getResult('gameId') == 9999:
            self.gameData9999 = msg.getKey('result')
            if self.checkState(CMD_GANEDATA_9999):
                mo = MsgPack()
                mo.setCmdAction('game', 'enter')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', self.gameId)
                mo.setParam('clientId', self.clientId)
                self.writeMsg(mo)
            return 1

        # game#enter DIZHU_GAMEID 命令返回结果
        if cmd == 'game_data' and msg.getResult('gameId') == self.gameId:
            self.gameData = msg.getKey('result')
            if self.checkState(CMD_GANEDATA_CUR_GAMEID):
                return 2
            return 1
        return 0
Ejemplo n.º 19
0
    def onMsgLogin(self, msg):
        ftlog.debug('RobotUser.onMsgLogin snsId=', self.snsId, 'msg->', msg)
        cmd = msg.getCmd()

        if cmd == '_tcp_closed_':
            self.stop()
            return 1

        if cmd == '_tcp_conneted_':
            if self.checkState(CMD_TCP_CONNECTED):
                mo = MsgPack()
                mo.setCmd('bind_user')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', 9999)
                mo.setParam('clientId', self.clientId)
                self.writeMsg(mo)
            return 1

        if cmd == 'user_info':  # bind_user 命令返回结果
            if self.checkState(CMD_BIND_USER):
                mo = MsgPack()
                mo.setCmdAction('game', 'enter')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', 9999)
                mo.setParam('clientId', self.clientId)
                self.writeMsg(mo)
            return 1

        # game#enter 9999 命令返回结果
        if cmd == 'game_data' and msg.getResult('gameId') == 9999:
            self.gameData9999 = msg.getKey('result')
            if self.checkState(CMD_GANEDATA_9999):
                mo = MsgPack()
                mo.setCmdAction('game', 'enter')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', self.gameId)
                mo.setParam('clientId', self.clientId)
                self.writeMsg(mo)
            return 1

        # game#enter DIZHU_GAMEID 命令返回结果
        if cmd == 'game_data' and msg.getResult('gameId') == self.gameId:
            self.gameData = msg.getKey('result')
            if self.checkState(CMD_GANEDATA_CUR_GAMEID):
                return 2
            return 1
        return 0
Ejemplo n.º 20
0
    def onMsgTableBegin(self):
        roomTypeName = self.getRoomConfKey('typeName')
        ftlog.debug('RobotUser.onMsgTableBegin roomId=', self.roomId,
                    'roomTypeName=', roomTypeName)
        if roomTypeName in (rooms.tyRoomConst.ROOM_TYPE_NAME_BIG_MATCH,
                            rooms.tyRoomConst.ROOM_TYPE_NAME_ARENA_MATCH,
                            rooms.tyRoomConst.ROOM_TYPE_NAME_GROUP_MATCH,
                            rooms.tyRoomConst.ROOM_TYPE_NAME_ERDAYI_MATCH,
                            'dizhu_group_match', 'dizhu_arena_match',
                            'dizhu_erdayi_match'):
            ftlog.debug('send enter and sign in match !!!')
            moEnterMatch = MsgPack()
            moEnterMatch.setCmdAction('room', 'enter')
            moEnterMatch.setParam('userId', self.userId)
            moEnterMatch.setParam('gameId', self.gameId)
            moEnterMatch.setParam('clientId', self.clientId)
            moEnterMatch.setParam('roomId', self.roomId)
            self.writeMsg(moEnterMatch)

            moSigninMatch = MsgPack()
            moSigninMatch.setCmdAction('room', 'signin')
            moSigninMatch.setParam('userId', self.userId)
            moSigninMatch.setParam('gameId', self.gameId)
            moSigninMatch.setParam('clientId', self.clientId)
            moSigninMatch.setParam('roomId', self.roomId)
            self.writeMsg(moSigninMatch)
        elif roomTypeName in ('dizhu_custom_match', ):
            moSigninMatch = MsgPack()
            moSigninMatch.setCmdAction('custom_match', 'signin')
            moSigninMatch.setParam('userId', self.userId)
            moSigninMatch.setParam('gameId', self.gameId)
            moSigninMatch.setParam('clientId', self.clientId)
            moSigninMatch.setParam('matchId', self.matchId)
            self.writeMsg(moSigninMatch)
        else:
            self.adjustChip()
            mo = MsgPack()
            mo.setCmdAction('game', 'quick_start')
            mo.setParam('userId', self.userId)
            mo.setParam('gameId', self.gameId)
            mo.setParam('clientId', self.clientId)
            mo.setParam('roomId', self.roomId)
            mo.setParam('tableId', self.tableId)
            ctrlRoomId = gdata.roomIdDefineMap()[
                self.roomId].parentId or self.roomId
            if gdata.roomIdDefineMap()[ctrlRoomId].configure.get('isMix'):
                mixId = gdata.roomIdDefineMap()[ctrlRoomId].configure.get(
                    'mixConf')[0].get('mixId')
                mo.setParam('mixId', mixId)
            ftlog.debug('send quick Start !!!', 'userId=', self.userId,
                        'gameId=', self.gameId, 'clientId=', self.clientId,
                        'roomId=', self.roomId, 'tableId=', self.tableId,
                        'mixId=', mo.getParam('mixId', ''))
            self.writeMsg(mo)
        return
Ejemplo n.º 21
0
def _leaveFromMatchs(userId):
    from dizhu.servers.util.rpc import match_remote
    from dizhu.servers.util.rpc.match_remote import UserMatchInfo
    userMatchInfoMap = match_remote.loadAllUserMatchInfo(DIZHU_GAMEID, userId)
    if ftlog.is_debug():
        ftlog.debug('dizhuonlinedata._leaveFromMatchs userId=', userId,
                    'infos=', [(rid, umi.state)
                               for rid, umi in userMatchInfoMap.iteritems()])
    for _, userMatchInfo in userMatchInfoMap.iteritems():
        if userMatchInfo.state == UserMatchInfo.ST_SIGNIN:
            msg = MsgPack()
            msg.setCmdAction('room', 'leave')
            msg.setParam('userId', userId)
            msg.setParam('roomId', userMatchInfo.ctrlRoomId)
            msg.setParam(
                'gameId',
                strutil.getGameIdFromInstanceRoomId(userMatchInfo.ctrlRoomId))
            msg.setParam('reason', TYRoom.LEAVE_ROOM_REASON_LOST_CONNECTION)
            router.sendRoomServer(msg, userMatchInfo.ctrlRoomId)
Ejemplo n.º 22
0
def _remoteCall(markParams, argl, argd):
    srvtype = markParams['remoteServerType']
    syncCall = markParams['remoteSyncCall']
    remoteGroupByIndex = markParams['remoteGroupByIndex']
    remoteGroupBy = markParams['remoteGroupBy']
    cmd = markParams['remoteCmd']
    action = markParams['remoteAction']
    groupVal = argl[remoteGroupByIndex]
    msgpack = MsgPack()
    msgpack.setCmdAction(cmd, action)
    msgpack.setParam(remoteGroupBy, groupVal)
    msgpack.setParam('argl', argl[1:])  # 去掉self, cls
    msgpack.setParam('argd', argd)
    msgpack.setParam('clientId', configure.CLIENTID_RPC)
    msgpack = msgpack.pack()
    jstr = None
    if srvtype == gdata.SRV_TYPE_UTIL:
        jstr = _communicateServer(_utilServer, groupVal, groupVal, msgpack,
                                  'RQ', syncCall)
    elif srvtype == gdata.SRV_TYPE_ROOM:
        assert (groupVal in gdata.roomIdDefineMap())
        jstr = _communicateRoomServer(0, groupVal, msgpack, 'RQ', syncCall)
    elif srvtype == gdata.SRV_TYPE_TABLE:
        assert (groupVal in gdata.roomIdDefineMap())
        jstr = _communicateTableServer(0, groupVal, msgpack, 'RQ', syncCall)
    elif srvtype == gdata.SRV_TYPE_CENTER:
        jstr = _communicateServer(_centerServer, groupVal, groupVal, msgpack,
                                  'RQ', syncCall)
    else:
        raise Exception('ERROR RPC cmd route false !!' + cmd + '.' + action)
    ret = None
    if syncCall and jstr:
        mo = MsgPack()
        try:
            mo.unpack(jstr)
        except:
            raise Exception('the json data error 5 !! [' + repr(jstr) + ']')
        ret = mo.getKey('result')
    return ret
Ejemplo n.º 23
0
def _remoteCall(markParams, argl, argd):
    srvtype = markParams['remoteServerType']
    syncCall = markParams['remoteSyncCall']
    remoteGroupByIndex = markParams['remoteGroupByIndex']
    remoteGroupBy = markParams['remoteGroupBy']
    cmd = markParams['remoteCmd']
    action = markParams['remoteAction']
    groupVal = argl[remoteGroupByIndex]
    msgpack = MsgPack()
    msgpack.setCmdAction(cmd, action)
    msgpack.setParam(remoteGroupBy, groupVal)
    msgpack.setParam('argl', argl[1:])  # 去掉self, cls
    msgpack.setParam('argd', argd)
    msgpack.setParam('clientId', configure.CLIENTID_RPC)
    msgpack = msgpack.pack()
    jstr = None
    if srvtype == gdata.SRV_TYPE_UTIL:
        jstr = _communicateServer(_utilServer, groupVal, groupVal, msgpack, 'RQ', syncCall)
    elif srvtype == gdata.SRV_TYPE_ROOM:
        assert (groupVal in gdata.roomIdDefineMap())
        jstr = _communicateRoomServer(0, groupVal, msgpack, 'RQ', syncCall)
    elif srvtype == gdata.SRV_TYPE_TABLE:
        assert (groupVal in gdata.roomIdDefineMap())
        jstr = _communicateTableServer(0, groupVal, msgpack, 'RQ', syncCall)
    elif srvtype == gdata.SRV_TYPE_CENTER:
        jstr = _communicateServer(_centerServer, groupVal, groupVal, msgpack, 'RQ', syncCall)
    else:
        raise Exception('ERROR RPC cmd route false !!' + cmd + '.' + action)
    ret = None
    if syncCall and jstr:
        mo = MsgPack()
        try:
            mo.unpack(jstr)
        except:
            raise Exception('the json data error 5 !! [' + repr(jstr) + ']')
        ret = mo.getKey('result')
    return ret
Ejemplo n.º 24
0
 def onMsgTableBegin(self):
     roomTypeName = gdata.roomIdDefineMap()[self.roomId].configure['typeName']
     if roomTypeName == "majiang_bigmatch":             
         moSigninMatch = MsgPack()
         moSigninMatch.setCmdAction('room', 'signin')
         moSigninMatch.setParam('userId', self.userId)
         moSigninMatch.setParam('gameId', self.gameId)
         moSigninMatch.setParam('clientId', self.clientId)
         moSigninMatch.setParam('roomId', self.roomId)
         self.writeMsg(moSigninMatch)
         self.isMatch = True
     else :
         ftlog.debug('send quick Start !!!')
         self.adjustChip()
         mo = MsgPack()
         mo.setCmdAction('game', 'quick_start')
         mo.setParam('userId', self.userId)
         mo.setParam('gameId', self.gameId)
         mo.setParam('clientId', self.clientId)
         mo.setParam('roomId', self.roomId)
         mo.setParam('tableId', self.tableId)
         self.writeMsg(mo)
         self.isMatch = False
     return
Ejemplo n.º 25
0
    def doUserOffline(self, userId, clientId):
        evt = OnLineTcpChangedEvent(userId, HALL_GAMEID, 0)
        TGHall.getEventBus().publishEvent(evt)
        # 补发room_leave消息
        olist = onlinedata.getOnlineLocList(userId)
        ftlog.debug('doUserOffline onlines->', olist)
        for ol in olist:
            roomId, _, _ = ol[0], ol[1], ol[2]
            if roomId > 0:
                msg = MsgPack()
                msg.setCmdAction('room', 'leave')
                msg.setParam('userId', userId)
                msg.setParam('roomId', roomId)
                msg.setParam('gameId',
                             strutil.getGameIdFromInstanceRoomId(roomId))
                msg.setParam('clientId', clientId)
                msg.setParam('reason',
                             TYRoom.LEAVE_ROOM_REASON_LOST_CONNECTION)
                router.sendRoomServer(msg, roomId)

        # offline_geoc处理
        onlinedata.setUserGeoOffline(userId, HALL_GAMEID)
        # 通知push服务
        self._notifyPushUserOnlineStateChanged(userId, 0, clientId)
Ejemplo n.º 26
0
 def _dealSendTile(self, msg):
     ftlog.debug("standuptiles:", self._getStandupTiles(), self.snsId)
     tile = msg.getResult("tile")
     result = msg.getKey('result')
     mo = MsgPack()
    
     if "win_action" in result and result.get("win_action") == 1:
         mo.setCmdAction('table_call', 'win')
     elif "ting_action" in result and len(result.get("ting_action")) >= 1:
         self._addTile(tile)
         ting_action = result.get("ting_action")
         tingTile = ting_action[0][0]
         self._delTile(tingTile)
         mo.setCmdAction('table_call', 'play')
         mo.setParam('tile', tingTile)
         mo.setParam('ting', 1) 
     elif "gang_action" in result:
         mo.setCmdAction('table_call', 'gang')  
         mo.setParam('tile', result.get("gang_action")[0])
     else:
         self._addTile(tile)
         mo.setCmdAction('table_call', 'play')
         playTile = self._playAsTrustee()
         self._delTile(playTile)
         mo.setParam('tile', playTile)
         
     mo.setParam('userId', self.userId)
     mo.setParam('gameId', self.gameId)
     mo.setParam('clientId', self.clientId)
     mo.setParam('roomId', self.roomId)
     mo.setParam('tableId', self.tableId)         
     mo.setParam('seatId', self.seatId)
     mo.setParam('action_id', result.get("action_id"))
         
     self.writeMsg(mo)
     return  
Ejemplo n.º 27
0
    def _dealSendTile(self, msg):
        ftlog.debug("standuptiles:", self._getStandupTiles(), self.snsId)
        tile = msg.getResult("tile")
        result = msg.getKey('result')
        mo = MsgPack()

        if "win_action" in result and result.get("win_action") == 1:
            mo.setCmdAction('table_call', 'win')
        elif "ting_action" in result and len(result.get("ting_action")) >= 1:
            self._addTile(tile)
            ting_action = result.get("ting_action")
            tingTile = ting_action[0][0]
            self._delTile(tingTile)
            mo.setCmdAction('table_call', 'play')
            mo.setParam('tile', tingTile)
            mo.setParam('ting', 1)
        elif "gang_action" in result:
            mo.setCmdAction('table_call', 'gang')
            mo.setParam('tile', result.get("gang_action")[0])
        else:
            self._addTile(tile)
            mo.setCmdAction('table_call', 'play')
            playTile = self._playAsTrustee()
            self._delTile(playTile)
            mo.setParam('tile', playTile)

        mo.setParam('userId', self.userId)
        mo.setParam('gameId', self.gameId)
        mo.setParam('clientId', self.clientId)
        mo.setParam('roomId', self.roomId)
        mo.setParam('tableId', self.tableId)
        mo.setParam('seatId', self.seatId)
        mo.setParam('action_id', result.get("action_id"))

        self.writeMsg(mo)
        return
Ejemplo n.º 28
0
    def onMsgTablePlay(self, msg):
        ftlog.debug('|snsId, userId, seatId:',
                    self.snsId,
                    self.userId,
                    self.seatId,
                    'msg->',
                    msg,
                    caller=self)
        cmd = msg.getCmd()
        if cmd == 'quick_start':
            roomId = msg.getResult('roomId')
            tableId = msg.getResult('tableId')
            roomTypeName = gdata.getRoomConfigure(roomId)['typeName']
            # if roomTypeName in (rooms.tyRoomConst.ROOM_TYPE_NAME_NORMAL,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_QUEUE,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_SNG,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_MTT,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_HUNDREDS,
            #                     rooms.tyRoomConst.ROOM_TYPE_NAME_DTG) :
            #     if tableId == 0: # 进入队列的返回,忽略
            #         return
            #     else:
            #         self.tableId = tableId

            seatId = msg.getResult('seatId', 0)
            self.seatId = seatId - 1
            if tableId == self.tableId and seatId > 0:
                ftlog.debug('QuickStart', self.snsId, 'OK !', roomId, tableId,
                            seatId)
            else:
                # 快速开始失败
                ftlog.error('QuickStart', self.snsId, self.roomId,
                            self.tableId, msg)
                self.stop()

        action = msg.getResult('action')
        if (cmd == 'table' and action == 'info') or cmd == 'tableInfo':
            self.tableInfoResult = msg.getKey('result')

        if cmd == 'standup':
            userId = msg.getResult('userId')
            reason = msg.getResult('reason')
            if userId == self.userId and reason != TYRoom.LEAVE_ROOM_REASON_CHANGE_TABLE:
                mo = MsgPack()
                mo.setCmdAction('room', 'leave')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', self.gameId)
                mo.setParam('clientId', self.clientId)
                mo.setParam('roomId', self.bigRoomId)
                self.writeMsg(mo)

        if (cmd == 'room' and action == 'leave') or cmd == 'room_leave':
            self.stop()

        if cmd == 'table_call':
            if action == 'game_start':
                ftlog.debug("table_call game_start |msg:", msg, caller=self)
                self.gameStartResult = msg.getKey('result')
                return

            elif action == 'game_win':
                ftlog.debug("table_call game_win |msg:", msg, caller=self)
                self.sendReadyReq(msg)
                return
Ejemplo n.º 29
0
    def onMsgTablePlay(self, msg):
        ftlog.debug('RobotUser.onMsgTablePlay snsId=', self.snsId, 'msg->',
                    msg)
        cmd = msg.getCmd()
        if cmd == 'quick_start':
            if self.checkState(CMD_QUICK_START):
                roomId = msg.getResult('roomId')
                tableId = msg.getResult('tableId')
                seatId = msg.getResult('seatId')
                self.seatId = seatId
                if self._isMatch:  # 比赛场机器人初始化时的roomId是bigRoomId,tableId是0,需要重新赋值为shadowRoomId和真实tableId
                    self.roomId = roomId
                    self.tableId = tableId
                if roomId == self.roomId and tableId == self.tableId and seatId > 0:
                    ftlog.debug('QuickStart', self.snsId, 'OK !', roomId,
                                tableId, seatId)
                else:
                    # 快速开始失败
                    ftlog.warn('QuickStart', self.snsId, msg)
                    self.stop()

        action = msg.getResult('action')
        if (cmd == 'table' and action == 'info') or cmd == 'table_info':
            if self.checkState(CMD_READY):
                self.tableId = msg.getResult('tableId')
                mo = MsgPack()
                mo.setCmdAction('table_call', 'ready')
                mo.setParam('userId', self.userId)
                mo.setParam('gameId', self.gameId)
                mo.setParam('clientId', self.clientId)
                mo.setParam('roomId', self.roomId)
                mo.setParam('tableId', self.tableId)
                mo.setParam('seatId', self.seatId)
                self.writeMsg(mo)
            self.tableInfoResult = msg.getKey('result')

        if cmd == 'table_call':
            if action == 'ready':
                # ready响应不需要返回消息
                pass

            if action == 'game_ready':
                if self.checkState(CMD_GAME_READY):
                    # game ready 不需要返回消息
                    self.base_cards = msg.getResult('basecard')
                    self.seat_cards = []
                    i = 0
                    while 1:
                        seatcard = msg.getResult('cards%d' % (i))
                        if seatcard:
                            self.seat_cards.append(seatcard)
                            i = i + 1
                        else:
                            break
                    pass
                ftlog.debug("game_ready | snsId, seat_cards:",
                            self.snsId,
                            self.seat_cards,
                            caller=self)

            if action == 'game_start':
                if self.checkState(CMD_GAME_START):
                    # game start 不需要返回消息
                    # 设置地主的牌为 +底牌
                    dizhu = msg.getResult('stat', {}).get('dizhu', 0)
                    if isinstance(dizhu, int) and dizhu > 0 and dizhu <= len(
                            self.seat_cards):
                        self.seat_cards[dizhu - 1].extend(self.base_cards)

            if action == 'next':
                # 更新当前的桌子状态
                if not self.tableInfoResult:
                    # 容错处理 self.tableInfoResult
                    ftlog.debug('RobotUser.onMsgTablePlay',
                                'action[next][update tables status]',
                                'cmd[table_call], tableInfoResult= None',
                                'msg.getKey(result)=', msg.getKey('result'))
                    self.tableInfoResult = msg.getKey('result')

                stat = self.tableInfoResult['stat']
                stat['call'] = msg.getResult('stat')['call']
                stat["topseat"] = msg.getResult('stat')['topseat']
                stat["topcard"] = msg.getResult('stat')['topcard']
                stat["ccrc"] = msg.getResult('stat')['ccrc']
                stat["rangpaiMulti"] = msg.getResult('stat')['rangpaiMulti']

                if msg.getResult('next') == self.seatId:
                    if self.getState(CMD_GAME_START) == 0:
                        # 叫地主阶段
                        """
                        # 机器人不叫地主
                        """
                        # mycall = 0
                        # mygrab = 0
                        # if stat['call'] >= 0:
                        #     if self.rangPaiMode:
                        #         mygrab = 1
                        #     else:
                        #         mygrab = 1
                        """
                        # 机器人正常叫地主
                        """
                        mycall = 1
                        mygrab = 0
                        if stat['call'] >= 0:
                            if self.rangPaiMode:
                                mygrab = 1
                                if stat["rangpaiMulti"] == 2:
                                    mycall = stat['call'] * 2
                                else:
                                    mycall = stat['call'] + 1
                            else:
                                mygrab = 1
                                if self.tableInfoResult['config'].get(
                                        'grab', 0) == 1:
                                    mycall = random.randint(0, 1)
                                else:
                                    callValues = [] if self.tableInfoResult.get(
                                        'playMode') == 'erdayi' else [0]
                                    if stat['call'] < 3:
                                        callValues.extend([
                                            i for i in range(
                                                max(1, stat['call'] + 1), 3 +
                                                1)
                                        ])
                                    mycall = random.choice(
                                        callValues) if callValues else 0

                        mo = MsgPack()
                        mo.setCmdAction('table_call', 'call')
                        mo.setParam('userId', self.userId)
                        mo.setParam('gameId', self.gameId)
                        mo.setParam('clientId', self.clientId)
                        mo.setParam('roomId', self.roomId)
                        mo.setParam('tableId', self.tableId)
                        mo.setParam('seatId', self.seatId)
                        mo.setParam('grab', mygrab)
                        mo.setParam('call', mycall)
                        self.writeDelayMsg(self.getResponseDelaySecond(), mo)
                    else:
                        # 出牌阶段
                        mycards = self.seat_cards[self.seatId - 1]
                        topseat, topcard = stat["topseat"], stat["topcard"]
                        if topseat == 0 or topseat == self.seatId:
                            if mycards:
                                cards = self.card.findFirstCards(mycards)
                            else:
                                ftlog.warn('mycards is empty BUG !!', topseat,
                                           topcard, self.seatId, mycards)
                                self.stop()
                                return
                        else:
                            cards = self.card.findGreaterCards(
                                topcard, mycards)
                        ftlog.debug('chupai topcard->', topcard, 'mycards->',
                                    mycards, 'outcards=', cards)
                        mo = MsgPack()
                        mo.setCmdAction('table_call', 'card')
                        mo.setParam('userId', self.userId)
                        mo.setParam('gameId', self.gameId)
                        mo.setParam('clientId', self.clientId)
                        mo.setParam('roomId', self.roomId)
                        mo.setParam('tableId', self.tableId)
                        mo.setParam('seatId', self.seatId)
                        mo.setParam('cards', cards)
                        mo.setParam('ccrc', stat["ccrc"])
                        self.writeDelayMsg(self.getResponseDelaySecond(), mo)

            if action == 'wild_card':
                wildCardBig = msg.getResult('wildCardBig')
                for cards in self.seat_cards:
                    for j in xrange(len(cards)):
                        if self.card.isSamePointCard(cards[j], wildCardBig):
                            cards[j] = wildCardBig
                for i in xrange(len(self.base_cards)):
                    if self.card.isSamePointCard(self.base_cards[i],
                                                 wildCardBig):
                        self.base_cards[i] = wildCardBig

            if action == 'card':
                # 出牌, 同步当前的牌
                cards = msg.getResult('cards')
                if not isinstance(cards, list):
                    cards = []
                seatId = msg.getResult('seatId')

                if len(self.seat_cards) >= seatId:
                    seatcards = set(self.seat_cards[seatId - 1]) - set(cards)
                    self.seat_cards[seatId - 1] = list(seatcards)

                ftlog.debug("card | snsId, seatId, seat_cards, out_cards:",
                            self.snsId,
                            seatId,
                            self.seat_cards,
                            cards,
                            caller=self)

            if action == 'game_win':
                if not self._isMatch:
                    self.stop()
                else:
                    # 为下一局初始化部分状态
                    self.cleanState(CMD_QUICK_START, CMD_READY, CMD_GAME_READY,
                                    CMD_GAME_START, CMD_GAME_WINLOSE)

        if cmd == 'm_over':
            self.stop()

        return
Ejemplo n.º 30
0
    def _reactAsTrustee(self, actions, tile, msg):
        message = MsgPack()
        if (self.playMode == "sichuan" or self.playMode == "sichuan_dq"
                or self.playMode == "sichuan_xlch"):
            actionList = []
            if "win" in actions:
                actionList.append(0)
            if "gang" in actions:
                actionList.append(1)
            if "peng" in actions:
                actionList.append(2)
            action, tile = self.tileManager.DealAsTrustee(tile, actionList)
            if action == 0:
                message.setCmdAction('table_call', 'win')
            elif action == 1:
                message.setCmdAction('table_call', 'gang')
            elif action == 2:
                message.setCmdAction('table_call', 'peng')
            elif action == 3:
                message.setCmdAction('table_call', 'pass')
            message.setParam('tile', tile)
        elif (self.playMode == "guobiao" or self.playMode == "guobiao2ren"
              or self.playMode == "nanchang"):
            actionList = []
            if "win" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "gang" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "peng" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "chi" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            reply_action = self.tileManager.react_as_trustee(tile, actionList)
            if reply_action == 0:
                message.setCmdAction('table_call', 'win')
            elif reply_action == 1:
                message.setCmdAction('table_call', 'gang')
            elif reply_action == 2:
                message.setCmdAction('table_call', 'peng')
            elif reply_action == 3:
                message.setCmdAction('table_call', 'pass')
            else:
                message.setCmdAction('table_call', 'chi')
                message.setParam('style', reply_action - 4)
            message.setParam('tile', tile)
        elif (self.playMode == "harbin"):
            actionList = []
            if "win" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "grabTing" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "gang" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "peng" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            if "chi" in actions:
                actionList.append(True)
            else:
                actionList.append(False)
            reply_action = self.tileManager.react_as_trustee(tile, actionList)
            if reply_action == 0:
                message.setCmdAction('table_call', 'win')
            elif reply_action == 1:
                message.setCmdAction('table_call', 'grabTing')
                grabInfo = msg.getResult("grabTing_action")
                if "chi_action" in grabInfo:
                    message.setParam('chi', tile)
                    message.setParam('style', grabInfo["chi_action"][0])
                else:
                    message.setParam('peng', tile)

            elif reply_action == 2:
                message.setCmdAction('table_call', 'gang')
            elif reply_action == 3:
                message.setCmdAction('table_call', 'peng')
            elif reply_action == 4:
                message.setCmdAction('table_call', 'pass')
            else:
                message.setCmdAction('table_call', 'chi')
                message.setParam('style', reply_action - 5)

        message.setParam('userId', self.userId)
        message.setParam('gameId', self.gameId)
        message.setParam('clientId', self.clientId)
        message.setParam('roomId', self.roomId)
        message.setParam('tableId', self.tableId)
        message.setParam('seatId', self.seatId)
        message.setParam('action_id', msg.getResult("action_id"))
        self.writeMsg(message)
        return
Ejemplo n.º 31
0
 def _reactAsTrustee(self, actions, tile, msg):
     message = MsgPack()
     if (self.playMode == "sichuan" or self.playMode == "sichuan_dq" 
                 or self.playMode == "sichuan_xlch"):     
         actionList = []
         if "win" in actions:
             actionList.append(0)   
         if "gang" in actions:
             actionList.append(1)
         if "peng" in actions:
             actionList.append(2)
         action, tile = self.tileManager.DealAsTrustee(tile, actionList)
         if action == 0:
             message.setCmdAction('table_call', 'win')
         elif action == 1:
             message.setCmdAction('table_call', 'gang')
         elif action == 2:
             message.setCmdAction('table_call', 'peng')                
         elif action == 3:
             message.setCmdAction('table_call', 'pass')
         message.setParam('tile', tile)
     elif (self.playMode == "guobiao" or self.playMode == "guobiao2ren" or self.playMode == "nanchang"):
         actionList = []
         if "win" in actions:
             actionList.append(True) 
         else:
             actionList.append(False)
         if "gang" in actions:
             actionList.append(True) 
         else:
             actionList.append(False) 
         if "peng" in actions:
             actionList.append(True) 
         else:
             actionList.append(False) 
         if "chi" in actions:
             actionList.append(True) 
         else:
             actionList.append(False)  
         reply_action = self.tileManager.react_as_trustee(tile, actionList)
         if reply_action == 0:
             message.setCmdAction('table_call', 'win')
         elif reply_action == 1:
             message.setCmdAction('table_call', 'gang')
         elif reply_action == 2:
             message.setCmdAction('table_call', 'peng')
         elif reply_action == 3:
             message.setCmdAction('table_call', 'pass')
         else:
             message.setCmdAction('table_call', 'chi')
             message.setParam('style', reply_action - 4)
         message.setParam('tile', tile)
     elif (self.playMode == "harbin"):
         actionList = []
         if "win" in actions:
             actionList.append(True) 
         else:
             actionList.append(False)
         if "grabTing" in actions:
             actionList.append(True) 
         else:
             actionList.append(False)
         if "gang" in actions:
             actionList.append(True) 
         else:
             actionList.append(False) 
         if "peng" in actions:
             actionList.append(True) 
         else:
             actionList.append(False) 
         if "chi" in actions:
             actionList.append(True) 
         else:
             actionList.append(False)  
         reply_action = self.tileManager.react_as_trustee(tile, actionList)
         if reply_action == 0:
             message.setCmdAction('table_call', 'win')
         elif reply_action == 1:
             message.setCmdAction('table_call', 'grabTing')
             grabInfo = msg.getResult("grabTing_action")
             if "chi_action" in grabInfo:
                 message.setParam('chi', tile)
                 message.setParam('style', grabInfo["chi_action"][0])
             else:
                 message.setParam('peng', tile)
                 
         elif reply_action == 2:
             message.setCmdAction('table_call', 'gang')
         elif reply_action == 3:
             message.setCmdAction('table_call', 'peng')
         elif reply_action == 4:
             message.setCmdAction('table_call', 'pass')
         else:
             message.setCmdAction('table_call', 'chi')
             message.setParam('style', reply_action - 5)
                     
     message.setParam('userId', self.userId)
     message.setParam('gameId', self.gameId)
     message.setParam('clientId', self.clientId)
     message.setParam('roomId', self.roomId)
     message.setParam('tableId', self.tableId)         
     message.setParam('seatId', self.seatId)
     message.setParam('action_id', msg.getResult("action_id"))
     self.writeMsg(message)
     return