def doQuickStart(self, roomId, msgDict, isSync): if not isSync: ftcore.runOnce(self.doQuickStart, roomId, msgDict, 1) return 1 # do sync code msg = MsgPack(msgDict) tyglobal.rooms()[roomId].doQuickStart(msg) return 1
def endCLientGame(self, msg): if _DEBUG: debug("In synClientInfo @@@ msg = ", msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('endCLientGame the msg params error !', mi.error) else: #todo 1: add loc 2:客户端上行的第一条end_game消息作为判断依据,对双方结算 room = tyglobal.rooms()[mi.roomId] if room.maptable.has_key(mi.tableId): table = room.maptable.pop(mi.tableId) for userid in table.playersInfo.keys(): mo = MsgPack() mo.setCmd('end_game') mo.setResult('result', 'ok') mo.setResult('gameResult', msg.getParamStr('gameResult')) if _DEBUG: debug("OUT endCLientGame @@@ table_info = ", msg) tyrpcconn.sendToUser(userid, mo) else: pass # mo = MsgPack() # mo.setCmd('end_game') # mo.setResult('result', 'has finished') # mo.setResult('msg', msg) # if _DEBUG: # debug("OUT endCLientGame @@@ table_info = ", msg) # tyrpcconn.sendToUser(mi.userid, mo) return 1
def _onTimeout(self, lostUserId): if _DEBUG: debug("In MiniMatchProcess @@@@ onTimeOut, lostUserId = ", lostUserId) room = tyglobal.rooms()[self._roomId] if room.maptable.has_key(self.tableId): room.maptable.pop(self.tableId) if lostUserId == self.userId_a: self.winnerId = self.userId_b mo = MsgPack() mo.setCmd('game_finish_result') mo.setResult('result', 'other player lost internet') mo.setResult('winnerId', self.winnerId) if _DEBUG: debug("OUT game_finish_result @@@ winnerId = ", self.winnerId) tyrpcconn.sendToUser(self.winnerId, mo) else: self.winnerId = self.userId_a mo = MsgPack() mo.setCmd('game_finish_result') mo.setResult('result', 'other player lost internet') mo.setResult('winnerId', self.winnerId) if _DEBUG: debug("OUT game_finish_result @@@ self.winnerId = ", self.winnerId) tyrpcconn.sendToUser(self.winnerId, mo)
def _doMatchAwardCertificate(self, userId, gameId, roomId, match_id): ''' ''' room = tyglobal.rooms()[roomId] if hasattr(room, 'get_award_certificate'): room.get_award_certificate(userId, gameId, match_id)
def quitCLientGame(self, msg): if _DEBUG: debug("In quitCLientGame @@@ msg = ", msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('quitCLientGame the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] loserId = 0 winnerId =0 if room.maptable.has_key(mi.tableId): table = room.maptable.pop(mi.tableId) for userid in table.playersInfo.keys(): if userid == mi.userId: loserId = userid else: winnerId = userid mo = MsgPack() mo.setCmd('table/quit_game') mo.setResult('winnerId', self.winnerId) mo.setResult('userId_a', self.loserId) mo.setResult('userId_b', self.winnerId) mo.setResult('table_msgId', table.tableMsgId) if _DEBUG: debug("OUT quitCLientGame @@@ winnerId = ", winnerId) tyrpcconn.sendToUser(winnerId, mo) tyrpcconn.sendToUser(loserId, mo) else: pass return 1
def synClientInfo(self, msg): if _DEBUG: debug("In synClientInfo @@@ msg = ", msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('synClientInfo the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] if _DEBUG: ftlog.debug("IN synClientInfo @@ synClientInfo =", table.playersInfo.keys()) userId_b = 0 for userid in table.playersInfo.keys(): if userid != mi.userId: mo = MsgPack() mo.setCmd('syn_info') mo.setResult('gdata', msg.getParamStr('gdata')) if _DEBUG: debug("OUT synClientInfo @@@ table_info = ", msg) tyrpcconn.sendToUser(userid, mo) userId_b = userid if table._timer == None: table._timer = MiniMatchProcess(7, mi.userId, userId_b, mi.roomId, mi.tableId) table._timer.stop() table._timer.start() return 1
def check_roomId(msg, _result, name): val = msg.getParamInt(name, 0) if not val: return None, 'the param %s = %s error !' % (name, val) room = tyglobal.rooms().get(val) if not room: return None, 'the param %s = %s room instance not found error !' % (name, val) return val, None
def _doTableSceneLeave(self, userId, roomId, tableId, seatId): """ 客户端离开牌桌场景时通知服务器 added by nick.kai.lee 客户端离开场景时主动发消息告知服务器,服务器可以推送一些消息,比如免费金币的todotask给客户端,当客户端返回房间列表时触发 不能复用leave消息,因为客户端结算时会leave,点击返回按钮时还会leave一次. """ room = tyglobal.rooms()[roomId] table = room.maptable[tableId] table._send_win_sequence_led_message(userId)
def doRoomVipTableList(self, msg): if _DEBUG: debug('doRoomVipTableList->', msg) mi = self.checker1.check(msg) if mi.error: ftlog.error('doRoomVipTableList the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] room.doGetVipTableList(mi.userId, mi.clientId) return 1
def check_tableId(msg, _result, name): tableId = msg.getParamInt(name, 0) if not tableId: return None, 'the param %s = %s error !' % (name, tableId) roomId = tyconfig.getTableRoomId(tableId) room = tyglobal.rooms().get(roomId) if not room: return None, 'the param %s = %s tableid\'s room instance not found error !' % (name, tableId) if not room.maptable.get(tableId): return None, 'the param %s = %s (%s) table instance not found error !' % (name, tableId, roomId) return tableId, None
def doTableSit(self, msg): if _DEBUG: debug('doTableSit->', msg) mi = self.checker2.check(msg) if mi.error: ftlog.error('doTableSit the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doSit(msg, mi.userId, mi.seatId0, mi.clientId) return 1
def get_create_table_by_roomid(cls, roomid): """ table的RPC方法调用,UT进程请求执行,获取此房间符合条件的桌子并返回给UT进程 """ results = {} room = tyglobal.rooms()[roomid] room_conf = room.roomDefine.configure ftlog.debug('room_conf =', room_conf, caller=cls) if not room_conf.get(MFTDefine.IS_CREATE, 0): return results tableId = gameRpcRoomOne.srvtable.getTableByRoomId(roomid).getResult() return tableId
def doTableCall(self, msg): if _DEBUG: debug('doTableCall->', msg) mi = self.checker3.check(msg) if mi.error: ftlog.error('doTableCall the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doTableCall(msg, mi.userId, mi.seatIdObserver, mi.action, mi.clientId) return 1
def doClearTable(roomId, tableId, info): room = tyglobal.rooms()[roomId] if room: table = room.maptable.get(tableId) if table: table.clearMatchTable(info) else: ftlog.warn("stage_match_table_remote clearTable not find table", tableId) else: ftlog.warn("stage_match_table_remote clearTable not find room", roomId) return 0
def doGiveUp(roomId, tableId, userId): room = tyglobal.rooms()[roomId] if room: table = room.maptable.get(tableId) if table: table.giveUp(userId) else: ftlog.warn("stage_match_table_remote doGiveUp not find table", tableId) else: ftlog.warn("stage_match_table_remote doGiveUp not find room", roomId) return 0
def doTableManage(self, msg): # TODO 转换为RPC模式 if _DEBUG: debug('doTableManage->', msg) mi = self.checker3.check(msg) if mi.error: ftlog.error('doTableManage the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doTableManage(msg, mi.action) return 1
def doJoinCreateTable(self, userId, gameId, roomId, msg): """ 加入自建桌 """ ftlog.debug('RoomTcpHandler.doJoinCreateTable msg=', userId, gameId, roomId, msg, caller=self) room = tyglobal.rooms()[roomId] self._doJoinCreateTable(room, msg)
def doSitDown(self, roomId, msgDict, isSync): if not isSync: ftcore.runOnce(self.doSitDown, roomId, msgDict, 1) return 1 msg = MsgPack(msgDict) tableId = msg.getParamInt('tableId', 0) userId = msg.getParamInt('userId', 0) seatId = msg.getParamInt('seatId', 0) clientId = msg.getParamStr('clientId', '') room = tyglobal.rooms()[roomId] table = room.maptable[tableId] table.doSit(msg, userId, seatId, clientId) return 1
def getTableByRoomId(self, roomId): """ * UT调用,需要处理完之后返回消息给UT """ room = tyglobal.rooms().get(roomId, None) if not room: ftlog.info('getTableByRoomId, room is null:', roomId) return 0 table_list = [] for table in room.maptable.values(): table_list.append([table.realPlayerNum, table]) table_list = sorted(table_list, reverse=True) ftlog.debug('===getTableByRoomId===table_list=', table_list) return CreateTable.get_create_table_from_table_list(table_list)
def createNewTable(userId_A, userId_B): for roomId, roomIns in tyglobal.rooms().items(): if _DEBUG: debug("In createNewTable @@@@ roomId = ", roomId, " roomIns = ", roomIns, " userId_A = ", userId_A, " userId_B = ", userId_B) global tableId if not roomIns.maptable: baseid = roomId * 10000 + 1 tableId = baseid if tableId >= roomId * 10000 + 9999: tableId = roomId * 10000 + 1 tableId += 1 tblIns = TYTable(roomIns, tableId) roomIns.maptable[tableId] = tblIns table_Info = {} for userId in [userId_A, userId_B]: name, purl, sex, addr, citycode = _rpc_user_info.getUserBaseInfo( userId) table_Info[userId] = (name, purl, sex, addr, citycode) tblIns.playersInfo = table_Info time_seed = fttime.getCurrentTimestamp() mo = MsgPack() mo.setCmd('start_game') mo.setResult('gameId', tyglobal.gameId()) mo.setResult('roomId', tblIns.roomId) mo.setResult('tableId', tblIns.tableId) mo.setResult('seatId', 1) mo.setResult('time_seed', time_seed) mo.setResult('table_info', table_Info) if _DEBUG: debug("OUT createNewTable @@@ table_info = ", table_Info) tyrpcconn.sendToUser(userId_A, mo) mo = MsgPack() mo.setCmd('start_game') mo.setResult('gameId', tyglobal.gameId()) mo.setResult('roomId', tblIns.roomId) mo.setResult('tableId', tblIns.tableId) mo.setResult('seatId', 2) mo.setResult('time_seed', time_seed) mo.setResult('table_info', table_Info) if _DEBUG: debug("OUT createNewTable @@@ table_info = ", table_Info) tyrpcconn.sendToUser(userId_B, mo) break
def _doMatchState(self, userId, gameId, roomId, match_id): ''' 获取比赛状态 ''' if match_id: # 老比赛,由于前端新比赛也会发此消息,但没有match_id导致的问题,这里处理下 state = tyglobal.rooms()[roomId].getMatchState( userId, gameId, match_id) current_ts = int(time.time()) msg = MsgPack() msg.setCmd('match_state') msg.setResult('gameId', gameId) msg.setResult('userId', userId) msg.setResult('state', state) msg.setResult('match_id', match_id) msg.setResult('current_ts', current_ts) tyrpcconn.sendToUser(userId, msg)
def startGameInfo(self, msg): if _DEBUG: debug("In startGameInfo @@@ msg = ", msg) mi = self.checkStartGameInfo.check(msg) if mi.error: ftlog.error('startGameInfo the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] if _DEBUG: ftlog.debug("IN startGameInfo @@ startGameInfo =", table.playersInfo.keys(), " MsgId = ", mi.MsgId) table.tableMsgId = mi.MsgId mo = MsgPack() mo.setCmd('start_game_info') mo.setResult('result', "ok") tyrpcconn.sendToUser(mi.userid, mo) return 1
def doTableStandUp(self, msg): ''' 此命令一定是由客户端发送的命令, 如果是内部控制命令,那么需要进行区分命令,不能混合调用 主要是为了避免站起的原因混乱, ''' if _DEBUG: debug('doTableStandUp->', msg) mi = self.checker2.check(msg) if mi.error: ftlog.error('doTableStandUp the msg params error !', mi.error) else: room = tyglobal.rooms()[mi.roomId] table = room.maptable[mi.tableId] table.doStandUp(msg, mi.userId, mi.roomId, mi.tableId, mi.seatId0, tygame.TableStandUpEvent.REASON_USER_CLICK_BUTTON, mi.clientId) return 1
def _onTimeout(self, lostUserId): if _DEBUG: debug("In MiniMatchProcess @@@@ onTimeOut, lostUserId = ", lostUserId) room = tyglobal.rooms()[self._roomId] if room.maptable.has_key(self.tableId): table = room.maptable.pop(self.tableId) self.table_msgId = table.tableMsgId if lostUserId == self.userId_a: self.winnerId = self.userId_b mo = MsgPack() mo.setCmd('end_game') mo.setResult('winnerId', self.winnerId) mo.setResult('userId_a', self.userId_a) mo.setResult('userId_b', self.userId_b) mo.setResult('table_msgId', self.table_msgId) if _DEBUG: debug("OUT end_game @@@ winnerId = ", self.winnerId) tyrpcconn.sendToUser(self.winnerId, mo) rpcproxy = getRpcProxy(9993, RPC_CALL_SAFE, RPC_TARGET_MOD_ONE) rpcproxy.srvgame.doReportGameResult(mo, tyglobal.gameId()) else: self.winnerId = self.userId_a mo = MsgPack() mo.setCmd('end_game') mo.setResult('winnerId', self.winnerId) mo.setResult('userId_a', self.userId_a) mo.setResult('userId_b', self.userId_b) mo.setResult('table_msgId', self.table_msgId) if _DEBUG: debug("OUT end_game @@@ self.winnerId = ", self.winnerId) tyrpcconn.sendToUser(self.winnerId, mo) rpcproxy = getRpcProxy(9993, RPC_CALL_SAFE, RPC_TARGET_MOD_ONE) rpcproxy.srvgame.doReportGameResult(mo, tyglobal.gameId())
def doSignin(self, request): userId = request.getParamStr('userId') gameId = request.getParamStr('gameId') roomId0 = request.getParamStr('roomId0') fee = request.getParamStr('fee') ftlog.info('httpmatch_test.doSignin userId=', userId,gameId,roomId0) msg = MsgPack() msg.setCmd('match') msg.setAction('signin') msg.setParam('userId', userId) msg.setParam('gameId', gameId) msg.setParam('roomId', roomId0) msg.setParam('fee', fee) signinParams = {} msg.setParam('signinParams', signinParams) roomIns = tyglobal.rooms()[roomId0] roomIns._do_match__signin(msg) # router.sendRoomServer(msg, roomId0) return 'sign in ok'
def getMatchArea(roomId): room = tyglobal.rooms()[roomId] if room and hasattr(room, 'match'): return room.match return None
def _doTableSmilies(self, userId, roomId, tableId, seatId, smilies, toseat): room = tyglobal.rooms()[roomId] table = room.maptable[tableId] table.doTableSmilies(userId, seatId, smilies, toseat)
def getMatchAwardListInfo(self, roomId, gameId, userId): ftlog.debug('getMatchAwardListInfo, input: ', roomId, gameId, userId) roomIns = tyglobal.rooms()[roomId] bigMatch = tyglobal.gameIns().getBigMatchPlugin() return bigMatch.getMatchAwardListInfo(roomIns, userId)
def doMatchDesc(self, roomId, userId): ftlog.debug('doMatchDesc, input: ', roomId, userId) roomIns = tyglobal.rooms()[roomId] roomIns.doMatchDesc(userId) return 1
def getMaster(roomId): room = tyglobal.rooms()[roomId] if room and hasattr(room, 'matchMaster'): return room.matchMaster return None