Пример #1
0
def getTreasureBoxDescInfo(gameId, roomPath=''):
    '''
    获取循环任务的奖励描述配置
    '''
    if not roomPath:
        return None
    infos = tyconfig.getCacheGame0Data(roomPath, gameId, None, None, {})
    return infos.get('desc', '')
Пример #2
0
def getTreasureBoxDoubleInfo(gameId, roomPath=''):
    '''
    获取循环任务的翻倍活动配置
    '''
    if not roomPath:
        return None
    infos = tyconfig.getCacheGame0Data(roomPath, gameId, None, None, {})
    return infos.get('double', {})
Пример #3
0
def getTreasureBoxRoomInfo(gameId, bigRoomId, roomPath=''):
    '''
    获取对应房间的循环任务配置
    '''
    if not roomPath:
        return None
    infos = tyconfig.getCacheGame0Data(roomPath, gameId, None, None, {})
    rooms = infos.get('rooms', {})
    return rooms.get(str(bigRoomId), None)
Пример #4
0
    def unload(cls, gameId, handler_names=None):
        """卸载插件"""

        for name in handler_names:
            plugin = cls.get_plugin(name, gameId)
            if hasattr(plugin.module, "onUnload"):
                try:
                    plugin.module.onUnload(gameId)
                except Exception:
                    ftlog.error("TYPluginCenter.unload"
                                "|gameId, name:", gameId, name)
            del cls.plugins[gameId][name]

        handlers_config = tyconfig.getCacheGame0Data(gameId, 'plugins', None,
                                                     None, {})
        cls.buildEventMap(gameId, cls.plugins[gameId], handlers_config,
                          cls.map_events[gameId])
Пример #5
0
    def reload(cls,
               gameId,
               handler_name='',
               handler_names=[],
               handlers_config=None):
        '''
        reload 某个 gameId 的插件

        @handlers_names: 指定要reload哪些plugin。不指定就reload所有(plugins越来越多,会比较慢)

        不管有没有指定 reload 哪些插件,都会重新 build 事件表。
        为什么不优化为只处理指定的plugins的事件?
        没有必要,性能瓶颈不在这,而且全部重新build一定不会出问题,而且的而且,那样做会增加复杂性。
        '''

        if not cls.needLoadPlugin():
            ftlog.info('reload >> |this type of server not need load plugin',
                       '|serverId, gameId:',
                       tyglobal.serverId(),
                       gameId,
                       caller=cls)
            return

        if cls.isOtherGameServer(gameId):
            ftlog.info('reload >> |',
                       'do not reload in other game GR/GT',
                       '|serverId, gameId:',
                       tyglobal.serverId(),
                       gameId,
                       caller=cls)
            return

        if not handlers_config:
            handlers_config = tyconfig.getCacheGame0Data(
                gameId, 'plugins', None, None, {})
            if not handlers_config:
                return
                # handlers_config = dict([(hc['name'], hc) for hc in handlers_config])
        handlers_config_dict = dict([(hc['name'], hc)
                                     for hc in handlers_config['handlers']])
        ftlog.info('<< |', cls.plugins, handlers_config, caller=cls)

        if handler_name:
            handler_names = [handler_name]

        handlers_config_list = []  # to be reload
        cls.map_events[gameId] = {}  # 事件表
        if handler_names:
            for handler_name in handler_names:
                if handler_name in handlers_config_dict:
                    handlers_config_list.append(
                        handlers_config_dict.get(handler_name))
                if handler_name in cls.plugins[gameId]:
                    del cls.plugins[gameId][handler_name]
        else:
            handlers_config_list = handlers_config['handlers']
            cls.plugins[gameId] = {}  # plugins 表

        # 先 reload modules
        plugins = cls.plugins[gameId]
        reloadPlugins = []
        for cfg in handlers_config_list:
            try:
                plugin = TYPlugin(gameId, cfg)
                if plugin.handlers:
                    plugins[cfg['name']] = plugin
                    reloadPlugins.append(plugin)
            except Exception as e:
                ftlog.exception(e)

        cls.buildEventMap(gameId, plugins, handlers_config,
                          cls.map_events[gameId])

        ftlog.info("TYPluginCenter.reload | "
                   "reloadPlugins:", [plugin.name for plugin in reloadPlugins])

        # onReload 时可能会有阻塞操作而让出CPU, 这时有可能会产生新的事件
        # 如果在 onReload 后才 buildEventMap,则这个事件会丢(因为eventMap在build之前是空的)
        # 所以,把 onReload 移到 build Event Map 之后
        for plugin in reloadPlugins:
            try:
                plugin.onReload()
            except Exception as e:
                ftlog.exception(e)
Пример #6
0
def get_room_other_config(gameId):
    """获取房间相关的其他配置"""
    datas = tyconfig.getCacheGame0Data('room_other', gameId, None, None, {})
    return copy.deepcopy(datas)
Пример #7
0
def getTableRecordConfig():
    return tyconfig.getCacheGame0Data('table_record', tyglobal.gameId(), None, None, {})
Пример #8
0
def getMajiangConf(gameId, mainKey, subKey, defaultRet=None):
    datas = tyconfig.getCacheGame0Data(mainKey, gameId, None, None, {})
    return datas.get(subKey, defaultRet)