def saveVideoData(userId, gameRound): if ftlog.is_debug(): ftlog.debug('obsystem.saveVideoData mode=', gdata.mode(), 'in', gdata.RUN_MODE_TINY_TEST, gdata.RUN_MODE_ONLINE, gdata.RUN_MODE_SIMULATION) if gdata.mode() in (gdata.RUN_MODE_TINY_TEST, gdata.RUN_MODE_ONLINE, gdata.RUN_MODE_SIMULATION): return saveVideoDataToCDN(userId, gameRound) else: return saveVideoDataToHttp(userId, gameRound)
def http7muri(): if gdata.mode() == gdata.RUN_MODE_ONLINE: return 'http://httpproxy.ywdier.com/zaixiantuyou/soccer/' elif gdata.mode() == gdata.RUN_MODE_TINY_TEST: return 'http://httpproxy.ywdier.com/zaixiantuyou/soccer/' elif gdata.mode() == gdata.RUN_MODE_SIMULATION: return 'http://httpproxy.ywdier.com/zaixiantuyou/soccer/' return 'http://httpproxy.ywdier.com/zaixiantuyou/soccer/'
def addUserCredit(userId, productId, rmbs): """ 增加用户微信公众号积分商城积分 """ # 玩家每充值1元,增加10积分 if gdata.mode() == gdata.RUN_MODE_ONLINE: requestUrl = "http://wx.dnale4.cn/" else: requestUrl = "http://wxtest.tuyoo.com/" response = None try: params = { "act": "xxfishpoint.xxfishHandel", "type": 1, "typename": u"游戏充值", "account_num": rmbs * 10, "user_id": userId } params["code"] = util.httpParamsSign(params) response, _ = webpage.webget(requestUrl, querys=params, method_="GET") response = json.loads(response) if response.get("code") != 0: ftlog.error("addUserCredit->error", "userId=", userId, "productId=", productId, "rmbs=", rmbs, "response=", response) else: ftlog.info("addUserCredit->success", "userId=", userId, "productId=", productId, "rmbs=", rmbs, "response=", response) except: ftlog.error("addUserCredit->error", "userId=", userId, "productId=", productId, "rmbs=", rmbs, "response=", response)
def make_order_id(appId, orderIdVer62, httpcallback=None, isRemote=False): if gdata.mode() == gdata.RUN_MODE_ONLINE or isRemote: appId = int(appId) seqNum = daobase.executeMixCmd('INCR', 'global.orderid.seq.' + orderIdVer62) # orderId构成:<1位API版本号>+<4位APPID>+DD+<5位序号>,共14位 ct = datetime.now() dd = ct.strftime('%d') a = hex(appId)[2:][-4:] a = '0' * (4 - len(a)) + a b = hex(seqNum)[2:][-7:] b = '0' * (7 - len(b)) + b oid = orderIdVer62 + a + dd + b # 记录单号回应的回调地址 if httpcallback != None and isinstance( httpcallback, (str, unicode)) and httpcallback.find('http://') == 0: daobase.executeMixCmd('HSET', 'global.orderid.callback', oid, httpcallback) return oid else: # 通知订单数据中心(线上GATEWAY服务), 产生了一个新订单, 需要进行 单号<->回调服务的记录 httpurl = gdata.httpOnlieGateWay() + '/_testorder_make_id' datas = { 'appId': appId, 'orderIdVer62': orderIdVer62, 'httpcallback': gdata.httpSdk() } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def _passThis(self): """ 判断这个请求是否需要被屏蔽 """ # 不能在线上和仿真服使用 if gdata.mode() not in [3, 4]: return False return True
def getInfo(self): item = {} item["seatId"] = self.seatIndex # 德州客户端 seatId 从0开始 ! item["userId"] = self.userId if self.userId == 0: return item # user信息 if gdata.mode() == gdata.RUN_MODE_ONLINE: item["name"] = self.name else: item["name"] = '%s_%s_%s' % (self.userId, self.seatIndex, self.name) item["purl"] = self.purl item["sex"] = self.sex item["ip"] = sessiondata.getClientIp(self.userId) # 需要实时更新ip数据 # 牌桌筹码信息 item["chips"] = self.tableChips item["state"] = self.state # game信息 # 统计信息 # 手牌信息 # 状态信息 item["managed"] = self.isManaged # 以插件形式来填充palyerInfo数据 TYPluginCenter.event(TYPluginUtils.updateMsg(cmd=PluginEvents.EV_GET_PLAYER_INFO, params=TYPluginUtils.mkdict( table=self.table, userId=self.userId, player=self, playerInfo=item)), self.table.gameId) return item
def _passThis(self): """ 判断这个请求是否需要被屏蔽 """ # 不能在线上和仿真服使用 if gdata.mode() not in [3, 4]: return False return True
def make_order_id(appId, orderIdVer62, httpcallback=None, isRemote=False): if gdata.mode() == gdata.RUN_MODE_ONLINE or isRemote: appId = int(appId) seqNum = daobase.executeMixCmd('INCR', 'global.orderid.seq.' + orderIdVer62) # orderId构成:<1位API版本号>+<4位APPID>+DD+<5位序号>,共14位 ct = datetime.now() dd = ct.strftime('%d') a = hex(appId)[2:][-4:] a = '0' * (4 - len(a)) + a b = hex(seqNum)[2:][-7:] b = '0' * (7 - len(b)) + b oid = orderIdVer62 + a + dd + b # 记录单号回应的回调地址 if httpcallback != None and isinstance(httpcallback, (str, unicode)) and httpcallback.find('http://') == 0: daobase.executeMixCmd('HSET', 'global.orderid.callback', oid, httpcallback) return oid else: # 通知订单数据中心(线上GATEWAY服务), 产生了一个新订单, 需要进行 单号<->回调服务的记录 httpurl = gdata.httpOnlieGateWay() + '/_testorder_make_id' datas = { 'appId': appId, 'orderIdVer62': orderIdVer62, 'httpcallback': gdata.httpSdk() } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def _reset_daily_task_expire(cls, delta_ts): """动态更改,供测试接口使用""" if gdata.mode() not in (2, 3, 4): return cls.is_testing = True cls.change_delta_ts = delta_ts cls.expire_ts = int(time.time()) + delta_ts
def _initMatch(self): ftlog.info('DizhuCtrlRoomArenaMatch._initMatch', 'roomId=', self.roomId, 'bigmatchId=', self.bigmatchId) conf = DizhuMatchConf().decodeFromDict(self.matchConf) conf.gameId = self.gameId conf.roomId = self.roomId conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 for feeReward in conf.feeRewardList: if not feeReward.roomName: feeReward.roomName = self.roomConf.get('name') self.conf = conf tableManager = MatchTableManager(self.gameId, conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds ftlog.info('DizhuCtrlRoomArenaMatch._initMatch', 'roomId=', self.roomId, 'bigmatchId=', self.bigmatchId, 'shadowRoomIds=', list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure['gameTableCount'] baseid = roomId * 10000 ftlog.info('DizhuCtrlRoomArenaMatch._initMatch', 'roomId=', self.roomId, 'bigmatchId=', self.bigmatchId, 'shadowRoomId=', roomId, 'tableCount=', count, 'baseid=', baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match = DizhuMatch(conf) match.tableController = MatchTableControllerDizhu(self) match.playerNotifier = MatchPlayerNotifierDizhu(self) match.matchRankRewardsSelector = MatchRankRewardsSelectorDizhu(self) match.matchRewardsSender = MatchRankRewardsSenderDizhu(self) match.userInfoLoader = UserInfoLoaderDizhu() match.signinFee = SigninFeeDizhu(self) match.signinRecordDao = SigninRecordDaoDizhu(self) match.userLocker = UserLockerDizhu() match.tableManager = tableManager if not match.matchSafeDao: match.matchSafeDao = MatchSafeDaoRedis() if (gdata.mode() == gdata.RUN_MODE_ONLINE): playerCapacity = int(tableManager.allTableCount * tableManager.tableSeatCount * 0.9) ftlog.info('DizhuCtrlRoomArenaMatch._initMatch AddIdleTable', 'roomId=', self.roomId, 'allTableCount=', tableManager.allTableCount, 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'matchUserMaxCount=', conf.maxPlayerCount) assert(playerCapacity >= conf.maxPlayerCount) self.match = match match.start()
def doRoomSigIn(self, roomId, userId, signinParams): msg = runcmd.getMsgPack() if ftlog.is_debug(): ftlog.debug('msg=', msg, 'mode=', gdata.mode(), caller=self) if not signinParams and gdata.enableTestHtml(): room = gdata.rooms()[roomId] signinParams = gamedata.getGameAttrJson(userId, room.gameId, 'test.signinParams') gdata.rooms()[roomId].doSignin(userId, signinParams)
def doRoomSigIn(self, roomId, userId, signinParams): msg = runcmd.getMsgPack() if ftlog.is_debug(): ftlog.debug('msg=', msg, 'mode=', gdata.mode(), caller=self) if not signinParams and gdata.enableTestHtml(): room = gdata.rooms()[roomId] signinParams = gamedata.getGameAttrJson(userId, room.gameId, 'test.signinParams') gdata.rooms()[roomId].doSignin(userId, signinParams)
def get_daily_task_remain_time(cls): """获取每日任务离重置剩余的时间, 单位:秒""" if (cls.is_testing and gdata.mode() in (2, 3, 4) and cls.change_delta_ts > 0): if cls.expire_ts <= int(time.time()): cls.expire_ts += cls.change_delta_ts return cls.expire_ts - int(time.time()) else: timestamp = pktimestamp.getCurrentDayLeftSeconds() timestamp = max(0, timestamp) return timestamp
def is_old_task(cls, create_time): if (cls.is_testing and cls.change_delta_ts > 0 and gdata.mode() in (2, 3, 4)): delta = cls.expire_ts - int(time.time()) is_old = create_time < cls.expire_ts - cls.change_delta_ts if delta <= 0: cls.expire_ts += cls.change_delta_ts return is_old else: cls.is_testing = False return not pktimestamp.is_same_day(create_time, int(time.time()))
def _initMatch(self): ftlog.info('DizhuCtrlRoomErdayiMatch._initMatch', 'roomId=', self.roomId, 'bigmatchId=', self.bigmatchId) self.conf = MatchConfig.parse(self.gameId, self.roomId, self.bigmatchId, self.roomConf['name'], self.matchConf) self.conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId self.conf.seatId = 1 self.masterRoomId = self.getMasterRoomId() self.isMaster = self.masterRoomId == self.roomId tableManager = TableManager(self, self.conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds ftlog.info('DizhuCtrlRoomErdayiMatch.initMatch', 'roomId=', self.roomId, 'masterRoomId=', self.masterRoomId, 'isMaster=', self.isMaster, 'bigmatchId=', self.bigmatchId, 'shadowRoomIds=', list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure['gameTableCount'] baseid = roomId * 10000 ftlog.info('DizhuErdayiMatchCtrlRoom._initMatch', 'roomId=', self.roomId, 'masterRoomId=', self.masterRoomId, 'isMaster=', self.isMaster, 'bigmatchId=', self.bigmatchId, 'shadowRoomId=', roomId, 'tableCount=', count, 'baseid=', baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match, master = self.buildMatch() match.tableManager = tableManager if gdata.mode() == gdata.RUN_MODE_ONLINE: playerCapacity = int(tableManager.allTableCount * tableManager.tableSeatCount * 0.9) if playerCapacity <= self.conf.start.userMaxCountPerMatch: ftlog.error( 'DizhuErdayiMatchCtrlRoom._initMatch', 'roomId=', self.roomId, 'masterRoomId=', self.masterRoomId, 'isMaster=', self.isMaster, 'bigmatchId=', self.bigmatchId, 'allTableCount=', tableManager.allTableCount, 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'userMaxCount=', self.conf.start.userMaxCount, 'confUserMaxCountPerMatch=', self.conf.start.userMaxCountPerMatch, 'err=', 'NotEnoughTable') assert (playerCapacity >= self.conf.start.userMaxCountPerMatch) self.match = match self.matchMaster = master if master: master.startHeart()
def doRoomQuickSigIn(self, roomId, userId, signinParams): msg = runcmd.getMsgPack() room = gdata.rooms()[roomId] if ftlog.is_debug(): ftlog.debug('msg=', msg, 'mode=', gdata.mode(), caller=self) if isinstance(room, DizhuRoom): room.handleMsg(msg) else: if not signinParams and gdata.enableTestHtml(): room = gdata.rooms()[roomId] signinParams = gamedata.getGameAttrJson( userId, room.gameId, 'test.signinParams') feeIndex = msg.getParam('feeIndex', 0) room.doSignin(userId, signinParams, feeIndex)
def initMatch(self): assert (self.matchPlugin.getMatch(self.roomId) is None) self._logger.info('TYGroupMatchRoom.initMatch ...') conf = MatchConfig.parse(self.gameId, self.roomId, self.bigmatchId, self.roomConf['name'], self.matchConf) conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 tableManager = TableManager(self, conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds self._logger.info('TYGroupMatchRoom.initMatch', 'shadowRoomIds=', list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure['gameTableCount'] baseid = roomId * 10000 self._logger.info('TYGroupMatchRoom.initMatch addTables', 'shadowRoomId=', roomId, 'tableCount=', count, 'baseid=', baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match, master = self.matchPlugin.buildMatch(conf, self) match.tableManager = tableManager if gdata.mode() == gdata.RUN_MODE_ONLINE: playerCapacity = int(tableManager.allTableCount * tableManager.tableSeatCount * 0.9) userMaxCountPerMatch = conf.start.userMaxCountPerMatch if conf.stages and conf.stages[0].groupingType != 0: # 分组赛 userMaxCountPerMatch *= 0.5 if playerCapacity <= userMaxCountPerMatch: self._logger.error('TYGroupMatchRoom.initMatch', 'allTableCount=', tableManager.allTableCount, 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'userMaxCount=', conf.start.userMaxCount, 'confUserMaxCountPerMatch=', conf.start.userMaxCountPerMatch, 'userMaxCountPerMatch=', userMaxCountPerMatch, 'err=', 'NotEnoughTable') assert (playerCapacity > conf.start.userMaxCountPerMatch) self.match = match self.matchMaster = master self.matchPlugin.setMatch(self.roomId, match) if master: master.start() match.start()
def get_short_order_id(orderPlatformId): if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么再mix库中生成短单号 shortOrderId = daobase.executeMixCmd('INCR', 'global.orderid.seq.sort') shortOrderId = str(100000 + shortOrderId)[-6:] daobase.executeMixCmd('HSET', 'sort.orderid.map', shortOrderId, orderPlatformId) return shortOrderId else: # 若是测试服务, 那么调用正式服远程API生成单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_short_id' datas = {'orderPlatformId': orderPlatformId} result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['sortOrderPlatformId']
def initMatch(self): assert (self.matchPlugin.getMatch(self.roomId) is None) self._logger.info('TYGroupMatchRoom.initMatch ...') conf = MatchConfig.parse(self.gameId, self.roomId, self.bigmatchId, self.roomConf['name'], self.matchConf) conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 tableManager = TableManager(self, conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds self._logger.info('TYGroupMatchRoom.initMatch', 'shadowRoomIds=', list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure['gameTableCount'] baseid = roomId * 10000 self._logger.info('TYGroupMatchRoom.initMatch addTables', 'shadowRoomId=', roomId, 'tableCount=', count, 'baseid=', baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match, master = self.matchPlugin.buildMatch(conf, self) match.tableManager = tableManager if gdata.mode() == gdata.RUN_MODE_ONLINE: playerCapacity = int(tableManager.allTableCount * tableManager.tableSeatCount * 0.9) userMaxCountPerMatch = conf.start.userMaxCountPerMatch if conf.stages and conf.stages[0].groupingType != 0: # 分组赛 userMaxCountPerMatch *= 0.5 if playerCapacity <= userMaxCountPerMatch: self._logger.error('TYGroupMatchRoom.initMatch', 'allTableCount=', tableManager.allTableCount, 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'userMaxCount=', conf.start.userMaxCount, 'confUserMaxCountPerMatch=', conf.start.userMaxCountPerMatch, 'userMaxCountPerMatch=', userMaxCountPerMatch, 'err=', 'NotEnoughTable') assert (playerCapacity > conf.start.userMaxCountPerMatch) self.match = match self.matchMaster = master self.matchPlugin.setMatch(self.roomId, match) if master: master.start() match.start()
def get_short_order_id(orderPlatformId): if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么再mix库中生成短单号 shortOrderId = daobase.executeMixCmd('INCR', 'global.orderid.seq.sort') shortOrderId = str(100000 + shortOrderId)[-6:] daobase.executeMixCmd('HSET', 'sort.orderid.map', shortOrderId, orderPlatformId) return shortOrderId else: # 若是测试服务, 那么调用正式服远程API生成单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_short_id' datas = { 'orderPlatformId': orderPlatformId } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['sortOrderPlatformId']
def get_long_order_id(shortOrderId): if not is_short_order_id_format(shortOrderId): return shortOrderId if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么重mix库中取得长单号 orderPlatformId = daobase.executeMixCmd('HGET', 'sort.orderid.map', shortOrderId) return str(orderPlatformId) else: # 若是测试服务, 那么调用正式服远程API取得长单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_long_id' datas = {'sortOrderPlatformId': shortOrderId} result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def get_long_order_id(shortOrderId): if not is_short_order_id_format(shortOrderId): return shortOrderId if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么重mix库中取得长单号 orderPlatformId = daobase.executeMixCmd('HGET', 'sort.orderid.map', shortOrderId) return str(orderPlatformId) else: # 若是测试服务, 那么调用正式服远程API取得长单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_long_id' datas = { 'sortOrderPlatformId': shortOrderId } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def doRoomRevival(self, roomId, userId): msg = runcmd.getMsgPack() room = gdata.rooms()[roomId] if ftlog.is_debug(): ftlog.debug('DizhuRoomTcpHandler.doRoomRevival', 'userId=', userId, 'msg=', msg, 'mode=', gdata.mode(), caller=self) if isinstance(room, DizhuRoom): room.handleMsg(msg) else: pass
def sendCards(self, tableId, userIds): from poker.entity.configure import gdata if gdata.mode() == gdata.RUN_MODE_ONLINE: return None final_bcards = [] allCards = set([c for c in xrange(54)]) if len(userIds) == 2: kick_out_card = set([2, 3, 15, 16, 28, 29, 41, 42]) allCards -= kick_out_card ret = [[] for _ in xrange(len(userIds) + 1)] changed = False try: for i, userId in enumerate(userIds): cards, bcards = gamedata.getGameAttrs( userId, DIZHU_GAMEID, ['test.cards', 'test.bcards']) if cards: changed = True cards = self.decodeCards(cards) if len(cards) > 17: cards = cards[0:17] cards = self.__sendCards(cards, allCards) cards = self.__buqiCards(cards, allCards, 17) ret[i] = list(cards) if not final_bcards and bcards: final_bcards = self.decodeCards(bcards) if len(final_bcards) > 3: final_bcards = final_bcards[0:3] if final_bcards: changed = True final_bcards = self.__sendCards(final_bcards, allCards) final_bcards = self.__buqiCards(final_bcards, allCards, 3) ret[-1] = list(final_bcards) if changed: for i in xrange(len(userIds)): if not ret[i] or len(ret[i]) != 17: ret[i] = list(self.__buqiCards(ret[i], allCards, 17)) return ret return None except: ftlog.error('sendCards.sendCardsToAllUserIds error') return None
def __auto_change_room_count(roomDict): ''' 此方法和webmgr中mode1~mode4的削减标准一致 ''' mode = gdata.mode() if mode == gdata.RUN_MODE_ONLINE: # 模式1,完全配置控制 return roomDict if mode == gdata.RUN_MODE_SIMULATION: pcount = 2 # 模式2,限制为二个进程 tcount = 100 # 模式3, 4限制为一个桌子 if mode in (gdata.RUN_MODE_RICH_TEST, gdata.RUN_MODE_TINY_TEST): pcount = 1 # 模式2,限制为二个进程 tcount = 200 # 模式3, 4限制为一个桌子 roomDict['controlServerCount'] = min(pcount, int(roomDict['controlServerCount'])) roomDict['controlTableCount'] = min(pcount, int(roomDict['controlTableCount'])) roomDict['gameServerCount'] = min(pcount, int(roomDict['gameServerCount'])) roomDict['gameTableCount'] = min(tcount, int(roomDict['gameTableCount'])) return roomDict
def _reportOnlineToSdk(_lockobj): ''' 向当前的SDK服务汇报自己的运行状态 ''' posturl = '%s/_game_server_online_?' % (gdata.httpSdkInner()) datas = {'http_game': gdata.httpGame(), 'conns': gdata.getUserConnIpPortList(), 'mode': gdata.mode(), 'name': gdata.name(), 'time': int(time.time()) } datas = strutil.dumpsbase64(datas) ret, _ = webpage.webgetJson(posturl, {'params': datas}, None, 10) if isinstance(ret, dict): result = ret.get('result', {}) ok = result.get('ok', False) if ok == True: global _REPORT_OK _REPORT_OK = True ftlog.debug('_reportOnlineToSdk-> OK !', ret) return ftlog.debug('_reportOnlineToSdk-> ERROR !', ret)
def initMatch(self): ftlog.info(getMethodName(), '<< |roomId=', self.roomId) assert (self.matchPlugin.getMatch(self.roomId) is None) conf = MatchConfig.parse(self.gameId, self.roomId, self.bigmatchId, self.roomConf["name"], self.matchConf) # conf.tableId = self.maptable.values()[0]._id conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 tableManager = TableManager(self.gameId, conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds ftlog.info(getMethodName(), 'before add IdleTables.', '|roomId=', self.roomId, 'roomIds=', list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure['gameTableCount'] baseid = roomId * 10000 ftlog.info(getMethodName(), 'adding IdleTables of one shadowRoom.', '|roomId=', self.roomId, 'shadowRoomId=', roomId, 'tableCount=', count, 'baseid=', baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match = self.matchPlugin.buildMatch(conf, self) match.tableManager = tableManager if gdata.mode() == gdata.RUN_MODE_ONLINE: playerCapacity = int(tableManager.getAllTableCount() * tableManager.tableSeatCount * 0.9) ftlog.info(getMethodName(), '<< |roomId=', self.roomId, 'allTableCount=', tableManager.getAllTableCount(), 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'matchUserMaxCount=', conf.start.userMaxCount) assert (playerCapacity > conf.start.userMaxCount) match.load() self.match = match self.matchPlugin.setMatch(self.roomId, match)
def initMatch(self): """初始化比赛""" assert (self.matchPlugin.getMatch(self.roomId) is None) self._logger.info("initMatch ...") conf = MatchConfig.parse(self.gameId, self.roomId, self.bigmatchId, self.roomConf["name"], self.matchConf) conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 tableManager = TableManager(self, conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds self._logger.info("initMatch", "shadowRoomIds=", list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure["gameTableCount"] baseid = roomId * 10000 self._logger.info("initMatch addTables", "shadowRoomId=", roomId, "tableCount=", count, "baseid=", baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match, master = self.matchPlugin.buildMatch(conf, self) match.tableManager = tableManager if gdata.mode() == gdata.RUN_MODE_ONLINE: playerCapacity = tableManager.allTableCount * tableManager.tableSeatCount if playerCapacity <= conf.start.userMaxCountPerMatch: self._logger.error("initMatch", "allTableCount=", tableManager.allTableCount, "tableSeatCount=", tableManager.tableSeatCount, "playerCapacity=", playerCapacity, "userMaxCount=", conf.start.userMaxCount, "confUserMaxCountPerMatch=", conf.start.userMaxCountPerMatch, "err=", "NotEnoughTable") # assert (playerCapacity > conf.start.userMaxCountPerMatch) self.match = match self.matchMaster = master self.matchPlugin.setMatch(self.roomId, match) if master: master.startHeart()
def _auto_change_room_count(roomDict): ''' 此方法和webmgr中mode1~mode4的削减标准一致 ''' mode = gdata.mode() if mode == gdata.RUN_MODE_ONLINE: # 模式1,完全配置控制 return roomDict if mode == gdata.RUN_MODE_SIMULATION: pcount = 2 # 模式2,限制为二个进程 tcount = 100 # 模式3, 4限制为一个桌子 if mode in (gdata.RUN_MODE_RICH_TEST, gdata.RUN_MODE_TINY_TEST): pcount = 1 # 模式2,限制为二个进程 tcount = 200 # 模式3, 4限制为一个桌子 roomDict['controlServerCount'] = min(pcount, int(roomDict['controlServerCount'])) roomDict['controlTableCount'] = min(pcount, int(roomDict['controlTableCount'])) roomDict['gameServerCount'] = min(pcount, int(roomDict['gameServerCount'])) roomDict['gameTableCount'] = min(tcount, int(roomDict['gameTableCount'])) return roomDict
def _reportOnlineToSdk(_lockobj): ''' 向当前的SDK服务汇报自己的运行状态 ''' posturl = '%s/_game_server_online_?' % (gdata.httpSdkInner()) datas = { 'http_game': gdata.httpGame(), 'conns': gdata.getUserConnIpPortList(), 'mode': gdata.mode(), 'name': gdata.name(), 'time': int(time.time()) } datas = strutil.dumpsbase64(datas) ret, _ = webpage.webgetJson(posturl, {'params': datas}, None, 10) if isinstance(ret, dict): result = ret.get('result', {}) ok = result.get('ok', False) if ok == True: global _REPORT_OK _REPORT_OK = True ftlog.debug('_reportOnlineToSdk-> OK !', ret) return ftlog.debug('_reportOnlineToSdk-> ERROR !', ret)
def initMatch(self): ftlog.info(getMethodName(), '<< |roomId=', self.roomId) assert (self.matchPlugin.getMatch(self.roomId) is None) conf = MatchConfig.parse(self.gameId, self.roomId, self.bigmatchId, self.roomConf["name"], self.matchConf) # conf.tableId = self.maptable.values()[0]._id conf.tableId = self.roomId * 10000 # 用来表示玩家在房间队列的特殊tableId conf.seatId = 1 tableManager = TableManager(self.gameId, conf.tableSeatCount) shadowRoomIds = self.roomDefine.shadowRoomIds ftlog.info(getMethodName(), 'before add IdleTables.', '|roomId=', self.roomId, 'roomIds=', list(shadowRoomIds)) for roomId in shadowRoomIds: count = self.roomDefine.configure['gameTableCount'] baseid = roomId * 10000 ftlog.info(getMethodName(), 'adding IdleTables of one shadowRoom.', '|roomId=', self.roomId, 'shadowRoomId=', roomId, 'tableCount=', count, 'baseid=', baseid) tableManager.addTables(roomId, baseid, count) random.shuffle(tableManager._idleTables) match = self.matchPlugin.buildMatch(conf, self) match.tableManager = tableManager if gdata.mode() == gdata.RUN_MODE_ONLINE: playerCapacity = int(tableManager.getAllTableCount() * tableManager.tableSeatCount * 0.9) ftlog.info(getMethodName(), '<< |roomId=', self.roomId, 'allTableCount=', tableManager.getAllTableCount(), 'tableSeatCount=', tableManager.tableSeatCount, 'playerCapacity=', playerCapacity, 'matchUserMaxCount=', conf.start.userMaxCount) assert (playerCapacity > conf.start.userMaxCount) match.load() self.match = match self.matchPlugin.setMatch(self.roomId, match)
def runAsDebugMode(): return gdata.mode() not in (gdata.RUN_MODE_ONLINE, gdata.RUN_MODE_SIMULATION)
def runAsDebugMode(): return gdata.mode() not in (gdata.RUN_MODE_ONLINE, gdata.RUN_MODE_SIMULATION)
def _reset_daily_task_expire(uid, delta_ts): """动态更改""" if gdata.mode() not in (2, 3, 4): return expire_time = int(time.time()) + delta_ts user_db(uid, "EXPIRE", daily_key(uid), expire_time)