def __notifyRobotSigninMatch(self, player): ftlog.debug("<< |roomId, instId, playerId :", self.roomId, player.inst.instId, player.userId, caller=self) # if hasattr(player.inst, "calledRobot") : #同一个比赛实例只召唤一次机器人 # return if player.inst.state >= player.inst.STATE_PREPARE: return if self.roomConf.get('hasrobot'): # player.inst.calledRobot = True #同一个比赛实例只召唤一次机器人 startConf = player.inst.conf.start if self.roomConf["robotUserMaxCount"] == -1: if startConf.isTimingType(): minsize = startConf.userMinCount else: minsize = startConf.userCount - 2 else: minsize = self.roomConf["robotUserMaxCount"] cur_p = len(player.inst.playerMap) if cur_p >= minsize: return mo = MsgPack() mo.setCmd('robotmgr') mo.setAction('callmatch') mo.setParam('gameId', self.gameId) mo.setParam('roomId', self.roomId) mo.setParam('robotCount', 4) router.sendRobotServer(mo, player.userId) func = functools.partial(self.__notifyRobotSigninMatch, player) FTTimer(15, func)
def testQuickStart(self): '''测试快速开始''' gameId = 6 userId = random.randint(10000, 20000) roomId = 0 tableId = 0 chip = 800 clientId = "Android_3.501_tuyoo.YDJD.0-hall6.apphui.happy" playMode = "happy" onlinedata.setOnlineState(userId, onlinedata.ONLINE) onlinedata.cleanOnlineLoc(userId) userdata.setAttr(userId, "sessionClientId", clientId) # datas = sessiondata._getUserSessionValues(userId) # ftlog.debug("|userId, session:", userId, datas) oldChip = userchip.getChip(userId) userchip.incrChip(userId, gameId, chip - oldChip, 0, "GM_ADJUST_COIN", 0, clientId) msg = MsgPack() msg.setCmd("quick_start") msg.setParam("gameId", gameId) msg.setParam("userId", userId) # msg.setParam("roomId", roomId) # msg.setParam("tableId", tableId) msg.setParam("clientId", clientId) print '='*30 print msg BaseQuickStartDispatcher.dispatchQuickStart(msg, userId, gameId, roomId, tableId, playMode, clientId) print '='*30
def _callRobotSigninMatch(self, count=1): mo = MsgPack() mo.setCmd("robotmgr") mo.setAction("callmatch") mo.setParam("gameId", self.gameId) mo.setParam("roomId", self.roomId) mo.setParam("robotCount", count) router.sendRobotServer(mo)
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)
def checkTableTiles(self, roomId, tableId): ftlog.debug('MJAdmin.checkTableTiles roomId:', roomId, ' tableId:', tableId) mo = MsgPack() mo.setCmd('table_manage') mo.setAction('tableTiles') mo.setParam('roomId', roomId) mo.setParam('tableId', tableId) router.sendTableServer(mo, roomId) return {'info': 'ok', 'code': 0}
def asyncTestQuickStartPlayerSelectTable(self): roomId = 60011000 ftlog.debug('start testing...', caller=self) mpRoomQuickStartReq = MsgPack() mpRoomQuickStartReq.setCmd("room") mpRoomQuickStartReq.setParam("action", "quick_start") mpRoomQuickStartReq.setParam("userId", random.randint(10001, 20000)) mpRoomQuickStartReq.setParam("tableId", 1) mpRoomQuickStartReq.setParam("roomId", roomId) mpRoomQuickStartReq.setParam("shadowRoomId", roomId + 1) gdata.rooms()[roomId].doQuickStart(mpRoomQuickStartReq)
def sendTableCallObserveReq(cls, userId, shadowRoomId, tableId, clientId): mpReq = MsgPack() mpReq.setCmd("table_call") mpReq.setParam("action", "observe") mpReq.setParam("userId", userId) mpReq.setParam("roomId", shadowRoomId) mpReq.setParam("tableId", tableId) mpReq.setParam("clientId", clientId) if ftlog.is_debug(): ftlog.debug(str(mpReq), caller=cls) router.sendTableServer(mpReq, shadowRoomId)
def doNeituiguangCheckCode(self, userId, inviter, clientId): msg = MsgPack() msg.setCmd('promote_info') msg.setParam('action', 'code_check') msg.setParam('gameId', 9999) msg.setParam('userId', userId) msg.setParam('promoteCode', inviter) if clientId: msg.setParam('clientId', clientId) result = router.queryUtilServer(msg, userId) return {'result': result}
def newErrorMsgPack(errCode, edrrInfo): ''' 快速工具, 依据当前接收的命令, 生成一个返回错误信息的MsgPack ''' mi = getMsgPack() mo = MsgPack() mo.setCmd(mi.getCmd()) action = mi.getParam('action') if action: mo.setParam('action', action) mo.setError(errCode, edrrInfo) return mo
def notifyRobot(self, robotN=1): if ftlog.is_debug(): ftlog.debug("<< |roomId:", self.room.roomId, caller=self) if self.room.roomConf.get('hasrobot'): mo = MsgPack() mo.setCmd('robotmgr') mo.setAction('callmatch') mo.setParam('gameId', self.room.gameId) mo.setParam('roomId', self.room.roomId) mo.setParam('robotCount', robotN) router.sendRobotServer(mo)
def newOkMsgPack(code=1): ''' 快速工具, 依据当前接收的命令, 生成一个返回OK信息的MsgPack ''' mi = getMsgPack() mo = MsgPack() mo.setCmd(mi.getCmd()) action = mi.getParam('action') if action: mo.setParam('action', action) mo.setResult('ok', code) return mo
def convertOldRoomId(roomId, msgstr): if roomId in OLDROOMDI_MAP: rid = OLDROOMDI_MAP[roomId] ftlog.info('convertOldRoomId', roomId, '->', rid) msg = MsgPack() try: msg.unpack(msgstr) except: raise Exception('the json data error 7 !! [' + repr(msgstr) + ']') msg.setParam('roomId', rid) msgstr = msg.pack() return rid, msgstr return roomId, msgstr
def doHallExmallShippingResult(self, userId, exchangeId, result, jdOrderId): mo = MsgPack() mo.setCmd('exchange') mo.setParam('action', 'shippingResult') mo.setParam('userId', userId) mo.setParam('result', result) mo.setParam('exchangeId', exchangeId) mo.setParam('gameId', HALL_GAMEID) mo.setResult('0', 'ok') userdata.clearUserCache(userId) if not userdata.checkUserData(userId): mo.setError(1, 'userId error') mo.setResult('0', 'userId error') return mo try: ec, info = hall_exmall_remote.handleShippingResult( HALL_GAMEID, userId, exchangeId, result, jdOrderId) if ec != 0: mo.setError(ec, info) mo.setResult('0', info) except: ftlog.error() mo.setError(1, 'shipping result fail') mo.setResult('0', 'shipping result fail') return mo
def makeTableManageReq(cls, userId, shadowRoomId, tableId, clientId, action, params=None): mpReq = MsgPack() mpReq.setCmd("table_manage") mpReq.setParam("action", action) mpReq.setParam("userId", userId) mpReq.setParam("gameId", strutil.getGameIdFromInstanceRoomId(shadowRoomId)) mpReq.setParam("roomId", shadowRoomId) mpReq.setParam("tableId", tableId) mpReq.setParam("clientId", clientId) if params: mpReq.updateParam(params) if ftlog.is_debug(): ftlog.debug(str(mpReq), caller=cls) return mpReq
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)
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)
def doExchangeAudit(self, userId, exchangeId, result): mo = MsgPack() mo.setCmd('exchange') mo.setParam('action', 'audit') mo.setParam('userId', userId) mo.setParam('result', result) mo.setParam('exchangeId', exchangeId) mo.setParam('gameId', HALL_GAMEID) mo.setResult('0', 'ok') userdata.clearUserCache(userId) if not userdata.checkUserData(userId): mo.setError(1, 'userId error') mo.setResult('0', 'userId error') return mo try: ec, info = exchange_remote.handleAuditResult( HALL_GAMEID, userId, exchangeId, result) if ec != 0: mo.setError(ec, info) mo.setResult('0', info) except: ftlog.error() mo.setError(1, 'audit fail') mo.setResult('0', 'audit fail') return mo
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}
def _notifyPushUserOnlineStateChanged(self, userId, isOnline, clientId): if integrate.isEnabled('pushserver'): try: mo = MsgPack() mo.setCmd('push_set_user_tag') mo.setParam('appId', HALL_GAMEID) mo.setParam('userId', userId) mo.setParam('clientId', clientId) if isOnline: mo.setParam('tag', 'online') else: mo.setParam('tag', 'offline') integrate.sendTo('pushserver', mo) except: ftlog.error()
def continueTable(self, table): msg = MsgPack() msg.setCmd('table_manage') msg.setAction('ft_continue') msg.setParam('roomId', table.roomId) msg.setParam('tableId', table.tableId) msg.setParam('ftId', table.ftTable.ftId) msg.setParam('expires', table.ftTable.expires) router.sendTableServer(msg, table.roomId)
def createMsgPackRequest(self, cmd, action=None): mp = MsgPack() mp.setCmd(cmd) if action: mp.setParam('action', action) mp.setParam('gameId', self.table.gameId) mp.setParam('roomId', self.table.room.ctrlRoomId) # 目标进程是GR mp.setParam('tableId', self.table.tableId) return mp
def __changeMsgRoomId(msgpack, newRoomId, clientRoomId): """ 处理结果返回给客户端时,部分游戏(例如德州、三顺)需要判断返回的roomId是否与本地一致 """ if isinstance(msgpack, MsgPack): msgpack.setParam("roomId", newRoomId) msgpack.setParam("clientRoomId", clientRoomId) return msgpack else: newMsgPack = MsgPack() try: newMsgPack.unpack(msgpack) except: raise Exception('the json data error 3 !! [' + repr(msgpack) + ']') newMsgPack.setParam("roomId", newRoomId) newMsgPack.setParam("clientRoomId", clientRoomId) return newMsgPack
def doExchangeAudit(self, userId, exchangeId, result): userdata.clearUserCache(userId) msg = MsgPack() msg.setCmd('exchange') msg.setParam('action', 'audit') msg.setParam('userId', userId) msg.setParam('result', result) msg.setParam('exchangeId', exchangeId) msg.setParam('gameId', HALL_GAMEID) return router.queryUtilServer(msg, userId)
def _callRobotSigninMatch(self, count=1): self._logger.debug("MatchRoom._callRobotSigninMatch", count) for _ in xrange(count): ruid = random.randint(1, 200) # 有机器人直接进榜. if userdata.checkUserData(ruid): rname = userdata.getAttr(ruid, "name") self.addMatchRobotUser(ruid, rname) else: # 没有机器人召唤机器人登录. mo = MsgPack() mo.setCmd("robotmgr") mo.setAction("callmatch") mo.setParam("gameId", self.gameId) mo.setParam("roomId", self.roomId) mo.setParam("robotCount", 1) router.sendRobotServer(mo) self._logger.warn( "_callRobotSigninMatch, add robot failed, ruid =", ruid)
def getMsgPack(keys=None): ''' 将当前的HTTP请求的路径和参数内容, 转换为一个MsgPack ''' request = getRequest() args = request.args msg = MsgPack() if keys == None: keys = args.keys() for key in keys: if key in args: value = args[key][0] else: value = '' msg.setParam(key, value.strip()) rpath = request.path.lower().replace('/', '_') msg.setCmd(rpath[1:]) return msg
def doChargeNotify(self, appId, userId, buttonId, rmbs, diamonds, clientId): userdata.clearUserCache(userId) try: ftlog.info('HttpGameHandler.doChargeNotify', 'appId=', appId, 'userId=', userId, 'buttonId=', buttonId, 'rmbs=', rmbs, 'diamonds=', diamonds, 'clientId=', clientId) except: pass mo = MsgPack() mo.setCmd('charge_notify') mo.setParam('gameId', appId) mo.setParam('userId', userId) mo.setParam('prodId', buttonId) mo.setParam('rmbs', rmbs) mo.setParam('diamonds', diamonds) mo.setParam('clientId', clientId) router.sendUtilServer(mo, userId) return 'success'
def _enterTable(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.tableId / 10000) mo.setParam('tableId', self.tableId) self.writeMsg(mo)
def sendRealTimeColorfulLed(cls, gameId, content, receivers=[]): """ 发送一条实时LED消息 receivers: 接收者USERID列表。如果为[],发给所有在线玩家 """ mo = MsgPack() mo.setCmd('game_public_led') mo.setParam('gameId', gameId) mo.setParam('receivers', receivers) mo.setParam('msg', cls._mkRichTextLedBody(content)) mo.setParam('ledWithTodoTask', {'text': cls._mkRichTextBody(content)}) cls.sendToAllCoServer(mo)
def _sendOnLineInfoToUser(self, userId, gameId, clientId): all_count = _ONLINES.get(gameId, 30000) if all_count <= 0: all_count = 30000 rate = hallconf.getOnlineUserCountRate(clientId) mo = MsgPack() mo.setCmd('room_online_info') mo.setParam('gameId', gameId) mo.setParam('free_count', int(all_count * 0.5 * rate)) mo.setParam('high_count', int(all_count * 0.3 * rate)) mo.setParam('match_count', int(all_count * 0.2 * rate)) mo.setParam('rooms', []) router.sendToUser(mo, userId)
def __getRoomIdByTableId(msgpack): """ 部分游戏(例如德州、三顺)老版本牌桌周边功能需要使用bigRoomId,发送给GT的协议里roomId也是bigRoomId """ if isinstance(msgpack, MsgPack): tableId = msgpack.getParam("tableId", 0) shadowRoomId = tableId / 10000 msgpack.setParam("roomId", shadowRoomId) return msgpack, shadowRoomId else: newMsgPack = MsgPack() try: newMsgPack.unpack(msgpack) except: raise Exception('the json data error 4 !! [' + repr(msgpack) + ']') tableId = newMsgPack.getParam("tableId", 0) shadowRoomId = tableId / 10000 newMsgPack.setParam("roomId", shadowRoomId) return newMsgPack, shadowRoomId
def _notifyRobotSigninMatch(self, signer): if self._logger.isDebug(): self._logger.warn('TYGroupMatchRoom._notifyRobotSigninMatch', 'userId=', signer.userId, 'instId=', signer.inst) if self.roomConf.get('hasrobot'): startConf = self.match.matchConf.start if self.roomConf['robotUserMaxCount'] == -1: if startConf.isTimingType(): minsize = startConf.userMinCount else: minsize = startConf.userCount - 2 else: minsize = self.roomConf['robotUserMaxCount'] if signer.inst.signerCount >= minsize: return mo = MsgPack() mo.setCmd('robotmgr') mo.setAction('callmatch') mo.setParam('gameId', self.gameId) mo.setParam('roomId', self.bigRoomId) mo.setParam('robotCount', 4) router.sendRobotServer(mo, signer.userId) func = functools.partial(self._notifyRobotSigninMatch, signer) FTTimer(15, func)
def testQuickEnterRoom(self): '''测试快速进入房间''' gameId = 6 userId = random.randint(10000, 20000) roomId = 6001 tableId = 0 clientId = "Android_3.501_tuyoo.YDJD.0-hall6.apphui.happy" playMode = "happy" onlinedata.setOnlineState(userId, onlinedata.ONLINE) onlinedata.cleanOnlineLoc(userId) msg = MsgPack() msg.setCmd("quick_start") msg.setParam("userId", userId) msg.setParam("roomId", roomId) # msg.setParam("tableId", tableId) msg.setParam("clientId", clientId) print '='*30 print msg BaseQuickStartDispatcher.dispatchQuickStart(msg, userId, gameId, roomId, tableId, playMode, clientId) print '='*30
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}
def sendChangeBetsConfReq(cls, shadowRoomId, betsConf): mpReq = MsgPack() mpReq.setCmd("room") mpReq.setParam("action", "change_betsConf") mpReq.setParam("roomId", shadowRoomId) mpReq.setParam("betsConf", betsConf) if ftlog.is_debug(): ftlog.debug(str(mpReq), caller=cls) router.sendTableServer(mpReq, shadowRoomId)
def doSdkUnsubscribeMember(self, userId, isTempVipUser): userdata.clearUserCache(userId) mo = MsgPack() mo.setCmd('sub_member') mo.setParam('userId', userId) mo.setParam('action', 'unsub') mo.setParam('isTempVipUser', isTempVipUser) router.queryUtilServer(mo, userId) return 'success'
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)
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
def queryRoomGetPlayingTableListReq(cls, shadowRoomId, **kwargs): msg = MsgPack() msg.setCmd("room") msg.setParam("action", "playingTableList") msg.setParam("roomId", shadowRoomId) for key in kwargs: msg.setParam(key, kwargs[key]) if ftlog.is_debug(): ftlog.debug(msg, caller=cls) return router.queryTableServer(msg, shadowRoomId)
def kickUser(self, userId, roomId, tableId): ftlog.debug('MJAdmin.kickUser roomId:', roomId, ' tableId:', tableId, ' userId:', userId) mo = MsgPack() mo.setCmd('table_manage') mo.setAction('leave') mo.setParam('roomId', roomId) mo.setParam('tableId', tableId) mo.setParam('userId', userId) router.sendTableServer(mo, roomId) return {'info': 'ok', 'code': 0}