public static bool LoadConfig() { lock (Mutex) { try { LoadConfigSuccess = true; int v; string str; #region 务器相关配置 ConfigurationManager.RefreshSection("appSettings"); ServerListUrl = ConfigurationManager.AppSettings.Get("ServerListUrl"); KuaFuServerListUrl = ConfigurationManager.AppSettings.Get("KuaFuServerListUrl"); GetPlatChargeKingUrl = ConfigurationManager.AppSettings.Get("PlatChargeKingUrl"); ConstData.HTTP_MD5_KEY = ConfigurationManager.AppSettings.Get("MD5Key"); ResourcePath = ConfigurationManager.AppSettings.Get("ResourcePath"); string platformStr = ConfigurationManager.AppSettings.Get("Platform"); for (PlatformTypes i = PlatformTypes.Tmsk; i < PlatformTypes.Max; i++) { if (0 == string.Compare(platformStr, i.ToString(), true)) { platformType = i; break; } } if (platformType == PlatformTypes.Max) { LogManager.WriteLog(LogTypes.Fatal, "必须在配置文件中设置有效的平台类型: Platform"); LoadConfigSuccess = false; return(false); } string kuaFuMapLineStr = ConfigurationManager.AppSettings.Get("KuaFuMapLine"); if (!string.IsNullOrEmpty(kuaFuMapLineStr)) { KuaFuMapLineDict.Clear(); string[] mapLineStrs = kuaFuMapLineStr.Split('|'); foreach (var mapLineStr in mapLineStrs) { KuaFuLineData kuaFuLineData = new KuaFuLineData(); string[] mapLineParams = mapLineStr.Split(','); int line; int serverId; if (mapLineParams.Length == 2 && int.TryParse(mapLineParams[0], out line) && int.TryParse(mapLineParams[1], out serverId)) { KuaFuMapLineDict[line] = serverId; } } } #endregion 务器相关配置 #region 活动相关配置 string fullFileName = GetResourcePath("Config/MapLine.xml", ResourcePathTypes.GameRes); XElement xmlFile = ConfigHelper.Load(fullFileName); str = ConfigHelper.GetElementAttributeValue(xmlFile, "add", "key", "LoadConfigFromServer", "value", "true"); if (!bool.TryParse(str, out LoadConfigFromServer)) { LoadConfigFromServer = false; } WritePerformanceLogMs = (int)ConfigHelper.GetElementAttributeValueLong(xmlFile, "add", "key", "WritePerformanceLogMs", "value", 10); LineMap2KuaFuLineDataDict.Clear(); ServerMap2KuaFuLineDataDict.Clear(); KuaFuMapServerIdDict.Clear(); MapCode2KuaFuLineDataDict.Clear(); IEnumerable <XElement> xmls = ConfigHelper.GetXElements(xmlFile, "MapLine"); foreach (var node in xmls) { MapMaxOnlineCount = (int)ConfigHelper.GetElementAttributeValueLong(node, "MaxNum", 500); str = ConfigHelper.GetElementAttributeValue(node, "Line", ""); if (!string.IsNullOrEmpty(str)) { string[] mapLineStrs = str.Split('|'); foreach (var mapLineStr in mapLineStrs) { KuaFuLineData kuaFuLineData = new KuaFuLineData(); string[] mapLineParams = mapLineStr.Split(','); kuaFuLineData.Line = int.Parse(mapLineParams[0]); kuaFuLineData.MapCode = int.Parse(mapLineParams[1]); KuaFuMapLineDict.TryGetValue(kuaFuLineData.Line, out kuaFuLineData.ServerId); kuaFuLineData.MaxOnlineCount = MapMaxOnlineCount; LineMap2KuaFuLineDataDict.TryAdd(new IntPairKey(kuaFuLineData.Line, kuaFuLineData.MapCode), kuaFuLineData); if (kuaFuLineData.ServerId > 0) { if (ServerMap2KuaFuLineDataDict.TryAdd(new IntPairKey(kuaFuLineData.ServerId, kuaFuLineData.MapCode), kuaFuLineData)) { List <KuaFuLineData> list = null; if (!KuaFuMapServerIdDict.TryGetValue(kuaFuLineData.ServerId, out list)) { list = new List <KuaFuLineData>(); KuaFuMapServerIdDict.TryAdd(kuaFuLineData.ServerId, list); } list.Add(kuaFuLineData); if (!MapCode2KuaFuLineDataDict.TryGetValue(kuaFuLineData.MapCode, out list)) { list = new List <KuaFuLineData>(); MapCode2KuaFuLineDataDict.TryAdd(kuaFuLineData.MapCode, list); } list.Add(kuaFuLineData); } } } } } #endregion 活动相关配置 #region 其他配置 HuanYingSiYuanPersistence.Instance.InitConfig(); TianTiPersistence.Instance.InitConfig(); YongZheZhanChangPersistence.Instance.InitConfig(); KuaFuCopyDbMgr.Instance.InitConfig(); SpreadPersistence.Instance.InitConfig(); AllyPersistence.Instance.InitConfig(); #endregion } catch (System.Exception ex) { LogManager.WriteException(ex.ToString()); } } return(LoadConfigSuccess); }
/// <summary> /// 初始化配置 /// </summary> public bool InitConfig() { bool success = true; XElement xml = null; string fileName = ""; string fullPathFileName = ""; IEnumerable <XElement> nodes; lock (RuntimeData.Mutex) { try { int open = 0; string kuaFuUriKeyNamePrefix = null; int serverId = CoreInterface.GetLocalServerId(); PlatformTypes platfromType = CoreInterface.GetPlatformType(); fileName = string.Format("Config/ThroughService_{0}.xml", platfromType.ToString()); fullPathFileName = Global.GameResPath(fileName); //Global.IsolateResPath(fileName); //如果配置文件存在,则读配置文件,否则读默认配置 if (File.Exists(fullPathFileName)) { xml = XElement.Load(fullPathFileName); nodes = xml.Elements(); foreach (var node in nodes) { int startServer = (int)Global.GetSafeAttributeLong(node, "StartServer"); int endServer = (int)Global.GetSafeAttributeLong(node, "EndServer"); if (startServer <= serverId && serverId < endServer) { open = (int)Global.GetSafeAttributeLong(node, "Open"); kuaFuUriKeyNamePrefix = Global.GetSafeAttributeStr(node, "ID"); break; } } } else { open = 1; kuaFuUriKeyNamePrefix = null; } CoreInterface.SetRuntimeVariable(RuntimeVariableNames.KuaFuGongNeng, open.ToString()); CoreInterface.SetRuntimeVariable(RuntimeVariableNames.KuaFuUriKeyNamePrefix, kuaFuUriKeyNamePrefix); string huanYingSiYuanUri = null; string tianTiUri = null; string yongZheZhanChangUri = null; // string moRiJudgeUri = null; // string elementWarUri = null; string kfcopyUri = null; string spreadUri = null; string allyUri = null; if (open > 0) { string huanYingSiYuanUriKeyName = RuntimeVariableNames.HuanYingSiYuanUri + kuaFuUriKeyNamePrefix; huanYingSiYuanUri = CoreInterface.GetGameConfigStr(huanYingSiYuanUriKeyName, null); //如果数据库没配置,则读默认配置文件 if (string.IsNullOrEmpty(huanYingSiYuanUri)) { ConfigurationManager.RefreshSection("appSettings"); huanYingSiYuanUri = ConfigurationManager.AppSettings.Get(huanYingSiYuanUriKeyName); //如果没有指定后缀的配置,则读默认配置 if (string.IsNullOrEmpty(huanYingSiYuanUri)) { huanYingSiYuanUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.HuanYingSiYuanUri); } } string tianTiUriKeyName = RuntimeVariableNames.TianTiUri + kuaFuUriKeyNamePrefix; tianTiUri = CoreInterface.GetGameConfigStr(tianTiUriKeyName, null); //如果数据库没配置,则读默认配置文件 if (string.IsNullOrEmpty(tianTiUri)) { ConfigurationManager.RefreshSection("appSettings"); tianTiUri = ConfigurationManager.AppSettings.Get(tianTiUriKeyName); //如果没有指定后缀的配置,则读默认配置 if (string.IsNullOrEmpty(tianTiUri)) { tianTiUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.TianTiUri); } } string yongZheZhanChangUriKeyName = RuntimeVariableNames.YongZheZhanChangUri + kuaFuUriKeyNamePrefix; yongZheZhanChangUri = CoreInterface.GetGameConfigStr(yongZheZhanChangUriKeyName, null); //如果数据库没配置,则读默认配置文件 if (string.IsNullOrEmpty(yongZheZhanChangUri)) { ConfigurationManager.RefreshSection("appSettings"); yongZheZhanChangUri = ConfigurationManager.AppSettings.Get(yongZheZhanChangUriKeyName); //如果没有指定后缀的配置,则读默认配置 if (string.IsNullOrEmpty(yongZheZhanChangUri)) { yongZheZhanChangUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.YongZheZhanChangUri); } } /* * string moRiJudgeUriKeyName = RuntimeVariableNames.MoRiJudgeUri + kuaFuUriKeyNamePrefix; * moRiJudgeUri = CoreInterface.GetGameConfigStr(moRiJudgeUriKeyName, null); * * //如果数据库没配置,则读默认配置文件 * if (string.IsNullOrEmpty(moRiJudgeUri)) * { * ConfigurationManager.RefreshSection("appSettings"); * moRiJudgeUri = ConfigurationManager.AppSettings.Get(moRiJudgeUriKeyName); * * //如果没有指定后缀的配置,则读默认配置 * if (string.IsNullOrEmpty(moRiJudgeUri)) * { * moRiJudgeUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.MoRiJudgeUri); * } * } * * //元素试炼———————————————————————————————————————— * string elementWarUriKeyName = RuntimeVariableNames.ElementWarUri + kuaFuUriKeyNamePrefix; * elementWarUri = CoreInterface.GetGameConfigStr(elementWarUriKeyName, null); * * //如果数据库没配置,则读默认配置文件 * if (string.IsNullOrEmpty(elementWarUri)) * { * ConfigurationManager.RefreshSection("appSettings"); * elementWarUri = ConfigurationManager.AppSettings.Get(elementWarUriKeyName); * * //如果没有指定后缀的配置,则读默认配置 * if (string.IsNullOrEmpty(elementWarUri)) * { * elementWarUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.ElementWarUri); * } * } * */ string kfcopyUriKeyName = RuntimeVariableNames.KuaFuCopyUri + kuaFuUriKeyNamePrefix; kfcopyUri = CoreInterface.GetGameConfigStr(kfcopyUriKeyName, null); //如果数据库没配置,则读默认配置文件 if (string.IsNullOrEmpty(kfcopyUri)) { ConfigurationManager.RefreshSection("appSettings"); kfcopyUri = ConfigurationManager.AppSettings.Get(kfcopyUriKeyName); //如果没有指定后缀的配置,则读默认配置 if (string.IsNullOrEmpty(kfcopyUri)) { kfcopyUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.KuaFuCopyUri); } } // string SpreadUriKeyName = RuntimeVariableNames.SpreadUri + kuaFuUriKeyNamePrefix; spreadUri = CoreInterface.GetGameConfigStr(SpreadUriKeyName, null); //如果数据库没配置,则读默认配置文件 if (string.IsNullOrEmpty(spreadUri)) { ConfigurationManager.RefreshSection("appSettings"); spreadUri = ConfigurationManager.AppSettings.Get(SpreadUriKeyName); //如果没有指定后缀的配置,则读默认配置 if (string.IsNullOrEmpty(spreadUri)) { spreadUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.SpreadUri); } } string AllyUriKeyName = RuntimeVariableNames.AllyUri + kuaFuUriKeyNamePrefix; allyUri = CoreInterface.GetGameConfigStr(AllyUriKeyName, null); //如果数据库没配置,则读默认配置文件 if (string.IsNullOrEmpty(allyUri)) { ConfigurationManager.RefreshSection("appSettings"); allyUri = ConfigurationManager.AppSettings.Get(AllyUriKeyName); //如果没有指定后缀的配置,则读默认配置 if (string.IsNullOrEmpty(allyUri)) { allyUri = ConfigurationManager.AppSettings.Get(RuntimeVariableNames.AllyUri); } } } CoreInterface.SetRuntimeVariable(RuntimeVariableNames.HuanYingSiYuanUri, huanYingSiYuanUri); CoreInterface.SetRuntimeVariable(RuntimeVariableNames.TianTiUri, tianTiUri); CoreInterface.SetRuntimeVariable(RuntimeVariableNames.YongZheZhanChangUri, yongZheZhanChangUri); //CoreInterface.SetRuntimeVariable(RuntimeVariableNames.ElementWarUri, elementWarUri); //CoreInterface.SetRuntimeVariable(RuntimeVariableNames.MoRiJudgeUri, moRiJudgeUri); CoreInterface.SetRuntimeVariable(RuntimeVariableNames.KuaFuCopyUri, kfcopyUri); CoreInterface.SetRuntimeVariable(RuntimeVariableNames.SpreadUri, spreadUri); CoreInterface.SetRuntimeVariable(RuntimeVariableNames.AllyUri, allyUri); } catch (System.Exception ex) { success = false; LogManager.WriteLog(LogTypes.Fatal, string.Format("加载xml配置文件:{0}, 失败。", fileName), ex); } } return(success); }