def initGame(self): from majiang2.entity import majiang_account self._account = majiang_account serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROBOT : self._robotmgr = MajiangRobotManager() globalEventBus.subscribe(EventHeartBeat, self._robotmgr.onHeartBeat) elif (serverType == gdata.SRV_TYPE_TABLE) or (serverType == gdata.SRV_TYPE_ROOM): CreateTableData.initialize(gdata.serverId()) # 初始化创建牌桌数据模块 MJCreateTableRecord.initialize() # 初始化自建桌战绩模块 elif serverType == gdata.SRV_TYPE_CENTER: pass
def enterFriendTable(self, userId, gameId, clientId, ftId): """进入自建桌,插件实现具体功能""" if ftlog.is_debug(): ftlog.debug('MAJIANG enterFriendTable userId:', userId, ' gameId:', gameId, ' clientId:', clientId, ' ftId:', ftId) tableId0, roomId0 = CreateTableData.getTableIdByCreateTableNo(ftId) if ftlog.is_debug(): ftlog.debug('MAJIANG enterFriendTable ftId:', ftId, ' roomId:', roomId0, ' tableId:', tableId0) if not tableId0 or not roomId0: from majiang2.entity.util import sendPopTipMsg sendPopTipMsg(userId, '您要进入的朋友场房间不存在,请核对房间号') return config = { "type": "game", "pluginParams": { "gameType": 11, "ftId": ftId } } todotask = TodoTaskEnterGameNew(GAMEID, config) mo = MsgPack() mo.setCmd('todo_tasks') mo.setResult('gameId', gameId) mo.setResult('pluginId', GAMEID) mo.setResult('userId', userId) mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask)) router.sendToUser(mo, userId)
def enterFriendTable(self, userId, gameId, clientId, ftId): """进入自建桌,插件实现具体功能""" if ftlog.is_debug(): ftlog.debug('MAJIANG enterFriendTable userId:', userId , ' gameId:', gameId , ' clientId:', clientId , ' ftId:', ftId) tableId0, roomId0 = CreateTableData.getTableIdByCreateTableNo(ftId) if ftlog.is_debug(): ftlog.debug('MAJIANG enterFriendTable ftId:', ftId , ' roomId:', roomId0 , ' tableId:', tableId0) if not tableId0 or not roomId0: from majiang2.entity.util import sendPopTipMsg sendPopTipMsg(userId, '您要进入的朋友场房间不存在,请核对房间号') return config = { "type":"game", "pluginParams": { "gameType": 11, "ftId": ftId } } todotask = TodoTaskEnterGameNew(GAMEID, config) mo = MsgPack() mo.setCmd('todo_tasks') mo.setResult('gameId', gameId) mo.setResult('pluginId', GAMEID) mo.setResult('userId', userId) mo.setResult('tasks', TodoTaskHelper.encodeTodoTasks(todotask)) router.sendToUser(mo, userId)
def _doJoinCreateTable(self, room, msg): ''' 加入牌桌 ''' assert room.roomId == msg.getParam("roomId") userId = msg.getParam("userId") gameId = msg.getParam("gameId") shadowRoomId = msg.getParam("shadowRoomId") tableId = msg.getParam("tableId") clientId = msg.getParam("clientId") tableIdNo = msg.getParam("createTableNo") playMode = room.roomConf.get("playMode") initParams = CreateTableData.getTableParamsByCreateTableNo(tableIdNo) ftlog.debug('RoomTcpHandler._doJoinCreateTable tableNo:', tableIdNo, ' initParams:', initParams) fangKaCount = self.getFangKaCountByTableNo(tableIdNo, initParams, userId, gameId, playMode) ftlog.info( "RoomTcpHandler._doJoinCreateTable >>> userId, clientId, roomId, shadowRoomId, tableId, fangKaCount:", userId, clientId, room.roomId, shadowRoomId, tableId, fangKaCount) if (fangKaCount > 0) and (not self.consumeFangKa( room, userId, gameId, initParams, playMode, fangKaCount)): return assert isinstance(shadowRoomId, int) and tyglobal.roomIdDefineMap( )[shadowRoomId].bigRoomId == room.roomDefine.bigRoomId extParams = msg.getKey('params') room.querySitReq(userId, shadowRoomId, tableId, clientId, extParams)
def get_create_table_from_table_list(cls, table_list): """ 根据room得到合适的table返回 """ for i in xrange(len(table_list)): count, table = table_list[i] if count == 0: #桌子上没人 ftlog.debug('===========get_create_table_by_room==',table.tableId,caller=cls) if table.tableId not in CreateTableData.getAllCreatedTableIdList(): #桌子没被创建 return table.tableId ftlog.debug('===========rpc success==',caller=cls) return 0
def get_create_table_from_table_list(cls, table_list): """ 根据room得到合适的table返回 """ for i in xrange(len(table_list)): count, table = table_list[i] if count == 0: #桌子上没人 ftlog.debug('===========get_create_table_by_room==', table.tableId, caller=cls) if table.tableId not in CreateTableData.getAllCreatedTableIdList( ): #桌子没被创建 return table.tableId ftlog.debug('===========rpc success==', caller=cls) return 0
def checkFriendTable(self, ftId): ''' 检测自建桌ID是否继续使用,如果不使用,将回收次ftId 0 - 有效 1 - 无效 返回值: False - 无用 True - 有用 ''' tableId0, roomId0 = CreateTableData.getTableIdByCreateTableNo(ftId) if not tableId0 or not roomId0: # 房间无用,大厅可释放房间了 return False return True
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))
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))