def __init__(self, roomDefine): super(FishNewbieRoom, self).__init__(roomDefine) if ftlog.is_debug(): ftlog.debug("FishNewbieRoom->", gdata.serverType(), self.roomDefine.shadowRoomIds) self._keyLock = KeyLock() if gdata.serverType() == gdata.SRV_TYPE_ROOM: # GR进程 self.shadowRoomIdOccupyList = [[ shadowRoomId, 0, [] ] for shadowRoomId in self.roomDefine.shadowRoomIds] self.shadowRoomIdOccupyList.sort(key=lambda x: x[0]) self.tableSeatDetails = {} if gdata.serverType() == gdata.SRV_TYPE_TABLE: # GT进程 self._allTableDict = {} # tableId: table self._allPlayerDict = {} # userId: tableId self._allTableSeatDict = {} # tableId: set() self._usableTableDict = {} # taskId: [tableId, tableId1] FTLoopTimer(self.roomConf.get("occupyIntervalSeconds", 3), -1, self._reportRoomUserOccupy).start() from newfish.game import TGFish from newfish.entity.event import EnterTableEvent, LeaveTableEvent TGFish.getEventBus().subscribe(EnterTableEvent, self._triggerEnterTableEvent) TGFish.getEventBus().subscribe(LeaveTableEvent, self._triggerLeaveTableEvent)
def doReloadConf(self, roomDefine): super(TYMttRoom, self).doReloadConf(roomDefine) if gdata.serverType() == gdata.SRV_TYPE_ROOM and self.state < self.MTT_STATE_ENTER: self.matchPlugin.refreshMatchInfo(self.roomDefine) self.matchPlugin.refreshMatchStartTime(self.bigRoomId) else: self.configChanged = True if gdata.serverType() == gdata.SRV_TYPE_TABLE: self.matchPlugin.refreshMatchInfo(self.roomDefine)
def __init__(self, roomDefine): super(FishNormalRoom, self).__init__(roomDefine) self._keyLock = KeyLock() if gdata.serverType() == gdata.SRV_TYPE_ROOM: # 当前进程的类型 'GR' # 服务类型: 游戏的房间服务 self.shadowRoomIdOccupyList = [[shadowRoomId, 0] for shadowRoomId in self.roomDefine.shadowRoomIds] self.shadowRoomIdOccupyList.sort(key=lambda x: x[0]) if gdata.serverType() == gdata.SRV_TYPE_TABLE: # GT进程 self._allTableDict = {} # 所有桌子的字典 {桌子Id: 桌子对象} self._allPlayerDict = {} # {userId: tableId} self._usableTableList = [] # 所有可用的桌子对象 FTLoopTimer(self.roomConf.get("occupyIntervalSeconds", 3), -1, self._reportRoomUserOccupy).start() from newfish.game import TGFish from newfish.entity.event import EnterTableEvent, LeaveTableEvent TGFish.getEventBus().subscribe(EnterTableEvent, self._triggerEnterTableEvent) TGFish.getEventBus().subscribe(LeaveTableEvent, self._triggerLeaveTableEvent)
def checkSitCondition(self, userId): serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: if self.state == self.MTT_STATE_START or self.state < self.MTT_STATE_ENTER: return False, TYRoom.ENTER_ROOM_REASON_WRONG_TIME return self.matchPlugin.checkSitCondition(self.bigRoomId, userId)
def _initialize(): """初始化100万个自建桌房号""" if gdata.serverType() != gdata.SRV_TYPE_CENTER: return ftlog.debug( 'hall_friend_table._initialize check friend table randoms in process CT' ) randomLen = daobase.executeMixCmd('LLEN', FRIEND_TABLE_RANDOM_KEY) ftlog.debug('hall_friend_table._initialize randomLen:', randomLen) if randomLen != FRIEND_TABLE_RANDOM_COUNT: ftlog.debug('hall_friend_table._initialize push random begin:', pktimestamp.getCurrentTimestamp()) daobase.executeMixCmd('DEL', FRIEND_TABLE_RANDOM_KEY) rList = [x for x in range(0, 1000000)] random.shuffle(rList) # 每次PUSH 100个 for index in range(0, 10000): begin = index * 100 daobase.executeMixCmd( 'LPUSH', FRIEND_TABLE_RANDOM_KEY, rList[begin], rList[begin + 1], rList[begin + 2], rList[begin + 3], rList[begin + 4], rList[begin + 5], rList[begin + 6], rList[begin + 7], rList[begin + 8], rList[begin + 9], rList[begin + 10], rList[begin + 11], rList[begin + 12], rList[begin + 13], rList[begin + 14], rList[begin + 15], rList[begin + 16], rList[begin + 17], rList[begin + 18], rList[begin + 19], rList[begin + 20], rList[begin + 21], rList[begin + 22], rList[begin + 23], rList[begin + 24], rList[begin + 25], rList[begin + 26], rList[begin + 27], rList[begin + 28], rList[begin + 29], rList[begin + 30], rList[begin + 31], rList[begin + 32], rList[begin + 33], rList[begin + 34], rList[begin + 35], rList[begin + 36], rList[begin + 37], rList[begin + 38], rList[begin + 39], rList[begin + 40], rList[begin + 41], rList[begin + 42], rList[begin + 43], rList[begin + 44], rList[begin + 45], rList[begin + 46], rList[begin + 47], rList[begin + 48], rList[begin + 49], rList[begin + 50], rList[begin + 51], rList[begin + 52], rList[begin + 53], rList[begin + 54], rList[begin + 55], rList[begin + 56], rList[begin + 57], rList[begin + 58], rList[begin + 59], rList[begin + 60], rList[begin + 61], rList[begin + 62], rList[begin + 63], rList[begin + 64], rList[begin + 65], rList[begin + 66], rList[begin + 67], rList[begin + 68], rList[begin + 69], rList[begin + 70], rList[begin + 71], rList[begin + 72], rList[begin + 73], rList[begin + 74], rList[begin + 75], rList[begin + 76], rList[begin + 77], rList[begin + 78], rList[begin + 79], rList[begin + 80], rList[begin + 81], rList[begin + 82], rList[begin + 83], rList[begin + 84], rList[begin + 85], rList[begin + 86], rList[begin + 87], rList[begin + 88], rList[begin + 89], rList[begin + 90], rList[begin + 91], rList[begin + 92], rList[begin + 93], rList[begin + 94], rList[begin + 95], rList[begin + 96], rList[begin + 97], rList[begin + 98], rList[begin + 99]) ftlog.debug('hall_friend_table._initialize push random end:', pktimestamp.getCurrentTimestamp())
def _initialize(): global _instance newShortUrlSwitch = hallconf.getHallPublic().get('newShortUrlSwitch', 1) if not _instance and not newShortUrlSwitch: _instance = ShortUrlx3me('bqkVoGCAYx', 'EuOLQYtTwyrrkdSKEZWlgqOHRgMPtoZK') _instance.initialize(gdata.serverType()) ftlog.info('hall_short_url._initialize')
def getInstance(roomdefine): # ROOM的基本定义信息RoomDefine: # RoomDefine.parentId int 父级房间ID, 当前为管理房间时, 必定为0 (管理房间, 可以理解为玩家队列控制器) # RoomDefine.roomId int 当前房间ID # RoomDefine.gameId int 游戏ID # RoomDefine.playId int 玩法ID # RoomDefine.level int 级别ID # RoomDefine.controlId int 房间控制ID # RoomDefine.shadowId int 影子ID # RoomDefine.configId int 房间配置ID # RoomDefine.tableCount int 房间中桌子的数量 # RoomDefine.tableRoomIds tuple 当房间为管理房间时, 下属的桌子实例房间的ID列表 # RoomDefine.typeName str 房间类型的名字 # 实现方法依据给出的基本定义信息,返回创建房间实例, # 其必须是 poker.entity.game.rooms.room.TYRoom的子类 '''工场设计模式,根据roomTypeName来创建不同类型的room对象 Raise : KeyError : roomTypeName invalid ''' try: roomTypeName = roomdefine.configure["typeName"] ftlog.debug("create room", "|roomId, roomType:", roomdefine.roomId, roomTypeName) roomClass = tyRoomConst.ROOM_CLASS_DICT[roomTypeName] if isinstance(roomClass, (list, tuple)): from poker.entity.configure import gdata roomClass = roomClass[0] if gdata.serverType() == gdata.SRV_TYPE_ROOM else roomClass[1] if not TYRoomMixin in roomClass.__bases__: roomClass.__bases__ += (TYRoomMixin,) # 添加父类 return roomClass(roomdefine) # 获取房间的实例 except: ftlog.info('create room error, please check bigRoomId:', roomdefine.bigRoomId, ' roomId:', roomdefine.roomId) raise
def initGameAfter(self): serverType = gdata.serverType() if ftlog.is_debug(): ftlog.debug("<< |gameId, serverType:", self.gameId(), serverType) if serverType in (gdata.SRV_TYPE_HTTP, gdata.SRV_TYPE_UTIL, gdata.SRV_TYPE_ROOM, gdata.SRV_TYPE_TABLE, gdata.SRV_TYPE_CENTER): TYPluginCenter.reload(self.GAME_ID) if serverType == gdata.SRV_TYPE_TABLE: for room in gdata.rooms().values(): if room.gameId != self.gameId(): continue if ftlog.is_debug(): ftlog.debug("init tables" "|gameId, serverType, roomId:", self.gameId(), serverType, room.roomId) for table in room.maptable.values(): TYPluginCenter.evmsg(table.gameId, PluginEvent.EV_AFTER_TABLE_CHILD_INIT, {'table': table, 'tableType': table.tableType})
def initGame(self): if ftlog.is_debug(): ftlog.debug("<< |gameId:", self.GAME_ID, caller=self) self.gameInitTime = datetime.now() self._now = datetime.now() if self.GAME_ID == GAME_ID: return serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROBOT: self.initRobotServerGame() elif serverType == gdata.SRV_TYPE_UTIL: self.initUtilServerGame() elif serverType == gdata.SRV_TYPE_TABLE: self.initGTServerGame() elif serverType == gdata.SRV_TYPE_HTTP: self.initHTServerGame() elif serverType == gdata.SRV_TYPE_ROOM: self.initGRServerGame() globalEventBus.subscribe(EventConfigure, self.onReloadConfig) globalEventBus.subscribe(EventHeartBeat, self.onEventHeartBeat)
def on_conf_changed(event): if _inited and event.isChanged(['game:6:duobao.segment:0']): serverType = gdata.serverType() ftlog.debug("duobao.on_conf_changed serverType", serverType) if serverType == gdata.SRV_TYPE_UTIL: DuoBaoUTServerData.refresh_conf() elif serverType == gdata.SRV_TYPE_CENTER: DuoBaoCTServerData.refresh_conf()
def _getRpcDstServerId(rsrv, groupId): if groupId <= 0: if rsrv.srvType == gdata.serverType(): return gdata.serverId() groupId = rsrv.sididx rsrv.sididx += 1 dst = rsrv.sids[groupId % rsrv.sidlen] return dst
def __init__(self, roomdefine): super(TYBigMatchRoom, self).__init__(roomdefine) self.bigmatchId = self.bigRoomId self.matchPlugin = gdata.games()[self.gameId].getBigMatchPlugin() serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self.initMatch() # 此处会给self.match赋值
def needLoadPlugin(cls): return gdata.serverType() in { gdata.SRV_TYPE_ROOM, gdata.SRV_TYPE_TABLE, gdata.SRV_TYPE_UTIL, gdata.SRV_TYPE_HTTP, gdata.SRV_TYPE_CENTER, }
def _initializeCommands(gdatas): """ 初始化HTTP和TCP, RPC的命令入口, 获取各个游戏的实例的handler进行注册处理 分游戏自动搜索所需要的handler 分服务类型自动注册相应的服务handler 对远程调用接口自动进行local和remote的预处理 """ ftlog.debug('initializeCommands begin') stype = gdata.serverType() for gameId, tygame in gdata.games().items(): hpkg = gdata.SRV_TYPE_PKG_NAME[stype] mpkg = tygame._packageName pkg = mpkg + '.servers.' + hpkg ftlog.debug('initializeCommands package->', gameId, pkg) # 动态查找注册HTTP的命令入口 hclazzs = decorator._loadDecoratorClass(pkg, 'markHttpHandler') for fullName, hclazz in hclazzs.items(): handler = hclazz() if __isHandlerEnable(handler): hmts = decorator._findDecoratorMethod(handler, 'markHttpMethod') for mt in hmts: __registerHttpMethod(gameId, fullName, handler, mt[0], mt[1]) # 动态查找注册CMD#ACTION的命令入口 hclazzs = decorator._loadDecoratorClass(pkg, 'markCmdActionHandler') for fullName, hclazz in hclazzs.items(): handler = hclazz() if __isHandlerEnable(handler): hmts = decorator._findDecoratorMethod(handler, 'markCmdActionMethod') for mt in hmts: __registerCmdActionMethod(gameId, fullName, handler, mt[0], mt[1]) if stype != gdata.SRV_TYPE_AGENT: # 动态查找注册RPC的命令入口 hclazzs = decorator._loadDecoratorClass(pkg, 'markRpcHandler') for fullName, hclazz in hclazzs.items(): handler = hclazz() if __isHandlerEnable(handler): hmts = decorator._findDecoratorMethod(handler, 'markRpcMethod') for mt in hmts: __registerLocalRpcMethod(gameId, fullName, handler, mt[0], mt[1]) # 查找所有的游戏的RPC Client的, 进行预处理 for rpcSrvType, rpcSevPkg in gdata.SRV_TYPE_PKG_NAME.items(): pkg = mpkg + '.servers.' + rpcSevPkg hclazzs = decorator._loadDecoratorClass(pkg, 'markRpcHandler') for fullName, hclazz in hclazzs.items(): handler = hclazz() if __isHandlerEnable(handler): hmts = decorator._findDecoratorMethod(handler, 'markRpcMethod') for mt in hmts: __registerRemoteRpcMethod(gameId, rpcSrvType, fullName, handler, mt[0], mt[1]) cps = _runenv._cmd_path_methods.keys() cps.sort() for cp in cps: ftlog.debug('TCP CMD->', cp, _runenv._cmd_path_methods[cp]) ftlog.debug('initializeCommands end')
def __initMatch(self): return # SNG 已下线 self.matchPlugin = gdata.games()[self.gameId].getSngMatchPlugin() self.matchPlugin.initMatchConfs(self.gameId) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self.matchPlugin.cancelMatch(self)
def initialize(): global _inited if not _inited: _inited = True serverType = gdata.serverType() pkeventbus.globalEventBus.subscribe(EventConfigure, on_conf_changed) if serverType == gdata.SRV_TYPE_UTIL: DuoBaoUTServerData.initialize() elif serverType == gdata.SRV_TYPE_CENTER: DuoBaoCTServerData.restart_init_data()
def __init__(self, roomdefine): self.rankRewardsMap = {} self.rankBuildRewardsMap = {} self.userInfoMap = {} self.userInfoCacheTime = {} self.userVipMap = {} self.userFee = {} super(FishTimePointMatchRoom, self).__init__(roomdefine, TimePointMatch) self._logger.info("serverType=", gdata.serverType())
def _registerRpcCall(method, rpc=None): markParams = getattr(method, decorator._METHOD_MARKE, None) ftlog.debug('_registerRpcCall->', markParams) assert (isinstance(markParams, dict)) omethod = markParams['original'] assert (callable(omethod)) paramkeys, _, __, ___ = inspect.getargspec(omethod) markParams['paramkeys'] = paramkeys[:] syncCall = markParams.get('syncCall', 0) assert (syncCall in (0, 1)) groupName = markParams.get('groupName', None) if groupName == RPC_FIRST_SERVERID: groupIndex = 0 else: if groupName: assert (groupName in paramkeys) groupIndex = paramkeys.index(groupName) else: groupIndex = -1 lockName = markParams.get('lockName', None) if lockName: assert (lockName in paramkeys) lockIndex = paramkeys.index(lockName) else: lockIndex = -1 pyPkg = omethod.__module__ rpcSrvType = None if groupName == RPC_FIRST_SERVERID: rpcSrvType = RPC_FIRST_SERVERID else: srvPkg = pyPkg.split('.')[-3] for k, v, in gdata.SRV_TYPE_PKG_NAME.items(): if v == srvPkg: rpcSrvType = k break assert (rpcSrvType in gdata.SRV_TYPE_PKG_NAME) if not rpc: rpc = pyPkg + '.' + method.__name__ markParams['rpc'] = rpc markParams['lockIndex'] = lockIndex # 3个主要再调用端使用的参数 markParams['rpcSrvType'] = rpcSrvType markParams['syncCall'] = syncCall markParams['groupIndex'] = groupIndex if rpcSrvType == gdata.serverType() or rpcSrvType == RPC_FIRST_SERVERID: _runenv._rpc_methods[rpc] = markParams
def _resetIntegrate(adapterKey, integrates): conf = integrates.get(adapterKey, {}) # 配置为空,不启动集成 if conf: if '*' in conf['serverTypes']: pass # 所有类型的进程全部启动集成 else: if gdata.serverType() in conf['serverTypes']: pass # 当前类型的进程全部启动集成 else: conf = {} # 不启动集成 clients.resetAdapters(adapterKey, conf)
def __initMatch(self): return # 游轮赛已下线 self.matchPlugin = gdata.games()[self.gameId].getLtsMatchPlugin() self.matchPlugin.initMatchConfs(self.gameId) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_TABLE: endTimestamp = self.matchPlugin.match_room_confs[ self.bigRoomId]["end_timestamp"] FTTimer(endTimestamp - int(time.time()) + 5, self._checkMatchEnd)
def __init__(self, roomdefine): super(TYGroupMatchRoom, self).__init__(roomdefine) self.bigmatchId = self.bigRoomId self.matchPlugin = gdata.games()[self.gameId].getGroupMatchPlugin() self.match = None self.matchMaster = None self._logger = Logger() self._logger.add('roomId', self.roomId) self._logger.add('bigmatchId', self.bigmatchId) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self.initMatch() # 此处会给self.match赋值
def __init__(self, roomdefine): super(TYErdayiMatchRoom, self).__init__(roomdefine) self.bigmatchId = self.bigRoomId self.matchPlugin = gdata.games()[self.gameId].getErdayiMatchPlugin() self.match = None self.matchMaster = None self._logger = Logger() self._logger.add('roomId', self.roomId) self._logger.add('bigmatchId', self.bigmatchId) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self.initMatch() # 此处会给self.match赋值
def _initialize(): global _inited serverType = gdata.serverType() if not _inited and serverType == gdata.SRV_TYPE_CENTER: _inited = True _initRobots() _loadCfgRobotNamesAndUrls() tyeventbus.globalEventBus.subscribe(EventConfigure, _loadRobotsConfig) if ftlog.is_debug(): ftlog.debug('hall_robot_user._initialize', 'names=', _userNames, 'headUrls=', _headUrls)
def isOtherGameServer(cls, gameId): '''判断是否为别的游戏的GR/GT,如果是,不加载当前游戏的 plugins''' serverType, serverId = gdata.serverType(), gdata.serverId() if serverType not in (gdata.SRV_TYPE_ROOM, gdata.SRV_TYPE_TABLE): return False if '-' in serverId: serverGameId = int(serverId.split('-')[0][2:]) elif serverType == gdata.SRV_TYPE_ROOM: serverGameId = int(serverId[2:-4]) elif serverType == gdata.SRV_TYPE_TABLE: serverGameId = int(serverId[2:-7]) return serverGameId != gameId
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 initGame(self): from difang.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 __init__(self, roomdefine, plugin=None): super(FishTimeMatchRoom, self).__init__(roomdefine) self.bigmatchId = self.bigRoomId if plugin is None: self.matchPlugin = TimeMatch else: self.matchPlugin = plugin self.match = None self.matchMaster = None self._logger = Logger() self._logger.add("cls", self.__class__.__name__) self._logger.add("roomId", self.roomId) self._logger.add("bigmatchId", self.bigmatchId) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self.initMatch() # 此处会给self.match赋值
def check(self, userId, product): if gdata.serverType() != "HT": return True ret_code, ret_msg = _http_check_enough(self.itemId, userId) if ftlog.is_debug(): ftlog.debug('TYBuyConditionFangkaEnough.check userId=', userId, 'productId=', product.productId, 'itemId=', self.itemId, 'ret_code=', ret_code, 'ret_msg=', ret_msg) if ret_code != 1: raise TYStoreException(ret_code, ret_msg) return True
def initGameAfter(self): """ 此方法由系统进行调用 游戏初始化的后处理 """ serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_TABLE: roomIds = gdata.srvIdRoomIdListMap().get(gdata.serverId(), None) if roomIds: from freetime.core.timer import FTLoopTimer from newfish.servers.room.rpc import room_remote allRooms = gdata.roomIdDefineMap() for roomId in roomIds: ctrlRoomId = allRooms[roomId].parentId tableCount = allRooms[roomId].tableCount # 目前GR、GT是同时启动,GT启动完成时,GR不一定启动完成,所以暂时延后调用 FTLoopTimer(3, 0, room_remote.initializedGT, ctrlRoomId, roomId, tableCount).start()
def event_handle(self, gameId): serverType = gdata.serverType() if serverType not in (gdata.SRV_TYPE_TABLE, ): return {} common_handlers = { PluginEvent.EV_RELOAD_CONFIG: self.onEvReloadConfig, } handlers = {} if serverType == gdata.SRV_TYPE_TABLE: handlers = { ('table', 'smilies'): self.doTableSmilies, } handlers.update(common_handlers) return handlers
def newTable(self, room, tableId): """ 此方法由系统进行调用 更具给出的房间的基本定义信息, 创建一个TYTable的实例 其必须是 poker.entity.game.table.TYTable的子类 room 桌子所属的房间的TYRoom实例 tableId 新桌子实例的ID """ serverType = gdata.serverType() typeName = room.roomConf.get("typeName") if serverType == gdata.SRV_TYPE_TABLE and typeName in tyRoomConst.ROOM_CLASS_DICT: lotteryPool = hasattr(room, "lotteryPool") if not lotteryPool: room.lotteryPool = NormalLotteryPool(room) # ringLotteryPool = hasattr(room, "lotteryPool") # if not ringLotteryPool: # room.ringLotteryPool = RingLotteryPool(room) table = room.newTable(tableId) return table
def event_handle(self, gameId): serverType = gdata.serverType() if serverType not in (gdata.SRV_TYPE_TABLE, ): return {} common_handlers = { PluginEvent.EV_RELOAD_CONFIG: self.onEvReloadConfig, } handlers = {} if serverType == gdata.SRV_TYPE_TABLE: handlers = { PluginEvent.EV_TRANSIT_TO_STATE_START_GAME: self.onTableGameStart, PluginEvent.EV_TRANSIT_TO_STATE_FINAL: self.onTableGameWin, } handlers.update(common_handlers) return handlers
def _initializePoker(gdatas): ''' 初始化服务的基本(大厅通用)的HTTP和TCP命令入口 ''' if _DEBUG: debug('initializePoker begin') stype = gdata.serverType() # 启动全局配置系统的同步 from poker.entity.configure import synccenter synccenter._initialize() globalEventBus.subscribe(EventHeartBeat, synccenter.doSyncData) from poker.entity.biz import integrate integrate._initialize() # 如果是CONN进程, 那么启动空闲TCP链接的检查 if stype == gdata.SRV_TYPE_CONN: from poker.protocol.conn.protocols import doCleanUpEmptyTcp globalEventBus.subscribe(EventHeartBeat, doCleanUpEmptyTcp) # 如果是AGENT进程, 那么启用自身的命令处理器 if stype == gdata.SRV_TYPE_AGENT: from poker.protocol.common.protocols import onAgentSelfCommand from freetime.support.tcpagent.protocol import A2SProtocol, A2AProtocol A2SProtocol.onCommand = onAgentSelfCommand A2AProtocol.onCommand = onAgentSelfCommand if gdata.isHttpProcess(): from poker.protocol import runhttp runhttp.addWebRoot(gdata.pathWebroot()) if stype == gdata.SRV_TYPE_UTIL: from poker.entity.dao import datasubscribe datasubscribe._initialize() if _DEBUG: debug('initializePoker end')
def event_handle(self, gameId): serverType = gdata.serverType() if serverType not in (gdata.SRV_TYPE_UTIL, gdata.SRV_TYPE_ROOM, gdata.SRV_TYPE_HTTP, gdata.SRV_TYPE_TABLE): return {} common_handlers = { # PluginEvent.EV_NEW_TIME: self.onEvNewTime, PluginEvent.EV_RELOAD_CONFIG: self.onEvReloadConfig, } handlers = {} if serverType == gdata.SRV_TYPE_UTIL: handlers = { ('game', 'create_custom_table'): self.onGameCreateCustomTable, ('game', 'get_custom_options'): self.onGameGetCustomOptions, ('game', 'get_custom_records'): self.getCustomRecords, } elif serverType == gdata.SRV_TYPE_ROOM: handlers = { ('room', 'create_custom_table'): self.onRoomCreateCustomTable, } elif serverType == gdata.SRV_TYPE_TABLE: handlers = { PluginEvent.EV_SEND_TABLE_INFO: self.onSendTableInfo, PluginEvent.EV_TRANSIT_TO_STATE_START_GAME: self.onTableGameStart, PluginEvent.EV_BEFORE_TABLE_CLEAR_PLAYERS: self.onTableClearPlayers, } elif serverType == gdata.SRV_TYPE_HTTP: handlers = { PluginEvent.EV_HTTP_COMMON_REQUEST: self.onHttpRequest, } handlers.update(common_handlers) return handlers
def __initializePoker(gdatas): ''' 初始化服务的基本(大厅通用)的HTTP和TCP命令入口 ''' if _DEBUG: debug('initializePoker begin') stype = gdata.serverType() # 启动全局配置系统的同步 from poker.entity.configure import synccenter synccenter._initialize() globalEventBus.subscribe(EventHeartBeat, synccenter.doSyncData) from poker.entity.biz import integrate integrate._initialize() # 如果是CONN进程, 那么启动空闲TCP链接的检查 if stype == gdata.SRV_TYPE_CONN: from poker.protocol.conn.protocols import doCleanUpEmptyTcp globalEventBus.subscribe(EventHeartBeat, doCleanUpEmptyTcp) # 如果是AGENT进程, 那么启用自身的命令处理器 if stype == gdata.SRV_TYPE_AGENT: from poker.protocol.common.protocols import onAgentSelfCommand from freetime.support.tcpagent.protocol import A2SProtocol, A2AProtocol A2SProtocol.onCommand = onAgentSelfCommand A2AProtocol.onCommand = onAgentSelfCommand if gdata.isHttpProcess(): from poker.protocol import runhttp runhttp.addWebRoot(gdata.pathWebroot()) if stype == gdata.SRV_TYPE_UTIL: from poker.entity.dao import datasubscribe datasubscribe._initialize() if _DEBUG: debug('initializePoker end')
def __initMatch(self): # 老框架plugin被PluginCenter reload后XXPlugin类的id会发生变化,为了避免此问题,新框架里matchPlugin不再注册到PluginCenter self.matchPlugin = gdata.games()[self.gameId].getMttMatchPlugin() lastMatchStartTimeStamp = self.matchPlugin.getMatchStartTime(self.bigRoomId) self.matchPlugin.refreshMatchInfo(self.roomDefine) self.configChanged = False self.__initRedisLua() self.matchCounter = {} self.ranking = Ranking(self, 0) self.state = self.MTT_STATE_IDLE serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: nowTimeStamp = int(time.time()) if lastMatchStartTimeStamp and nowTimeStamp + self.matchPlugin.timedeltaEnterMatch >= lastMatchStartTimeStamp: # 重启后房间对象数据会被清空,重启前已经进入比赛房间的玩家需要退票; self.matchPlugin.cancelMatch(self, isRestart=True) else: # 报名信息在redis中,重启不会丢失; self.state = self.MTT_STATE_READY self.doHeartBeat()
def _initialize(): return # 当前没有做数据缓存,无需数据变化通知 if gdata.serverType() != gdata.SRV_TYPE_UTIL: return channelcount = 16 channels = [] usids = gdata.serverTypeMap()[gdata.SRV_TYPE_UTIL] usids.sort() if len(usids) < channelcount: if usids[0] == gdata.serverId(): for x in xrange(channelcount): channels.append('userdatachange_%d' % (x)) else: if gdata.serverId() in usids: i = usids.index(gdata.serverId()) if i < channelcount: channels.append('userdatachange_%d' % (i)) if channels: conf = config.redis_config_map.get('mix') ip, port = conf[0], conf[1] subscribe.startSubScriber(ip, port, channels, _onSubMessage)
def initGame(self): from hall.entity import hallaccount self._account = hallaccount # 大厅的账户处理类 serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_CENTER: centers = gdata.serverTypeMap().get(gdata.SRV_TYPE_CENTER, [])[:] centers.sort() sid = gdata.serverId() inits = gdata.centerServerLogics().get(sid, []) # 轮盘开奖信息的监听 from hall.servers.center.rpc.roulette_remote import sendReward globalEventBus.subscribe(EventHeartBeat, sendReward) if inits: for pkg in inits: ftlog.info('init center logic of ->', pkg) exec 'from %s import _initialize; _initialize(1)' % (pkg) if serverType == gdata.SRV_TYPE_UTIL: from hall.servers.util.account_handler import updateOnLineInfos globalEventBus.subscribe(EventHeartBeat, updateOnLineInfos) # 在线信息初始化, ONLIE处理必须在UTIL服务 from hall.entity import hallonline hallonline._initialize() if serverType == gdata.SRV_TYPE_TABLE or serverType == gdata.SRV_TYPE_ROOM: from hall.servers.room.room import reportRoomOnlineInfos globalEventBus.subscribe(EventHeartBeat, reportRoomOnlineInfos) from hall.entity import hallchatlog hallchatlog._initialize() # 注意: 各个模块间有先后初始化的顺序 from hall.entity import hallitem, hallstore, hallvip, hallbenefits, \ hallranking, hallshare, hallpromote, hallfree, hallgamelist, hallgamelist2, \ halldailycheckin, hallmenulist, hallcoupon, hallmoduletip, \ hallrename, hallads, hallflipcardluck, hallpopwnd, hallstartchip, \ fivestarrate, match360kp, neituiguang, hallstocklimit, \ hall_first_recharge, hallroulette, hallled, hall_exit_remind from hall.entity.hallactivity import activity from hall.entity.halltmpact import tmp_activity from hall.entity.hall_red_envelope import hall_red_envelope # 道具初始化 hallitem._initialize() # 限购初始化 hallstocklimit._initialize() # 商城初始化 hallstore._initialize() # VIP系统初始化 hallvip._initialize() # 救济金系统初始化 hallbenefits._initialize() # 用户初始基金初始化 hallstartchip._initialize() halldailycheckin._initialize() # 排行榜 hallranking._initialize(0) # 活动系统初始化 activity._initialize() hallcoupon._initialize() hallshare._initialize() hallgamelist._initialize() hallgamelist2._initialize() hallmenulist._initialize() hallrename._initialize() hallmoduletip._initialize() hallads._initialize() hallflipcardluck._initialize() hallpopwnd._initialize() hallpromote._initialize() hallfree._initialize() fivestarrate._initialize() match360kp._initialize() neituiguang._initialize() from hall.entity import halltask halltask.initialize() # 默认配置初始化 hallmoduledefault._initialize() halllocalnotification._initialize() # 首冲礼包配置 hall_first_recharge._initialize() tmp_activity._initialize() # 红包模块配置初始化 hall_red_envelope._initialize() # 钻石抽奖初始化 hallroulette._initialize() # led配置初始化 hallled._initializeConfig() # 退出提醒 hall_exit_remind._initialize() # 三方控制模块开关 hall_third_sdk_switch._initialize() # 域名配置初始化 halldomains._initialize() # 插件升级模块初始化 hall_game_update._initialize() # 登录奖励模块初始化 hall_login_reward._initialize() # 道具转换模块初始化 hall_item_exchange._initialize() # 自建桌房间号初始化 hall_friend_table._initialize() # 小推广系统初始化 from hall.entity import hall_simple_invite hall_simple_invite.initialize() # 房卡购买提示信息模块初始化 from hall.entity import hall_fangka_buy_info hall_fangka_buy_info._initialize()
def _initialize(): """初始化100万个自建桌房号""" if gdata.serverType() != gdata.SRV_TYPE_CENTER: return ftlog.debug('hall_friend_table._initialize check friend table randoms in process CT') randomLen = daobase.executeMixCmd('LLEN', FRIEND_TABLE_RANDOM_KEY) ftlog.debug('hall_friend_table._initialize randomLen:', randomLen) if randomLen != FRIEND_TABLE_RANDOM_COUNT: ftlog.debug('hall_friend_table._initialize push random begin:', pktimestamp.getCurrentTimestamp()) daobase.executeMixCmd('DEL', FRIEND_TABLE_RANDOM_KEY) rList = [x for x in range(0, 1000000)] random.shuffle(rList) # 每次PUSH 100个 for index in range(0, 10000): begin = index * 100 daobase.executeMixCmd('LPUSH', FRIEND_TABLE_RANDOM_KEY , rList[begin], rList[begin + 1], rList[begin + 2], rList[begin + 3], rList[begin + 4] , rList[begin + 5], rList[begin + 6], rList[begin + 7], rList[begin + 8], rList[begin + 9] , rList[begin + 10], rList[begin + 11], rList[begin + 12], rList[begin + 13], rList[begin + 14] , rList[begin + 15], rList[begin + 16], rList[begin + 17], rList[begin + 18], rList[begin + 19] , rList[begin + 20], rList[begin + 21], rList[begin + 22], rList[begin + 23], rList[begin + 24] , rList[begin + 25], rList[begin + 26], rList[begin + 27], rList[begin + 28], rList[begin + 29] , rList[begin + 30], rList[begin + 31], rList[begin + 32], rList[begin + 33], rList[begin + 34] , rList[begin + 35], rList[begin + 36], rList[begin + 37], rList[begin + 38], rList[begin + 39] , rList[begin + 40], rList[begin + 41], rList[begin + 42], rList[begin + 43], rList[begin + 44] , rList[begin + 45], rList[begin + 46], rList[begin + 47], rList[begin + 48], rList[begin + 49] , rList[begin + 50], rList[begin + 51], rList[begin + 52], rList[begin + 53], rList[begin + 54] , rList[begin + 55], rList[begin + 56], rList[begin + 57], rList[begin + 58], rList[begin + 59] , rList[begin + 60], rList[begin + 61], rList[begin + 62], rList[begin + 63], rList[begin + 64] , rList[begin + 65], rList[begin + 66], rList[begin + 67], rList[begin + 68], rList[begin + 69] , rList[begin + 70], rList[begin + 71], rList[begin + 72], rList[begin + 73], rList[begin + 74] , rList[begin + 75], rList[begin + 76], rList[begin + 77], rList[begin + 78], rList[begin + 79] , rList[begin + 80], rList[begin + 81], rList[begin + 82], rList[begin + 83], rList[begin + 84] , rList[begin + 85], rList[begin + 86], rList[begin + 87], rList[begin + 88], rList[begin + 89] , rList[begin + 90], rList[begin + 91], rList[begin + 92], rList[begin + 93], rList[begin + 94] , rList[begin + 95], rList[begin + 96], rList[begin + 97], rList[begin + 98], rList[begin + 99] ) ftlog.debug('hall_friend_table._initialize push random end:', pktimestamp.getCurrentTimestamp())
def __init__(self, roomDefine): super(TYDTGRoom, self).__init__(roomDefine) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self._initScheduler() self._roomUsers = set()
def __init__(self, roomdefine): super(TYHundredsRoom, self).__init__(roomdefine) serverType = gdata.serverType() if serverType == gdata.SRV_TYPE_ROOM: self.initData()
def initialize(): """ 扑克大厅系统的初始化入口 当所有的REDIS和MYSQL链接建立完成后调用此方法 """ try: if _DEBUG: debug('==== poker.initialize begin ====') sconf = ftcon.getServerConf(ftsvr.getId()) taskc = sconf.get('task-concurrent', 0) if taskc > 0: FTTasklet.MAX_CONCURRENT = taskc if _DEBUG: debug('reset FTTasklet.MAX_CONCURRENT=', FTTasklet.MAX_CONCURRENT) from poker.entity.dao import daobase daobase._REDIS_CMD_PPS_ = 1 configure._CONFIG_CMD_PPS_ = 1 protocol._COUNT_PPS = 1 performance.regPPSCounter(protocol.ppsCountProtocolPack) performance.regPPSCounter(configure.ppsCountConfigCmds) performance.regPPSCounter(daobase.ppsCountRedisCmd) performance.regPPSCounter(performance.threadInfo) # 初始化基本全局配置数据 updateStatus(10) gdatas = gdata._initialize() from poker.entity.biz import bireport bireport.report('bireport', 'open') # 初始化DAO updateStatus(20) daobase._initialize() # 初始化旧命令对照表 updateStatus(30) from poker.protocol import oldcmd oldcmd._initialize() # 装载游戏的PLUGIN updateStatus(40) tygamelist = __loadTYGames(gdatas) # 初始化命令路由 updateStatus(50) from poker.protocol import router router._initialize() if gdata.serverType() == gdata.SRV_TYPE_UTIL: router._initialize_udp() # 初始化房间配置 updateStatus(60) __loadRoomDefines(gdatas) # 各个游戏PLUGIN的命令入口初始化 updateStatus(70) from poker.protocol import handler handler._initializeCommands(gdatas) from poker.protocol import rpccore rpccore._initializeRpcMehodss(gdatas) if gdata.serverType() not in (gdata.SRV_TYPE_AGENT, gdata.SRV_TYPE_CONN): # 所有游戏PLUGIN进行初始化 updateStatus(80) for tygame in tygamelist: if _DEBUG: debug('call init function : ', tygame.gameId(), 'tygame.initGameBefore()') tygame.initGameBefore() # 所有游戏PLUGIN进行初始化 updateStatus(90) for tygame in tygamelist: if _DEBUG: debug('call init function : ', tygame.gameId(), 'tygame.initGame()') tygame.initGame() # 房间实例初始化 updateStatus(100) __initializeRooms(gdatas) # 桌子示例初始化 updateStatus(110) __initializeTables(gdatas) # 所有游戏PLUGIN进行初始化 updateStatus(120) for tygame in tygamelist: if _DEBUG: debug('call init function : ', tygame.gameId(), 'tygame.initGameAfter()') tygame.initGameAfter() # 大厅全局命令入口初始化 updateStatus(130) __initializePoker(gdatas) # 设置初始化完成标记 updateStatus(200) gdatas['initialize.ok'] = 1 if _DEBUG: debug('==== poker.initialize done ====') ide_print("==== poker.initialize done ====") # 启动服务系统心跳处理事件 FTTimer(1, __doServertHeartBeat) except: updateStatus(500) ftlog.error('poker.initialize ERROR') ftsvr.terminate()