| | |
| | | import os
|
| | | import GameWorld
|
| | | import md5
|
| | | import IpyGameDataPY
|
| | | import FormulaControl
|
| | | import ConfigParser
|
| | | import ShareDefine
|
| | |
| | |
|
| | | AllChConfig = {}
|
| | | GeneralProgramme = {}
|
| | | ServersRouteConfig = None
|
| | | ServersConfigDict = {}
|
| | | PyMongoDataServerConfig = None
|
| | | DBAllChConfig = {}
|
| | |
|
| | | # db路径下对应的配置文件路径 {key:path, ...}
|
| | | Def_DBCfgFilePath = {
|
| | | "DBPlatformNum":"\\Config\\DBPlatformNum.txt",
|
| | | }
|
| | |
|
| | | #---------------------------------------------------------------------
|
| | | ## 获取原样的Config此方法仅用于公式 !!!!
|
| | |
| | |
|
| | | return
|
| | |
|
| | | def SetReloadConfig():
|
| | | ## 标记重读配置
|
| | | global PyMongoDataServerConfig
|
| | | global ServersRouteConfig
|
| | | global ServersConfigDict
|
| | | |
| | | GameWorld.Log("=== 设置重读配置 ===")
|
| | | GameWorld.GetGameWorld().SetGameWorldDict(ShareDefine.Def_Notify_WorldKey_ReloadConfig, 1)
|
| | | PyMongoDataServerConfig = None
|
| | | ServersRouteConfig = None
|
| | | ServersConfigDict = {}
|
| | | IpyGameDataPY.IPYData.IpyDataClear()
|
| | | import DataRecordPack
|
| | | DataRecordPack.DR_Reload("config")
|
| | | OnReloadConfig()
|
| | | return
|
| | |
|
| | | def OnReloadConfig():
|
| | | ## 配置文件重读后需要额外处理的逻辑
|
| | | GameWorld.Log("OnReloadConfig...")
|
| | | if GameWorld.IsCrossCenter():
|
| | | import DBFamily
|
| | | DBFamily.OnReloadConfig()
|
| | | return
|
| | |
|
| | | ## 重读,清除配置
|
| | | # @param key 表名
|
| | |
| | | def ClearAllConfig():
|
| | | global AllChConfig
|
| | | global GeneralProgramme
|
| | | global PyMongoDataServerConfig
|
| | | global DBAllChConfig
|
| | |
|
| | | #重读所有的配置表
|
| | | AllChConfig = {}
|
| | | GeneralProgramme = {}
|
| | | FormulaControl.ClearCompileFormulaDist()
|
| | | PyMongoDataServerConfig = None
|
| | | DBAllChConfig = {}
|
| | |
|
| | | GameWorld.Log('MapServer_Reload_ChConfig')
|
| | | #关闭字典
|
| | |
| | |
|
| | | ## -----------------------------------------------------------
|
| | |
|
| | | def GetServersRouteConfig(section, option, raw=False, defaultValue=None, isLog=True):
|
| | | global ServersRouteConfig
|
| | | |
| | | if not ServersRouteConfig:
|
| | | filePath = ChConfig.GetServersRoutePath() + "\\PyMongoDataServer.ini"
|
| | | |
| | | if not os.path.isfile(filePath):
|
| | | GameWorld.Log('无法找到文件 = %s'%(filePath))
|
| | | raise Exception('无法找到文件 = %s'%(filePath))
|
| | | |
| | | ServersRouteConfig = ConfigParser.ConfigParser()
|
| | | ServersRouteConfig.read(filePath)
|
| | | GameWorld.DebugLog("Reload %s" % str(filePath))
|
| | | |
| | | if not ServersRouteConfig.has_option(section, option):
|
| | | if defaultValue != None:
|
| | | return defaultValue
|
| | | if isLog:
|
| | | GameWorld.ErrLog("ServersRoute->PyMongoDataServer.ini找不到配置: section=%s,option=%s" % (section, option))
|
| | | return ""
|
| | | |
| | | strParam = ServersRouteConfig.get(section, option, raw)
|
| | | return strParam
|
| | |
|
| | | def GetServerConfigDict():
|
| | | global ServersConfigDict
|
| | | if not ServersConfigDict:
|
| | | filePath = ChConfig.GetServersRoutePath() + "\\Config\\ServersConfig.json"
|
| | | if not os.path.isfile(filePath):
|
| | | GameWorld.Log('无法找到文件 = %s'%(filePath))
|
| | | raise Exception('无法找到文件 = %s'%(filePath))
|
| | | |
| | | f = open(filePath, 'r')
|
| | | strMsg = f.read()
|
| | | f.close()
|
| | | |
| | | ServersConfigDict = eval(strMsg)
|
| | | |
| | | return ServersConfigDict
|
| | |
|
| | | ## PyMongoDataServer.ini配置读取
|
| | | # @param section: 分段区块名
|
| | | # @param option: 配置项名
|
| | |
| | |
|
| | | strParam = PyMongoDataServerConfig.get(section, option, raw)
|
| | | return strParam
|
| | |
|
| | | def GetDBConfig(key): return __DoLogic_GetDBConfig(key)
|
| | | def GetDBEvalChConfig(key): return __DoLogic_GetDBConfig(key, True)
|
| | |
|
| | | ## 通过key查找策划表,如果还未加载,则进行加载
|
| | | # @param key 表名
|
| | | # @return None
|
| | | # @remarks 函数详细说明.
|
| | | def __DoLogic_GetDBConfig(key, needEval=False):
|
| | | global DBAllChConfig
|
| | | |
| | | #是否重读所有的配置表
|
| | | if GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ReloadConfig):
|
| | | ClearAllConfig()
|
| | | else:
|
| | | #找到了,就返回
|
| | | if DBAllChConfig.has_key(key):
|
| | | return DBAllChConfig[key]
|
| | | |
| | | if key not in Def_DBCfgFilePath:
|
| | | GameWorld.Log('DB配置中未发现Key文件 = %s' % (key))
|
| | | return
|
| | | filePath = ChConfig.GetServerConfigPath() + Def_DBCfgFilePath[key]
|
| | | |
| | | retData = __ReadConfigDataEx(key, filePath, needEval)
|
| | | if not retData:
|
| | | return
|
| | | DBAllChConfig.update({key:retData})
|
| | | return retData
|
| | |
|
| | | def __ReadConfigDataEx(fileName, filePath, needEval):
|
| | | |
| | | if not os.path.isfile(filePath):
|
| | | GameWorld.Log('未发现目标文件 = %s' % (filePath))
|
| | | raise Exception ('未发现目标文件 = %s' % (filePath))
|
| | | |
| | | file = open(filePath, 'r')
|
| | | strMsg = file.read()
|
| | | file.close()
|
| | | |
| | | if needEval:
|
| | | try:
|
| | | result = eval(strMsg)
|
| | | except BaseException, e:
|
| | | GameWorld.Log('获取配置信息Key = %s 读取失败,无法解析原因:%s, 抛出,%s' % (fileName, e, strMsg))
|
| | | raise Exception('获取配置信息Key = %s 读取失败' % fileName)
|
| | | |
| | | return result
|
| | | |
| | | else:
|
| | | #编译后储存
|
| | | return compile(strMsg, 'ReadChConfig', 'eval')
|
| | |
|