Exemplo n.º 1
0
 def doGetCreateTableRecord(self, userId, gameId, clientId):
     """全量请求牌桌记录
     """
     MJCreateTableRecord.sendAllRecordToUser(userId, gameId)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 2
0
def _handlerMsgCommand(markParams, msg):
    handler = markParams['handler']
    fun_method = markParams['fun_method']
    #     ftlog.debug('_handlerMsgCommand->', handler, fun_method)
    errmsg, values = _checkCmdParams(handler, markParams['paramkeys'])
    if errmsg:
        ftlog.error('the command params error !! msg=', getMsgPack(),
                    'errmsg=', errmsg)

    if router.isQuery():
        if errmsg:
            if not isinstance(errmsg, MsgPack):
                errmsg = newErrorMsgPack(2, errmsg)
            router.responseQurery(errmsg)
            try:
                filterErrorMessage(msg)
            except:
                ftlog.error("filterErrorMessage error. msg:", msg)
        else:
            try:
                response = fun_method(*values)
                if not response:
                    response = newOkMsgPack(1)
            except Exception, e:
                ftlog.error('method->', fun_method, 'Exception !',
                            ftsvr.getTaskRunArg())
                response = newErrorMsgPack(1, str(e))
            targs = ftsvr.getTaskRunArg()
            if not targs.get('responsed'):
                if targs.get('userheader1') == 'CQ':
                    if not isinstance(response, MsgPack):
                        response = newOkMsgPack(1)
                router.responseQurery(response)
Exemplo n.º 3
0
def _handlerMsgCommand(markParams, msg):
    handler = markParams['handler']
    fun_method = markParams['fun_method']
    #     ftlog.debug('_handlerMsgCommand->', handler, fun_method)
    errmsg, values = _checkCmdParams(handler, markParams['paramkeys'])
    if errmsg:
        ftlog.error('the command params error !! msg=', getMsgPack(), 'errmsg=', errmsg)

    if router.isQuery():
        if errmsg:
            if not isinstance(errmsg, MsgPack):
                errmsg = newErrorMsgPack(2, errmsg)
            router.responseQurery(errmsg)
            try:
                filterErrorMessage(msg)
            except:
                ftlog.error("filterErrorMessage error. msg:", msg)
        else:
            try:
                response = fun_method(*values)
                if not response:
                    response = newOkMsgPack(1)
            except Exception, e:
                ftlog.error('method->', fun_method, 'Exception !', ftsvr.getTaskRunArg())
                response = newErrorMsgPack(1, str(e))
            targs = ftsvr.getTaskRunArg()
            if not targs.get('responsed'):
                if targs.get('userheader1') == 'CQ':
                    if not isinstance(response, MsgPack):
                        response = newOkMsgPack(1)
                router.responseQurery(response)
Exemplo n.º 4
0
 def doRoomQuickStart(self, roomId, userId):
     msg = runcmd.getMsgPack()
     ftlog.debug('msg=', msg, caller=self)
     gdata.rooms()[roomId].doQuickStart(msg)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 5
0
 def doRoomQuickStart(self, roomId, tableId0, userId):
     msg = runcmd.getMsgPack()
     ftlog.debug('msg=', msg, caller=self)
     gdata.rooms()[roomId].doQuickStart(msg)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 6
0
 def doTableSit(self, userId, roomId, tableId, seatId0, clientId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     table.doSit(msg, userId, seatId0, clientId)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 7
0
 def doTableLeave(self, userId, roomId, tableId, clientId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     table.doLeave(msg, userId, clientId)
     if router.isQuery() :
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 8
0
 def doRoomGetPlayingTableList(self, roomId):
     msg = runcmd.getMsgPack()
     ftlog.debug('msg=', msg, caller=self)
     result = gdata.rooms()[roomId].doGetPlayingTableList()
     if router.isQuery():
         mo = MsgPack()
         mo.setCmd("room")
         mo.setResult("action", "playingTableList")
         mo.updateResult(result)
         router.responseQurery(mo)
Exemplo n.º 9
0
 def doRoomGetPlayingTableList(self, roomId):
     msg = runcmd.getMsgPack()
     ftlog.debug('msg=', msg, caller=self)
     result = gdata.rooms()[roomId].doGetPlayingTableList()
     if router.isQuery() :
         mo = MsgPack()
         mo.setCmd("room")
         mo.setResult("action", "playingTableList")
         mo.updateResult(result)
         router.responseQurery(mo)
Exemplo n.º 10
0
 def doJoinCreateTable(self, userId, gameId, roomId):
     """加入自建桌
     """
     msg = runcmd.getMsgPack()
     ftlog.debug('RoomTcpHandler.doJoinCreateTable msg=', userId,
                 gameId, roomId, msg, caller=self)
     room = gdata.rooms()[roomId]
     self._doJoinCreateTable(room, msg)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 11
0
 def doRoomQuickStart(self, roomId, userId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     if isinstance(room, DizhuRoom):
         room.handleMsg(msg)
     else:
         msg = runcmd.getMsgPack()
         room.doQuickStart(msg)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 12
0
 def doTableCall(self, userId, roomId, tableId, clientId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     action = msg.getParam('action')
     seatId = msg.getParam('seatId', -1) # 旁观时没有seatId参数
     assert isinstance(seatId, int)
     table.doTableCall(msg, userId, seatId, action, clientId)
     if router.isQuery() :
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 13
0
 def doGameQuickStart(self, userId, gameId, clientId, roomId0, tableId0, kindId):
     """
     TCP 发送的至UTIL服务的quick_start暂时不能用lock userid的方式,
     因为,消息流 CO->UT->GR->GT->UT会死锁
     """
     msg = runcmd.getMsgPack()
     ftlog.debug("doGameQuickStart", userId, gameId, clientId, roomId0, tableId0, caller=self)
     FishQuickStartDispatcher.dispatchQuickStart(msg, userId, gameId, roomId0, tableId0, clientId, kindId)
     if router.isQuery():
         mo = runcmd.newOkMsgPack()
         router.responseQurery(mo, "", str(userId))
Exemplo n.º 14
0
 def doTableSit(self, userId, roomId, tableId, seatId0, clientId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     if isinstance(table, DizhuTableCtrl):
         table.proto.handleMsg(msg)
     else:
         table.doSit(msg, userId, seatId0, clientId)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 15
0
 def doTableCall(self, userId, roomId, tableId, clientId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     action = msg.getParam('action')
     seatId = msg.getParam('seatId', -1)  # 旁观时没有seatId参数
     assert isinstance(seatId, int)
     table.doTableCall(msg, userId, seatId, action, clientId)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 16
0
    def doGameQuickStart(self, userId, gameId, clientId, roomId0, tableId0,
                         playMode, sessionIndex):
        '''
        TCP 发送的至UTIL服务的quick_start暂时不能用lock userid的方式, 
        因为,消息流 CO->UT->GR->GT->UT会死锁
        '''
        msg = runcmd.getMsgPack()
        ftlog.debug('doGameQuickStart',
                    userId,
                    gameId,
                    clientId,
                    roomId0,
                    tableId0,
                    playMode,
                    sessionIndex,
                    caller=self)
        if not playMode and roomId0 <= 0 and tableId0 <= 0:
            try:
                # 前端对于sessionIndex是写死的, 不会更具hall_info中的顺序改变而改变
                if sessionIndex == 0:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO
                elif sessionIndex == 1:
                    playMode = majiang_conf.PLAYMODE_SICHUAN
                elif sessionIndex == 2:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO_EREN
                elif sessionIndex == 3:
                    playMode = majiang_conf.PLAYMODE_HARBIN
                elif sessionIndex == 4:
                    playMode = majiang_conf.PLAYMODE_SICHUAN_DQ
                elif sessionIndex == 5:
                    playMode = majiang_conf.PLAYMODE_SICHUAN_XLCH
                elif sessionIndex == 6:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO_VIP
                else:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO
                msg.setParam('playMode', playMode)  # 透传playMode, 以便发送高倍房引导弹窗
            except:
                ftlog.error('doGameQuickStart', msg)
            ftlog.debug('doGameQuickStart sessionIndex=', sessionIndex,
                        'playMode=', playMode)

        if roomId0 < 1000:
            roomIdx = roomId0
            roomId0 = 0
            ftlog.info("quickstart roomID error, from %d change to %d" %
                       (roomIdx, roomId0))

        MajiangQuickStartDispatcher.dispatchQuickStart(msg, userId, gameId,
                                                       roomId0, tableId0,
                                                       playMode, clientId)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 17
0
 def doTableManage(self, roomId, tableId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     action = msg.getParam('action')
     result = table.doTableManage(msg, action)
     if router.isQuery() :
         mo = MsgPack()
         mo.setCmd('table_manage')
         mo.setResult('action', action)
         mo.updateResult(result)
         router.responseQurery(mo)
Exemplo n.º 18
0
 def doTableStandUp(self, userId, roomId, tableId, seatId, clientId):
     '''
     此命令一定是由客户端发送的命令, 如果是内部控制命令,那么需要进行区分命令,不能混合调用
     主要是为了避免站起的原因混乱,
     '''
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     table.doStandUp(msg, userId, roomId, tableId, seatId, TableStandUpEvent.REASON_USER_CLICK_BUTTON, clientId)
     if router.isQuery() :
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 19
0
 def _do_room__quick_start(self, msg):
     '''
     用户快速开始,随机选择一个troom,把用户分发到troom
     '''
     userId = msg.getParam('userId')
     shadowRoomId = msg.getParam('clientRoomId')
     tableId = msg.getParam('tableId')
     continueBuyin = True if msg.getParam('buyin', 0) else False
     self.quickStart(userId, shadowRoomId, tableId, continueBuyin)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 20
0
 def doTableManage(self, roomId, tableId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     action = msg.getParam('action')
     result = table.doTableManage(msg, action)
     if router.isQuery():
         mo = MsgPack()
         mo.setCmd('table_manage')
         mo.setResult('action', action)
         mo.updateResult(result)
         router.responseQurery(mo)
Exemplo n.º 21
0
 def doTableStandUp(self, userId, roomId, tableId, seatId, clientId):
     '''
     此命令一定是由客户端发送的命令, 如果是内部控制命令,那么需要进行区分命令,不能混合调用
     主要是为了避免站起的原因混乱,
     '''
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     table.doStandUp(msg, userId, roomId, tableId, seatId, TableStandUpEvent.REASON_USER_CLICK_BUTTON, clientId)
     if router.isQuery():
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, str(tableId), str(userId))
Exemplo n.º 22
0
    def doCreateTable(self, userId, gameId, roomId):
        """自建桌创建
            1.通过roomId得到房间对象
            2.得到合适的tableId,然后sit
        """
        ftlog.info("<< doCreateTable | userId, clientId, roomId, msg:", userId, gameId, roomId)

        msg = runcmd.getMsgPack()
        room = gdata.rooms()[roomId]
        self._doCreateTable(room, msg, gameId)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 23
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)
Exemplo n.º 24
0
    def doHandleCommonRoomCmdAction(self, userId, gameId, roomId, clientId):
        room = gdata.rooms()[roomId]
        msg = runcmd.getMsgPack()
        params = msg.getKey('params')
        params.update({'room': room})

        if ftlog.is_debug():
            ftlog.debug("<< |userId, gameId, roomId, clientId, msg:", userId, gameId, roomId, clientId, msg,
                        caller=self)

        TYPluginCenter.event(msg, gameId)

        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo)
Exemplo n.º 25
0
 def doGetCreateTableRecord(self, userId, gameId, clientId):
     """全量请求牌桌记录
     """
     msg = runcmd.getMsgPack()
     startRecordIndex = msg.getParam('startRecordIndex', None)
     if not startRecordIndex:
         startRecordIndex = 0
     endRecordIndex = msg.getParam('endRecordIndex', None)
     if not endRecordIndex:
         endRecordIndex = 19
         
     MJCreateTableRecord.sendAllRecordToUser(userId, gameId, startRecordIndex, endRecordIndex)
     if router.isQuery() :
         mo = runcmd.newOkMsgPack(1)
         router.responseQurery(mo, '', str(userId))
Exemplo n.º 26
0
 def doTableManage(self, roomId, tableId):
     msg = runcmd.getMsgPack()
     room = gdata.rooms()[roomId]
     table = room.maptable[tableId]
     action = msg.getParam('action')
     if isinstance(table, DizhuTableCtrl):
         table.proto.handleMsg(msg)
     else:
         table = room.maptable[tableId]
         result = table.doTableManage(msg, action)
     if router.isQuery():
         mo = MsgPack()
         mo.setCmd('table_manage')
         mo.setResult('action', action)
         mo.updateResult(result)
         router.responseQurery(mo)
Exemplo n.º 27
0
    def doJoinCreateTable(self, userId, gameId, clientId, roomId0, tableId0,
                          playMode):
        """用户加入自建牌桌
        """
        loc = onlinedata.checkUserLoc(userId, clientId, gameId)
        lgameId, lroomId, ltableId, lseatId = loc.split('.')
        lgameId, lroomId, ltableId, lseatId = strutil.parseInts(
            lgameId, lroomId, ltableId, lseatId)
        if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >= 0:
            ftlog.warn('create_table error, user in table')
            sendPopTipMsg(userId, "请稍候,正在进桌...")
            config = {
                "type": "quickstart",
                "pluginParams": {
                    "roomId": lroomId,
                    "tableId": ltableId,
                    "seatId": lseatId
                }
            }
            todotask = TodoTaskEnterGameNew(lgameId, config)
            mo = MsgPack()
            mo.setCmd('todo_tasks')
            mo.setResult('gameId', gameId)
            mo.setResult('pluginId', lgameId)
            mo.setResult('userId', userId)
            mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
            router.sendToUser(mo, userId)
        else:
            msg = runcmd.getMsgPack()
            createTableNo = msg.getParam('createTableNo', 0)
            if not createTableNo:
                return
            tableId0, roomId0 = CreateTableData.getTableIdByCreateTableNo(
                createTableNo)
            if not tableId0 or not roomId0:
                sendPopTipMsg(userId, "找不到您输入的房间号")
                return
            msg = runcmd.getMsgPack()
            msg.setParam("shadowRoomId", roomId0)
            msg.setParam("roomId", roomId0)
            msg.setParam("tableId", tableId0)
            msg.setCmdAction("room", "join_create_table")
            router.sendRoomServer(msg, roomId0)

            if router.isQuery():
                mo = runcmd.newOkMsgPack(1)
                router.responseQurery(mo, '', str(userId))
Exemplo n.º 28
0
    def doRoomGM(self, roomId):
        msg = runcmd.getMsgPack()
        if ftlog.is_debug():
            ftlog.info('doRoomGM msg=', msg, caller=self)
        room = gdata.rooms()[roomId]

        result = {}
        params = msg.getKey('params')
        params.update({'room': room})

        evmsg = TYPluginUtils.updateMsg(cmd='EV_ROOM_GM', params=params,
                                        result=result)
        TYPluginCenter.event(evmsg, room.gameId)

        if router.isQuery():
            mo = TYPluginUtils.updateMsg(cmd='room', result=result)
            router.responseQurery(mo)
Exemplo n.º 29
0
    def doGetCreateTableRecord(self, userId, gameId, clientId):
        """全量请求牌桌记录
        """
        msg = runcmd.getMsgPack()
        startRecordIndex = msg.getParam('startRecordIndex', None)
        if not startRecordIndex:
            startRecordIndex = 0
        endRecordIndex = msg.getParam('endRecordIndex', None)
        if not endRecordIndex:
            endRecordIndex = 19

        MJCreateTableRecord.sendAllRecordToUser(userId, gameId,
                                                startRecordIndex,
                                                endRecordIndex)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 30
0
    def doAwardCertificate(self, userId, gameId, match_id, clientId):
        '''
        TCP 发送的至UTIL服务的quick_start暂时不能用lock userid的方式, 
        因为,消息流 CO->UT->GR->GT->UT会死锁
        '''
        msg = runcmd.getMsgPack()
        roomId = msg.getParam("roomId")
        ftlog.debug('doAwardCertificate',
                    userId,
                    gameId,
                    roomId,
                    match_id,
                    caller=self)
        if len(str(roomId)) != 4 and len(str(roomId)) != 8 and len(
                str(roomId)) != 0:
            roomIdx = roomId
            roomId = roomId * 100
            ftlog.info(
                "doAwardCertificate roomID error, from %d change to %d" %
                (roomIdx, roomId))

        allrooms = gdata.roomIdDefineMap()
        ctrlRoomId = roomId
        if roomId in allrooms:
            roomDef = allrooms[roomId]
            if roomDef.parentId > 0:  # this roomId is shadowRoomId
                ctrlRoomId = roomDef.parentId
        else:
            ftlog.warn("doAwardCertificate, error roomId", roomId)
            return

        ftlog.debug("ctrlRoomId:", ctrlRoomId)

        msg1 = MsgPack()
        msg1.setCmd('room')
        msg1.setParam('gameId', gameId)
        msg1.setParam('userId', userId)
        msg1.setParam('roomId', ctrlRoomId)
        msg1.setParam('action', "match_award_certificate")
        msg1.setParam('match_id', match_id)
        msg1.setParam('clientId', clientId)
        router.sendRoomServer(msg1, roomId)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 31
0
    def doRoomGM(self, roomId):
        msg = runcmd.getMsgPack()
        if ftlog.is_debug():
            ftlog.info('doRoomGM msg=', msg, caller=self)
        room = gdata.rooms()[roomId]

        result = {}
        params = msg.getKey('params')
        params.update({'room': room})

        evmsg = TYPluginUtils.updateMsg(cmd='EV_ROOM_GM',
                                        params=params,
                                        result=result)
        TYPluginCenter.event(evmsg, room.gameId)

        if router.isQuery():
            mo = TYPluginUtils.updateMsg(cmd='room', result=result)
            router.responseQurery(mo)
Exemplo n.º 32
0
    def doJoinCreateTable(self, userId, gameId, clientId, roomId0, tableId0, playMode):
        """用户加入自建牌桌
        """
        loc = onlinedata.checkUserLoc(userId, clientId, gameId)
        lgameId, lroomId, ltableId, lseatId = loc.split('.')
        lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId)
        if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >= 0:
            ftlog.warn('create_table error, user in table')
            sendPopTipMsg(userId, "请稍候,正在进桌...")
            config = {
                "type": "quickstart",
                "pluginParams": {
                    "roomId": lroomId,
                    "tableId": ltableId,
                    "seatId": lseatId
                }
            }
            todotask = TodoTaskEnterGameNew(lgameId, config)
            mo = MsgPack()
            mo.setCmd('todo_tasks')
            mo.setResult('gameId', gameId)
            mo.setResult('pluginId', lgameId)
            mo.setResult('userId', userId)
            mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
            router.sendToUser(mo, userId)
        else:
            msg = runcmd.getMsgPack()
            createTableNo = msg.getParam('createTableNo', 0)
            if not createTableNo:
                return
            tableId0, roomId0 = CreateTableData.getTableIdByCreateTableNo(createTableNo)
            if not tableId0 or not roomId0:
                sendPopTipMsg(userId, "找不到您输入的房间号")
                return
            msg = runcmd.getMsgPack()
            msg.setParam("shadowRoomId", roomId0)
            msg.setParam("roomId", roomId0)
            msg.setParam("tableId", tableId0)
            msg.setCmdAction("room", "join_create_table")
            router.sendRoomServer(msg, roomId0)

            if router.isQuery():
                mo = runcmd.newOkMsgPack(1)
                router.responseQurery(mo, '', str(userId))
Exemplo n.º 33
0
def _handlerRpcCommand(msg):
    '''
    处理接收到的一个远程RPC调用
    '''
    t1 = time()
    if performance.PERFORMANCE_NET:
        netkey = msg.getKey(performance.NET_KEY)
        if netkey:
            netkey.append(gdata.serverId())
            netkey.append('DO')
            netkey.append(float('%0.4f' % t1))
    try:
        rpc = msg.getKey('rpc')
        argl = msg.getKey('argl')
        argd = msg.getKey('argd')
        markParams = _runenv._rpc_methods.get(rpc, None)
        ret = _invokeMethodLocked(markParams, argl, argd)
        if markParams['syncCall']:
            if performance.PERFORMANCE_NET:
                netkey = msg.getKey(performance.NET_KEY)
                if not netkey:
                    netkey = []
                mo = strutil.dumps({'ret': ret,
                                    performance.NET_KEY: netkey})
            else:
                mo = strutil.dumps({'ret': ret})
            router.responseQurery(mo)
    except Exception, e:
        ftlog.error('_handlerRpcCommand msg=', msg)
        try:
            if router.isQuery():
                targs = ftsvr.getTaskRunArg()
                if not targs.get('responsed'):
                    if performance.PERFORMANCE_NET:
                        netkey = msg.getKey(performance.NET_KEY)
                        if not netkey:
                            netkey = []
                        mo = strutil.dumps({'ex': '_handlerRpcCommand Exception : ' + str(e),
                                            performance.NET_KEY: netkey})
                    else:
                        mo = strutil.dumps({'ex': '_handlerRpcCommand Exception : ' + str(e)})
                    router.responseQurery(mo)
        except:
            ftlog.error()
Exemplo n.º 34
0
    def doTableGM(self, gameId, roomId, tableId):
        msg = runcmd.getMsgPack()
        if ftlog.is_debug():
            ftlog.info('doTableGM msg=', msg, caller=self)

        room = gdata.rooms()[roomId]
        table = room.maptable[tableId]

        result = {}
        params = msg.getKey('params')
        params.update({'room': room, 'table': table})

        evmsg = TYPluginUtils.updateMsg(cmd="EV_TABLE_GM", params=params,
                                        result=result)
        TYPluginCenter.event(msg, room.gameId)

        if router.isQuery():
            mo = TYPluginUtils.updateMsg(cmd='table', result=result)
            router.responseQurery(mo)
Exemplo n.º 35
0
    def doGetCreateTableRecordForCustomer(self, userId, gameId, clientId):
        """全量请求他人的牌桌记录
        """
        msg = runcmd.getMsgPack()
        targetUserId = msg.getParam('targetUserId', None)
        targetTableNo = msg.getParam('targetTableNo', None)
        playMode = msg.getParam('playMode', None)

        startRecordIndex = msg.getParam('startRecordIndex', None)
        if not startRecordIndex:
            startRecordIndex = 0
        endRecordIndex = msg.getParam('endRecordIndex', None)
        if not endRecordIndex:
            endRecordIndex = 19

        MJCreateTableRecord.sendAllRecordToUserForCustomer(userId, gameId, playMode, targetUserId, targetTableNo, startRecordIndex, endRecordIndex)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 36
0
    def doTableGM(self, gameId, roomId, tableId):
        msg = runcmd.getMsgPack()
        if ftlog.is_debug():
            ftlog.info('doTableGM msg=', msg, caller=self)

        room = gdata.rooms()[roomId]
        table = room.maptable[tableId]

        result = {}
        params = msg.getKey('params')
        params.update({'room': room, 'table': table})

        evmsg = TYPluginUtils.updateMsg(cmd="EV_TABLE_GM",
                                        params=params,
                                        result=result)
        TYPluginCenter.event(msg, room.gameId)

        if router.isQuery():
            mo = TYPluginUtils.updateMsg(cmd='table', result=result)
            router.responseQurery(mo)
Exemplo n.º 37
0
    def doHandleCommonRoomCmdAction(self, userId, gameId, roomId, clientId):
        room = gdata.rooms()[roomId]
        msg = runcmd.getMsgPack()
        params = msg.getKey('params')
        params.update({'room': room})

        if ftlog.is_debug():
            ftlog.debug("<< |userId, gameId, roomId, clientId, msg:",
                        userId,
                        gameId,
                        roomId,
                        clientId,
                        msg,
                        caller=self)

        TYPluginCenter.event(msg, gameId)

        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo)
Exemplo n.º 38
0
    def doGameQuickStart(self, userId, gameId, clientId, roomId0, tableId0, playMode, sessionIndex):
        '''
        TCP 发送的至UTIL服务的quick_start暂时不能用lock userid的方式, 
        因为,消息流 CO->UT->GR->GT->UT会死锁
        '''
        msg = runcmd.getMsgPack()
        ftlog.debug('doGameQuickStart', userId, gameId, clientId, roomId0, tableId0, playMode, sessionIndex,
                    caller=self)
        if not playMode and roomId0 <= 0 and tableId0 <= 0:
            try:
                # 前端对于sessionIndex是写死的, 不会更具hall_info中的顺序改变而改变
                if sessionIndex == 0:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO
                elif sessionIndex == 1:
                    playMode = majiang_conf.PLAYMODE_SICHUAN
                elif sessionIndex == 2:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO_EREN
                elif sessionIndex == 3:
                    playMode = majiang_conf.PLAYMODE_HARBIN
                elif sessionIndex == 4:
                    playMode = majiang_conf.PLAYMODE_SICHUAN_DQ
                elif sessionIndex == 5:
                    playMode = majiang_conf.PLAYMODE_SICHUAN_XLCH
                elif sessionIndex == 6:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO_VIP
                else:
                    playMode = majiang_conf.PLAYMODE_GUOBIAO
                msg.setParam('playMode', playMode)  # 透传playMode, 以便发送高倍房引导弹窗
            except:
                ftlog.error('doGameQuickStart', msg)
            ftlog.debug('doGameQuickStart sessionIndex=', sessionIndex, 'playMode=', playMode)

        if roomId0 < 1000:
            roomIdx = roomId0
            roomId0 = 0
            ftlog.info("quickstart roomID error, from %d change to %d" % (roomIdx, roomId0))

        MajiangQuickStartDispatcher.dispatchQuickStart(msg, userId, gameId, roomId0, tableId0, playMode, clientId)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 39
0
    def doGetCreateTableRecordForCustomer(self, userId, gameId, clientId):
        """全量请求他人的牌桌记录
        """
        msg = runcmd.getMsgPack()
        targetUserId = msg.getParam('targetUserId', None)
        targetTableNo = msg.getParam('targetTableNo', None)
        playMode = msg.getParam('playMode', None)

        startRecordIndex = msg.getParam('startRecordIndex', None)
        if not startRecordIndex:
            startRecordIndex = 0
        endRecordIndex = msg.getParam('endRecordIndex', None)
        if not endRecordIndex:
            endRecordIndex = 19

        MJCreateTableRecord.sendAllRecordToUserForCustomer(
            userId, gameId, playMode, targetUserId, targetTableNo,
            startRecordIndex, endRecordIndex)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 40
0
Arquivo: gm.py Projeto: zhaozw/hall37
    def onEvTableGm(self, gameId, msg):
        ftlog.info('onEvTableGm', msg)
        cmd = msg.getParam('cmd')
        action = msg.getParam('sa')
        roomId = msg.getParam('roomId')
        tableId = msg.getParam('tableId')
        result = {}

        if action == 'playingTableList':
            tables = self._doTableGmGetPlayingTableList(gameId, roomId)
            # msg.setResult('playingTableList', tables)
            result['playingTableList'] = tables
        elif action == 'tableDetail':
            token = msg.getParam('token')
            tableDetail = self._doTableGmGetTableDetail(gameId, roomId, tableId, token)
            # msg.setResult('tableDetail', tableDetail)
            result['tableDetail'] = tableDetail

        if router.isQuery():
            mo = utils.updateMsg(cmd='table', result=result)
            router.responseQurery(mo)
Exemplo n.º 41
0
    def doAwardCertificate(self, userId, gameId, match_id, clientId):
        '''
        TCP 发送的至UTIL服务的quick_start暂时不能用lock userid的方式, 
        因为,消息流 CO->UT->GR->GT->UT会死锁
        '''
        msg = runcmd.getMsgPack()
        roomId = msg.getParam("roomId")
        ftlog.debug('doAwardCertificate', userId, gameId, roomId, match_id, caller=self)
        if len(str(roomId)) != 4 and len(str(roomId)) != 8 and len(str(roomId)) != 0:
            roomIdx = roomId
            roomId = roomId * 100
            ftlog.info("doAwardCertificate roomID error, from %d change to %d" % (roomIdx, roomId))

        allrooms = gdata.roomIdDefineMap()
        ctrlRoomId = roomId
        if roomId in allrooms:
            roomDef = allrooms[roomId]
            if roomDef.parentId > 0:  # this roomId is shadowRoomId
                ctrlRoomId = roomDef.parentId
        else:
            ftlog.warn("doAwardCertificate, error roomId", roomId)
            return

        ftlog.debug("ctrlRoomId:", ctrlRoomId)

        msg1 = MsgPack()
        msg1.setCmd('room')
        msg1.setParam('gameId', gameId)
        msg1.setParam('userId', userId)
        msg1.setParam('roomId', ctrlRoomId)
        msg1.setParam('action', "match_award_certificate")
        msg1.setParam('match_id', match_id)
        msg1.setParam('clientId', clientId)
        router.sendRoomServer(msg1, roomId)
        if router.isQuery():
            mo = runcmd.newOkMsgPack(1)
            router.responseQurery(mo, '', str(userId))
Exemplo n.º 42
0
    def doCreateTable(self,
                      userId,
                      gameId,
                      clientId,
                      roomId0,
                      tableId0,
                      playMode,
                      hasRobot=0):

        #临时硬编码,解决91晃晃提审问题
        if gameId == 791 and playMode == "queshou-lianjiang" and clientId == "IOS_3.901_weixin.appStore,weixinPay.0-hall791.queshou.iostsljmj":
            hasRobot = 1
        if gameId == 790 and playMode == 'luosihu-luosihuts' and clientId == "IOS_3.901_weixin.appStore,weixinPay.0-hall790.laodao.iostsxjmj":
            hasRobot = 1
        """房主创建牌桌"""
        if not playMode:
            ftlog.error(
                'game_handler, cat not create table without playMode...')

        loc = onlinedata.checkUserLoc(userId, clientId, gameId)
        lgameId, lroomId, ltableId, lseatId = loc.split('.')
        lgameId, lroomId, ltableId, lseatId = strutil.parseInts(
            lgameId, lroomId, ltableId, lseatId)
        if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >= 0:
            ftlog.warn('create_table error, user in table', lgameId, lroomId,
                       ltableId, lseatId)
            sendPopTipMsg(userId, "请稍候,正在进桌...")
            config = {
                "type": "quickstart",
                "pluginParams": {
                    "roomId": lroomId,
                    "tableId": ltableId,
                    "seatId": lseatId
                }
            }
            todotask = TodoTaskEnterGameNew(lgameId, config)
            mo = MsgPack()
            mo.setCmd('todo_tasks')
            mo.setResult('gameId', gameId)
            mo.setResult('pluginId', lgameId)
            mo.setResult('userId', userId)
            mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
            router.sendToUser(mo, userId)
        elif self._canEnterGame(userId, gameId):
            # 保存建桌时间戳
            gamedata.setGameAttr(userId, gameId, 'createTableTime',
                                 pktimestamp.getCurrentTimestamp())

            msg = runcmd.getMsgPack()
            itemParams = msg.getParam("itemParams")

            playerCount = 4
            playerTypeId = itemParams.get(MFTDefine.PLAYER_TYPE, 1)
            playerTypeConfig = majiang_conf.getCreateTableConfig(
                gameId, playMode, MFTDefine.PLAYER_TYPE, playerTypeId)
            if not playerTypeConfig:
                sendPopTipMsg(userId, '人数配置有误,请稍后重试')
                return

            playerCount = playerTypeConfig.get('count', 4)
            ftlog.debug('MajiangCreateTable.create_table playerCount:',
                        playerCount)
            cardCountKey = playerTypeConfig.get(MFTDefine.CARD_COUNT,
                                                MFTDefine.CARD_COUNT)

            cardCountId = itemParams.get(cardCountKey, 0)
            cardCountConfig = majiang_conf.getCreateTableConfig(
                gameId, playMode, cardCountKey, cardCountId)
            if not cardCountConfig:
                sendPopTipMsg(userId, '房卡配置有误,请稍后重试')
                return

            if hasRobot == 1 and 'hasRobot' in cardCountConfig:
                cardCountConfig = cardCountConfig.get('hasRobot', {})
                ftlog.debug('MajiangCreateTable.create_table hasRobot == 1:')
            fangka_count = cardCountConfig.get('fangka_count', 1)
            ftlog.debug('MajiangCreateTable.create_table fangka_count:',
                        fangka_count, ' cardCountConfig:', cardCountConfig)

            msg.setParam('isCreateTable', 1)  #标记创建的桌子是 自建桌
            from poker.entity.game.rooms.room import TYRoom
            '''
            根据五个因素筛选合适的房间
            1)gameId         游戏ID
            2)playMode       游戏玩法
            3)playerCount    玩家个数
            4)hasRobot       是否有机器人
            5)itemId         房卡道具
            '''
            itemId = hall_fangka.queryFangKaItem(gameId, userId, clientId)
            if itemId:
                ftlog.debug(
                    'MajiangCreateTable._chooseCreateRoom fangKa itemId:',
                    itemId)
            roomId, checkResult = MajiangCreateTable._chooseCreateRoom(
                userId, gameId, playMode, playerCount, hasRobot, itemId)
            ftlog.debug('MajiangCreateTable._chooseCreateRoom roomId:', roomId,
                        ' checkResult:', checkResult)

            if checkResult == TYRoom.ENTER_ROOM_REASON_OK:
                msg = runcmd.getMsgPack()
                msg.setCmdAction("room", "create_table")
                msg.setParam("roomId", roomId)
                msg.setParam("itemParams", itemParams)
                msg.setParam('needFangka', fangka_count)
                ftlog.debug(
                    'MajiangCreateTable._chooseCreateRoom send message to room:',
                    msg)

                router.sendRoomServer(msg, roomId)
            else:
                sendPopTipMsg(userId, "暂时无法创建请稍后重试")

            if router.isQuery():
                mo = runcmd.newOkMsgPack(1)
                router.responseQurery(mo, '', str(userId))
        else:
            ftlog.info('majiang2 game_handler, ignore enter game request...')
Exemplo n.º 43
0
    def doCreateTable(self, userId, gameId, clientId, roomId0, tableId0, playMode):
        """
        房主创建牌桌
        """
        if not playMode:
            ftlog.error('game_handler, cat not create table without playMode...')

        loc = onlinedata.checkUserLoc(userId, clientId, gameId)
        lgameId, lroomId, ltableId, lseatId = loc.split('.')
        lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId)
        if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >= 0:
            ftlog.warn('create_table error, user in table', lgameId, lroomId, ltableId, lseatId)
            sendPopTipMsg(userId, "请稍候,正在进桌...")
            config = {
                "type": "quickstart",
                "pluginParams": {
                    "roomId": lroomId,
                    "tableId": ltableId,
                    "seatId": lseatId
                }
            }
            todotask = TodoTaskEnterGameNew(lgameId, config)
            mo = MsgPack()
            mo.setCmd('todo_tasks')
            mo.setResult('gameId', gameId)
            mo.setResult('pluginId', lgameId)
            mo.setResult('userId', userId)
            mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
            router.sendToUser(mo, userId)
        elif self._canEnterGame(userId, gameId):
            # 保存建桌时间戳
            gamedata.setGameAttr(userId, gameId, 'createTableTime', pktimestamp.getCurrentTimestamp())

            msg = runcmd.getMsgPack()
            itemParams = msg.getParam("itemParams")
            # cardCount为总局数
            if "cardCount" in itemParams:
                cardCountId = itemParams.get('cardCount', 0)
                cardCountConfig = majiang_conf.getCreateTableConfig(gameId, playMode, 'cardCount', cardCountId)
                fangka_count = cardCountConfig.get('fangka_count', 1)
                ftlog.debug('MajiangCreateTable.create_table fangka_count:', fangka_count)

                playerCount = 4
                playerTypeId = itemParams.get('playerType', 1)
                if playerTypeId:
                    playerTypeConfig = majiang_conf.getCreateTableConfig(gameId, playMode, 'playerType', playerTypeId)
                    playerCount = playerTypeConfig.get('count', 4)
                    ftlog.debug('MajiangCreateTable.create_table playerCount:', playerCount)

                msg.setParam('isCreateTable', 1)  # 标记创建的桌子是 自建桌
                from poker.entity.game.rooms.room import TYRoom
                roomId, checkResult = MajiangCreateTable._chooseCreateRoom(userId, gameId, playMode, playerCount)
                ftlog.debug('MajiangCreateTable._chooseCreateRoom roomId:', roomId, ' checkResult:', checkResult)

                if checkResult == TYRoom.ENTER_ROOM_REASON_OK:
                    msg = runcmd.getMsgPack()
                    msg.setCmdAction("room", "create_table")
                    msg.setParam("roomId", roomId)
                    msg.setParam("itemParams", itemParams)
                    msg.setParam('needFangka', fangka_count)
                    ftlog.debug('MajiangCreateTable._chooseCreateRoom send message to room:', msg)

                    router.sendRoomServer(msg, roomId)
                else:
                    sendPopTipMsg(userId, "暂时无法创建请稍后重试")
            else:
                sendPopTipMsg(userId, "暂时无法创建请稍后重试")

            if router.isQuery():
                mo = runcmd.newOkMsgPack(1)
                router.responseQurery(mo, '', str(userId))
        else:
            ftlog.info('majiang2 game_handler, ignore enter game request...')
Exemplo n.º 44
0
    def doCreateTable(self, userId, gameId, clientId, roomId0, tableId0, playMode, hasRobot = 0):
        
        #临时硬编码,解决91晃晃提审问题
        if gameId==791 and playMode=="queshou-lianjiang" and clientId=="IOS_3.901_weixin.appStore,weixinPay.0-hall791.queshou.iostsljmj":
            hasRobot=1
	if gameId == 790 and playMode == 'luosihu-luosihuts' and clientId=="IOS_3.901_weixin.appStore,weixinPay.0-hall790.laodao.iostsxjmj":
	    hasRobot=1
        """房主创建牌桌"""
        if not playMode:
            ftlog.error('game_handler, cat not create table without playMode...')
        
        loc = onlinedata.checkUserLoc(userId, clientId, gameId)
        lgameId, lroomId, ltableId, lseatId = loc.split('.')
        lgameId, lroomId, ltableId, lseatId = strutil.parseInts(lgameId, lroomId, ltableId, lseatId)
        if lgameId > 0 and lroomId > 0 and ltableId > 0 and lseatId >=0:
            ftlog.warn('create_table error, user in table',lgameId, lroomId, ltableId, lseatId)
            sendPopTipMsg(userId, "请稍候,正在进桌...")
            config = {
                      "type":"quickstart",
                      "pluginParams": {
                          "roomId": lroomId,
                          "tableId": ltableId,
                          "seatId": lseatId
                          }
                      }
            todotask = TodoTaskEnterGameNew(lgameId, config)
            mo = MsgPack()
            mo.setCmd('todo_tasks')
            mo.setResult('gameId', gameId)
            mo.setResult('pluginId', lgameId)
            mo.setResult('userId', userId)
            mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask))
            router.sendToUser(mo, userId)
        elif self._canEnterGame(userId, gameId):
            # 保存建桌时间戳
            gamedata.setGameAttr(userId, gameId, 'createTableTime', pktimestamp.getCurrentTimestamp())
            
            msg = runcmd.getMsgPack()
            itemParams = msg.getParam("itemParams")
            
            playerCount = 4
            playerTypeId = itemParams.get(MFTDefine.PLAYER_TYPE, 1)
            playerTypeConfig = majiang_conf.getCreateTableConfig(gameId, playMode, MFTDefine.PLAYER_TYPE, playerTypeId)
            if not playerTypeConfig:
                sendPopTipMsg(userId, '人数配置有误,请稍后重试')
                return
            
            playerCount = playerTypeConfig.get('count', 4)
            ftlog.debug('MajiangCreateTable.create_table playerCount:', playerCount)
            cardCountKey = playerTypeConfig.get(MFTDefine.CARD_COUNT, MFTDefine.CARD_COUNT)

            cardCountId = itemParams.get(cardCountKey, 0)
            cardCountConfig = majiang_conf.getCreateTableConfig(gameId, playMode, cardCountKey, cardCountId)
            if not cardCountConfig:
                sendPopTipMsg(userId, '房卡配置有误,请稍后重试')
                return
            
            if hasRobot == 1 and 'hasRobot' in cardCountConfig:
                cardCountConfig = cardCountConfig.get('hasRobot', {})
                ftlog.debug('MajiangCreateTable.create_table hasRobot == 1:')
            fangka_count = cardCountConfig.get('fangka_count', 1)
            ftlog.debug('MajiangCreateTable.create_table fangka_count:', fangka_count
                        , ' cardCountConfig:', cardCountConfig)
            
            msg.setParam('isCreateTable', 1) #标记创建的桌子是 自建桌
            from poker.entity.game.rooms.room import TYRoom
            '''
            根据五个因素筛选合适的房间
            1)gameId         游戏ID
            2)playMode       游戏玩法
            3)playerCount    玩家个数
            4)hasRobot       是否有机器人
            5)itemId         房卡道具
            '''
            itemId = hall_fangka.queryFangKaItem(gameId, userId, clientId)
            if itemId:
                ftlog.debug('MajiangCreateTable._chooseCreateRoom fangKa itemId:', itemId)
            roomId, checkResult = MajiangCreateTable._chooseCreateRoom(userId, gameId, playMode, playerCount, hasRobot, itemId)
            ftlog.debug('MajiangCreateTable._chooseCreateRoom roomId:', roomId, ' checkResult:', checkResult)

            if checkResult==TYRoom.ENTER_ROOM_REASON_OK:
                msg = runcmd.getMsgPack()
                msg.setCmdAction("room", "create_table")
                msg.setParam("roomId", roomId)
                msg.setParam("itemParams", itemParams)
                msg.setParam('needFangka', fangka_count)
                ftlog.debug('MajiangCreateTable._chooseCreateRoom send message to room:', msg)

                router.sendRoomServer(msg, roomId)
            else:
                sendPopTipMsg(userId, "暂时无法创建请稍后重试")
                
            if router.isQuery() :
                mo = runcmd.newOkMsgPack(1)
                router.responseQurery(mo, '', str(userId))
        else:
            ftlog.info('majiang2 game_handler, ignore enter game request...')
Exemplo n.º 45
0
def handlerCommand(msg):
    """
    TCP消息命令处理总入口
    """
    orgcmd = msg.getCmd()
    if orgcmd == _runenv._CMD_RPC_:
        return rpccore._handlerRpcCommand(msg)

    orgaction = msg.getParam('action')
    gameId = msg.getParam('gameId')
    cmd, action = None, None
    try:
        if orgaction == None:
            orgaction = ''
        # ftlog.debug('handlerCommand->cmd, action->', cmd, action)
        cmdpath, cmd, action = oldcmd.convertCmdPath(orgcmd, orgaction, msg)
        #         ftlog.debug('handlerCommand->cmd, action, cmdpath, ver, gameId ->', cmd, action, cmdpath, ver, gameId)
        # 先以cmd#action#gameId去查找命令处理器
        vercalls = None
        if gameId:
            vercalls = _runenv._cmd_path_methods.get(cmdpath + '#' + str(gameId), None)
        # 再以cmd#action去查找命令处理器
        if not vercalls:
            vercalls = _runenv._cmd_path_methods.get(cmdpath, None)
        # 再以cmd#*去查找名利处理器
        if not vercalls:
            vercalls = _runenv._cmd_path_methods.get(str(cmd) + '#*#' + str(gameId), None)
        # 再以cmd#*去查找名利处理器
        if not vercalls:
            vercalls = _runenv._cmd_path_methods.get(str(cmd) + '#*', None)
        # ftlog.debug('handlerCommand->vercalls->', vercalls)
        # 再经过clietnId的版本号过滤
        markParams = None
        if vercalls:
            if len(vercalls) > 1:
                ver = getClientIdVer(msg)
                for vercall in vercalls:
                    if ver >= vercall[0]:
                        markParams = vercall[1]
                        break
            else:
                markParams = vercalls[0][1]
        else:
            vercalls = []
        # 若未找到对应的mark定义, 错误返回
        if not markParams:
            raise Exception('the cmd path method not found ! cmdpath=' + str(cmdpath) +
                            ' clientIdVer=' + str(getClientIdVer(msg)) + ' vercalls len=' + str(len(vercalls)) +
                            ' gameId=' + str(gameId) + ' msg=' + str(msg))
        # 锁定当前mark定义的资源
        lockParamName = markParams.get('lockParamName', None)
        if lockParamName:
            lockval = msg.getParam(lockParamName)
            if lockParamName == 'userId' or lockParamName == 'tableId':
                assert (isinstance(lockval, int))
            lockkey = 'lock:' + lockParamName + ':' + str(lockval)
            ftlock = _runenv._FTLOCKS.get(lockkey, None)
            if ftlock == None:
                ftlock = FTLock(lockkey)
                _runenv._FTLOCKS[lockkey] = ftlock
            ftlog.debug('lock resource of', lockkey, 'wait !!')
            ftlock.lock()
            ftlog.debug('lock resource of', lockkey, 'locked !!')

        try:
            if markParams['isRpc']:
                # RPC CALL
                _handlerRpcCommand(markParams, msg)
            else:
                # CLIENT MSG CALL
                _handlerMsgCommand(markParams, msg)
        finally:
            # 释放当前mark定义的资源
            if lockParamName:
                ftlog.debug('lock resource of', lockkey, 'released !!')
                if ftlock.unlock() == 0:
                    del _runenv._FTLOCKS[lockkey]
                    pass
    except Exception, e:
        ftlog.error('cmd=' + str(cmd) + ' action=' + str(action) + ' gameId=' + str(gameId),
                    'orgcmdpath=' + str(orgcmd) + '#' + str(orgaction))
        if router.isQuery():
            targs = ftsvr.getTaskRunArg()
            if not targs.get('responsed') and targs.get('userheader1') == 'CQ':
                response = newErrorMsgPack(1, str(e))
                router.responseQurery(response)
Exemplo n.º 46
0
def handlerCommand(msg):
    """
    TCP消息命令处理总入口
    """
    orgcmd = msg.getCmd()
    if orgcmd == _runenv._CMD_RPC_:
        return rpccore._handlerRpcCommand(msg)

    orgaction = msg.getParam('action')
    gameId = msg.getParam('gameId')
    cmd, action = None, None
    try:
        if orgaction == None:
            orgaction = ''
        # ftlog.debug('handlerCommand->cmd, action->', cmd, action)
        cmdpath, cmd, action = oldcmd.convertCmdPath(orgcmd, orgaction, msg)
        #         ftlog.debug('handlerCommand->cmd, action, cmdpath, ver, gameId ->', cmd, action, cmdpath, ver, gameId)
        # 先以cmd#action#gameId去查找命令处理器
        vercalls = None
        if gameId:
            vercalls = _runenv._cmd_path_methods.get(
                cmdpath + '#' + str(gameId), None)
        # 再以cmd#action去查找命令处理器
        if not vercalls:
            vercalls = _runenv._cmd_path_methods.get(cmdpath, None)
        # 再以cmd#*去查找名利处理器
        if not vercalls:
            vercalls = _runenv._cmd_path_methods.get(
                str(cmd) + '#*#' + str(gameId), None)
        # 再以cmd#*去查找名利处理器
        if not vercalls:
            vercalls = _runenv._cmd_path_methods.get(str(cmd) + '#*', None)
        # ftlog.debug('handlerCommand->vercalls->', vercalls)
        # 再经过clietnId的版本号过滤
        markParams = None
        if vercalls:
            if len(vercalls) > 1:
                ver = getClientIdVer(msg)
                for vercall in vercalls:
                    if ver >= vercall[0]:
                        markParams = vercall[1]
                        break
            else:
                markParams = vercalls[0][1]
        else:
            vercalls = []
        # 若未找到对应的mark定义, 错误返回
        if not markParams:
            raise Exception('the cmd path method not found ! cmdpath=' +
                            str(cmdpath) + ' clientIdVer=' +
                            str(getClientIdVer(msg)) + ' vercalls len=' +
                            str(len(vercalls)) + ' gameId=' + str(gameId) +
                            ' msg=' + str(msg))
        # 锁定当前mark定义的资源
        lockParamName = markParams.get('lockParamName', None)
        if lockParamName:
            lockval = msg.getParam(lockParamName)
            if lockParamName == 'userId' or lockParamName == 'tableId':
                assert (isinstance(lockval, int))
            lockkey = 'lock:' + lockParamName + ':' + str(lockval)
            ftlock = _runenv._FTLOCKS.get(lockkey, None)
            if ftlock == None:
                ftlock = FTLock(lockkey)
                _runenv._FTLOCKS[lockkey] = ftlock
            ftlog.debug('lock resource of', lockkey, 'wait !!')
            ftlock.lock()
            ftlog.debug('lock resource of', lockkey, 'locked !!')

        try:
            if markParams['isRpc']:
                # RPC CALL
                _handlerRpcCommand(markParams, msg)
            else:
                # CLIENT MSG CALL
                _handlerMsgCommand(markParams, msg)
        finally:
            # 释放当前mark定义的资源
            if lockParamName:
                ftlog.debug('lock resource of', lockkey, 'released !!')
                if ftlock.unlock() == 0:
                    del _runenv._FTLOCKS[lockkey]
                    pass
    except Exception, e:
        ftlog.error(
            'cmd=' + str(cmd) + ' action=' + str(action) + ' gameId=' +
            str(gameId), 'orgcmdpath=' + str(orgcmd) + '#' + str(orgaction))
        if router.isQuery():
            targs = ftsvr.getTaskRunArg()
            if not targs.get('responsed') and targs.get('userheader1') == 'CQ':
                response = newErrorMsgPack(1, str(e))
                router.responseQurery(response)