//根据StartConfig获取Session public Session GetSession(StartConfig startConfig) { IPEndPoint innerAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint; Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress); return(session); }
public void Awake() { //DBConfig config = StartConfigComponent.Instance.StartConfig.GetComponent<DBConfig>(); //string connectionString = config.ConnectionString; StartConfig dbStartConfig = StartConfigComponent.Instance.DBConfig; CacheConfig cacheConfig = dbStartConfig.GetComponent <CacheConfig>(); if (cacheConfig == null) { redisClient = ConnectionMultiplexer.Connect(connectionString); } else { redisClient = ConnectionMultiplexer.Connect(cacheConfig.ConnectionString); } database = redisClient.GetDatabase(); CollectCacheAttribute(); ClearAllKey(); for (int i = 0; i < taskCount; ++i) { DBTaskQueue taskQueue = ComponentFactory.Create <DBTaskQueue>(); this.tasks.Add(taskQueue); } }
public void Awake(string path, int appId) { Instance = this; this.configDict = new Dictionary <int, StartConfig>(); this.MapConfigs = new List <StartConfig>(); this.GateConfigs = new List <StartConfig>(); this.LobbyConfigs = new List <StartConfig>(); string[] ss = File.ReadAllText(path).Split('\n'); foreach (string s in ss) { string s2 = s.Trim(); if (s2 == "") { continue; } try { StartConfig startConfig = MongoHelper.FromJson <StartConfig>(s2); AddConfig(startConfig); } catch (Exception e) { Log.Error($"config错误: {s2} {e}"); } } this.StartConfig = this.Get(appId); }
public void Awake() { StartConfig startConfig = Game.Scene.GetComponent <StartConfigComponent>().StartConfig; this.appType = startConfig.AppType; this.HttpConfig = startConfig.GetComponent <HttpConfig>(); this.Load(); try { this.listener = new HttpListener(); if (this.HttpConfig.Url == null) { this.HttpConfig.Url = ""; } foreach (string s in this.HttpConfig.Url.Split(';')) { if (s.Trim() == "") { continue; } this.listener.Prefixes.Add(s); } this.listener.Start(); this.Accept(); } catch (HttpListenerException e) { throw new Exception($"http server error: {e.ErrorCode}", e); } }
/// <summary> /// 嘗試連接服務 /// </summary> /// <param name="startConfig"></param> /// <returns></returns> private async ETTask <bool> TryConnectService(StartConfig startConfig) { IPEndPoint instanceAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint; var session = Game.Scene.GetComponent <NetInnerComponent>().Get(instanceAddress); // 嘗試連接5次,每次間隔5秒 for (int i = 0; i < 5; i++) { await Game.Scene.GetComponent <TimerComponent>().WaitForSecondAsync(5f); try { A2S_ConnectService response = (A2S_ConnectService)await session.Call(new S2A_ConnectService()); if (response.Error == ErrorCode.ERR_Success) { return(true); } } catch (Exception) { // 不處理例外 Log.Info($"to try connecting service[{startConfig.AppType}:{startConfig.AppId}] again on count:{i + 1}."); } } return(false); }
public void Awake(string path, int appId) { Instance = this; this.configDict = new Dictionary <int, StartConfig>(); this.MapConfigs = new List <StartConfig>(); this.GateConfigs = new List <StartConfig>(); string[] ss = File.ReadAllText(path).Split('\n'); foreach (string s in ss) { string s2 = s.Trim(); if (s2 == "") { continue; } try { StartConfig startConfig = MongoHelper.FromJson <StartConfig>(s2); this.configDict.Add(startConfig.AppId, startConfig); InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>(); if (innerConfig != null) { this.innerAddressDict.Add(startConfig.AppId, innerConfig.IPEndPoint); } if (startConfig.AppType.Is(AppType.Realm)) { this.RealmConfig = startConfig; } if (startConfig.AppType.Is(AppType.Location)) { this.LocationConfig = startConfig; } if (startConfig.AppType.Is(AppType.DB)) { this.DBConfig = startConfig; } if (startConfig.AppType.Is(AppType.Map)) { this.MapConfigs.Add(startConfig); } if (startConfig.AppType.Is(AppType.Gate)) { this.GateConfigs.Add(startConfig); } } catch (Exception e) { Log.Error($"config错误: {s2} {e}"); } } this.StartConfig = this.Get(appId); }
private void StartProcess(int appId) { OptionComponent optionComponent = Game.Scene.GetComponent <OptionComponent>(); StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>(); string configFile = optionComponent.Options.Config; StartConfig startConfig = startConfigComponent.Get(appId); #if __MonoCS__ const string exe = @"dotnet"; string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}"; #else const string exe = @"dotnet"; string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}"; #endif Log.Info($"{exe} {arguments}"); try { ProcessStartInfo info = new ProcessStartInfo { FileName = exe, Arguments = arguments, CreateNoWindow = true, UseShellExecute = true }; Process process = Process.Start(info); this.processes.Add(startConfig.AppId, process); } catch (Exception e) { Log.Error(e); } }
private void StartProcess(int appId) { OptionComponent optionComponent = Game.Scene.GetComponent <OptionComponent>(); StartConfigComponent startConfigComponent = StartConfigComponent.Instance; string configFile = optionComponent.Options.Config; StartConfig startConfig = startConfigComponent.Get(appId); const string exe = "dotnet"; string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}"; Log.Info($"{exe} {arguments}"); try { bool useShellExecute = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); ProcessStartInfo info = new ProcessStartInfo { FileName = exe, Arguments = arguments, CreateNoWindow = true, UseShellExecute = useShellExecute }; Process process = Process.Start(info); this.processes.Add(startConfig.AppId, process); } catch (Exception e) { Log.Error(e); } }
public void Awake() { StartConfig startConfig = StartConfigComponent.Instance.StartConfig; this.HttpConfig = startConfig.GetComponent <HttpConfig>(); this.Load(); }
public void Awake() { StartConfig startConfig = Game.Scene.GetComponent <StartConfigComponent>().StartConfig; this.appType = startConfig.AppType; this.HttpConfig = startConfig.GetComponent <HttpConfig>(); this.Load(); }
public void Awake() { StartConfig startConfig = StartConfigComponent.Instance.StartConfig; this.appType = startConfig.AppType; this.HttpConfig = startConfig.GetComponent <HttpConfig>(); Log.Info(HttpConfig.Url); this.Load(); }
public void Awake() { StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>(); this.AppId = startConfigComponent.StartConfig.AppId; StartConfig startConfig = startConfigComponent.LocationConfig; this.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint; }
public void Awake() { StartConfig startConfig = StartConfigComponent.Instance.StartConfig; var sConfig = StartConfigComponent.Instance.GetByType(SceneType.Http); this.HttpConfig = sConfig.GetComponent <HttpConfig>(); this.Load(); }
public override void Awake(StartConfigDrawer self, int level) { StartConfig startConfig = self.GetParent <StartConfig>(); foreach (var childStartConfig in startConfig.List) { childStartConfig.AddComponentNoPool <StartConfigDrawer, int>(level + 1); } self.level = level; }
public bool AddConfig(StartConfig startConfig) { if (this.configDict.ContainsKey(startConfig.AppId)) { return(false); } this.configDict.Add(startConfig.AppId, startConfig); return(true); }
public bool AddConfig(StartConfig startConfig) { if (this.configDict.ContainsKey(startConfig.AppId)) { return(false); } this.configDict.Add(startConfig.AppId, startConfig); InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>(); if (innerConfig != null) { this.innerAddressDict.Add(startConfig.AppId, innerConfig.IPEndPoint); } if (startConfig.AppType.Is(AppType.Realm)) { this.RealmConfig = startConfig; } if (startConfig.AppType.Is(AppType.Location)) { this.LocationConfig = startConfig; } if (startConfig.AppType.Is(AppType.DB)) { this.DBConfig = startConfig; } if (startConfig.AppType.Is(AppType.Map)) { this.MapConfigs.Add(startConfig); } if (startConfig.AppType.Is(AppType.Gate)) { this.GateConfigs.Add(startConfig); } if (startConfig.AppType.Is(AppType.Lobby)) { this.LobbyConfigs.Add(startConfig); } if (startConfig.AppType.Is(AppType.Master)) { MasterConfig = startConfig; } return(true); }
public void Awake(string path, int appId) { this.configDict = new Dictionary <int, StartConfig>(); this.MapConfigs = new List <StartConfig>(); this.GateConfigs = new List <StartConfig>(); string[] ss = File.ReadAllText(path).Split("ServerJson"); Log.Info("ConfigCount:" + ss.Length); foreach (string s in ss) { string s2 = s.Trim(); if (s2 == "") { continue; } try { StartConfig startConfig = MongoHelper.FromJson <StartConfig>(s2); this.configDict.Add(startConfig.AppId, startConfig); if (startConfig.AppType.Is(AppType.Realm)) { this.RealmConfig = startConfig; } if (startConfig.AppType.Is(AppType.Location)) { this.LocationConfig = startConfig; } if (startConfig.AppType.Is(AppType.DB)) { this.DBConfig = startConfig; } if (startConfig.AppType.Is(AppType.Map)) { this.MapConfigs.Add(startConfig); } if (startConfig.AppType.Is(AppType.Gate)) { this.GateConfigs.Add(startConfig); } } catch (Exception e) { Log.Error($"config错误: {s2} {e}"); } } this.StartConfig = this.Get(appId); }
public void Awake(StartConfig allConfig, long id) { Instance = this; this.AllConfig = allConfig; this.AllConfig.Parent = this; // 每个进程的配置 foreach (StartConfig s in this.AllConfig.List) { s.SceneInstanceId = (s.Id << IdGenerater.HeadPos) + s.Id; if (s.Id == id) { this.StartConfig = s; } InnerConfig innerConfig = s.GetComponent <InnerConfig>(); if (innerConfig != null) { this.innerAddressDict.Add(s.Id, innerConfig.Address); } // 每个进程里面domain的配置 foreach (StartConfig startConfig in s.List) { startConfig.SceneInstanceId = (startConfig.Parent.Id << IdGenerater.HeadPos) + startConfig.Id; this.configDict.Add(startConfig.Id, startConfig); SceneConfig sceneConfig = startConfig.GetComponent <SceneConfig>(); switch (sceneConfig.SceneType) { case SceneType.Gate: this.Gates.Add(startConfig); break; case SceneType.Map: this.nameDict.Add(sceneConfig.Name, startConfig); break; default: this.typeDict.Add((int)sceneConfig.SceneType, startConfig); break; } } } }
public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); Instance = null; this.configDict.Clear(); this.innerAddressDict.Clear(); this.Gates.Clear(); this.Agents.Clear(); this.typeDict.Clear(); this.nameDict.Clear(); this.StartConfig = null; }
private void StartProcess(int appId) { OptionComponent optionComponent = Game.Scene.GetComponent <OptionComponent>(); StartConfigComponent startConfigComponent = StartConfigComponent.Instance; string configFile = optionComponent.Options.Config; StartConfig startConfig = startConfigComponent.Get(appId); const string exe = "dotnet"; string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}"; Log.Info($"{exe} {arguments}"); try { Process process = ProcessHelper.Run(exe, arguments); this.processes.Add(startConfig.AppId, process); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 向Master註冊服務 /// </summary> /// <returns></returns> public async ETTask RegisterService() { // 延遲5秒再跟Master註冊 await Game.Scene.GetComponent <TimerComponent>().WaitForSecondAsync(5f); var startComponent = Game.Scene.GetComponent <StartConfigComponent>(); IPEndPoint instanceAddress = startComponent.MasterConfig.GetComponent <InnerConfig>().IPEndPoint; var session = Game.Scene.GetComponent <NetInnerComponent>().Get(instanceAddress); M2S_RegisterService m2S_RegisterService = (M2S_RegisterService)await session.Call(new S2M_RegisterService { Component = StartConfig, }); if (m2S_RegisterService.Error != ErrorCode.ERR_Success) { Log.Error($"to register service is failed, error code: {m2S_RegisterService.Error}."); return; } Log.Info($"to register service is successful."); foreach (var v in m2S_RegisterService.Components) { StartConfig startConfig = (StartConfig)v; if (startConfig.AppId == StartConfig.AppId) { continue; } AddConfig(startConfig); bool result = await TryConnectService(startConfig); if (!result) { Log.Error($"to connect service[{startConfig.AppType}:{startConfig.AppId}] is failed"); } else { Log.Info($"to connect service[{startConfig.AppType}:{startConfig.AppId}] is successful"); } } }
private void LoadConfig() { string filePath = this.GetFilePath(); if (!File.Exists(filePath)) { return; } string s2 = ""; try { this.ClearConfig(); startConfig = MongoHelper.FromJson <StartConfig>(File.ReadAllText(filePath)); this.startConfig.AddComponentNoPool <StartConfigDrawer, int>(0); } catch (Exception e) { Log.Error($"加载配置失败! {s2} \n {e}"); } }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); try { Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly); Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly()); MongoHelper.Init(); // 命令行参数 Parser.Default.ParseArguments <Options>(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { Game.Options = o; }); IdGenerater.AppId = Game.Options.Id; // 启动配置 StartConfig allConfig = MongoHelper.FromJson <StartConfig>(File.ReadAllText(Path.Combine("../Config/StartConfig/", Game.Options.Config))); StartConfig startConfig = allConfig.Get(Game.Options.Id); Game.Scene = EntityFactory.CreateScene(0, "Process", SceneType.Process); LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}"; Game.Scene.AddComponent <StartConfigComponent, StartConfig, long>(allConfig, startConfig.Id); Log.Info($"server start........................ {Game.Scene.Id}"); Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatcherComponent>(); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.AddComponent <CoroutineLockComponent>(); // 发送普通actor消息 Game.Scene.AddComponent <ActorMessageSenderComponent>(); // 发送location actor消息 Game.Scene.AddComponent <ActorLocationSenderComponent>(); // 访问location server的组件 Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorMessageDispatcherComponent>(); // 数值订阅组件 Game.Scene.AddComponent <NumericWatcherComponent>(); // 控制台组件 Game.Scene.AddComponent <ConsoleComponent>(); OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>(); if (outerConfig != null) { // 外网消息组件 Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address); } InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>(); if (innerConfig != null) { << << << < HEAD case AppType.Manager: Game.Scene.AddComponent <AppManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address); Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address); break;
public bool OnGUI() { StartConfig startConfig = this.GetParent <StartConfig>(); GUILayout.BeginHorizontal(GUILayout.Height(16)); if (this.level > 0) { string s = ""; for (int i = 1; i < this.level; ++i) { s += $" "; } GUILayout.Label(s, GUILayout.Width(20 * this.level)); } { GUILayout.BeginHorizontal(GUILayout.Width(240), GUILayout.Height(16)); this.isFold = EditorGUILayout.Foldout(isFold, $"子配置数量:{startConfig.List.Count}"); if (GUILayout.Button("添加子配置", GUILayout.Height(16), GUILayout.Width(75))) { StartConfig s = new StartConfig(); startConfig.Add(s); s.AddComponentNoPool <StartConfigDrawer, int>(this.level + 1); for (int i = 0; i < startConfig.List.Count; ++i) { startConfig.List[i].Id = i + 1; } this.isFold = true; return(false); } if (GUILayout.Button("上", GUILayout.Height(16), GUILayout.Width(30))) { StartConfig parentStartConfig = startConfig.GetParent <StartConfig>(); int index = parentStartConfig.List.IndexOf(startConfig); if (index == 0) { return(true); } parentStartConfig.List.Remove(startConfig); parentStartConfig.List.Insert(index - 1, startConfig); for (int i = 0; i < parentStartConfig.List.Count; ++i) { parentStartConfig.List[i].Id = i + 1; } return(false); } if (GUILayout.Button("下", GUILayout.Height(16), GUILayout.Width(30))) { StartConfig parentStartConfig = startConfig.GetParent <StartConfig>(); int index = parentStartConfig.List.IndexOf(startConfig); if (index == parentStartConfig.List.Count - 1) { return(true); } parentStartConfig.List.Remove(startConfig); parentStartConfig.List.Insert(index + 1, startConfig); for (int i = 0; i < parentStartConfig.List.Count; ++i) { parentStartConfig.List[i].Id = i + 1; } return(false); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(50)); GUILayout.Label($"Id: "); startConfig.Id = EditorGUILayout.LongField(startConfig.Id, GUILayout.Width(30)); GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(200)); ProcessConfig processConfig = startConfig.GetComponent <ProcessConfig>(); if (processConfig != null) { GUILayout.Label($" ProcessConfig(", this.style); GUILayout.Label($"服务器IP: "); processConfig.ServerIP = EditorGUILayout.TextField(processConfig.ServerIP, GUILayout.Width(100)); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(200)); SceneConfig sceneConfig = startConfig.GetComponent <SceneConfig>(); if (sceneConfig != null) { GUILayout.Label($" SceneConfig(", this.style); GUILayout.Label($"SceneType: "); sceneConfig.SceneType = (SceneType)EditorGUILayout.EnumPopup(sceneConfig.SceneType, GUILayout.Width(100)); GUILayout.Label($"Name: "); sceneConfig.Name = EditorGUILayout.TextField(sceneConfig.Name, GUILayout.Width(100)); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(150)); InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>(); if (innerConfig != null) { GUILayout.Label($" InnerConfig(", this.style); GUILayout.Label($"内网地址:"); innerConfig.Address = EditorGUILayout.TextField(innerConfig.Address, GUILayout.Width(120)); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(350)); OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>(); if (outerConfig != null) { GUILayout.Label($" OuterConfig(", this.style); GUILayout.Label($"外网地址:"); outerConfig.Address = EditorGUILayout.TextField(outerConfig.Address, GUILayout.Width(120)); GUILayout.Label($"外网地址2:"); outerConfig.Address2 = EditorGUILayout.TextField(outerConfig.Address2, GUILayout.Width(120)); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(50)); CopyConfig copyConfig = startConfig.GetComponent <CopyConfig>(); if (copyConfig != null) { GUILayout.Label($" CopyConfig(", this.style); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(50)); MapConfig mapConfig = startConfig.GetComponent <MapConfig>(); if (mapConfig != null) { GUILayout.Label($" MapConfig(", this.style); GUILayout.Label($"MapType: "); mapConfig.MapType = (MapType)EditorGUILayout.EnumPopup(mapConfig.MapType, GUILayout.Width(100)); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(350)); ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>(); if (clientConfig != null) { GUILayout.Label($" ClientConfig(", this.style); GUILayout.Label($"连接地址:"); clientConfig.Address = EditorGUILayout.TextField(clientConfig.Address, GUILayout.Width(120)); GUILayout.Label($"),", this.style); } DBConfig dbConfig = startConfig.GetComponent <DBConfig>(); if (dbConfig != null) { GUILayout.Label($" DBConfig(", this.style); GUILayout.Label($"连接串:"); dbConfig.ConnectionString = EditorGUILayout.TextField(dbConfig.ConnectionString); GUILayout.Label($"DBName:"); dbConfig.DBName = EditorGUILayout.TextField(dbConfig.DBName); GUILayout.Label($"),", this.style); } GUILayout.EndHorizontal(); } { GUILayout.BeginHorizontal(GUILayout.Width(200), GUILayout.Height(16)); this.st = (StartConfigComponentType)EditorGUILayout.EnumPopup(this.st, GUILayout.Width(100)); if (GUILayout.Button("添加组件", GUILayout.Height(16))) { Assembly assembly = Assembly.GetAssembly(typeof(Game)); Type type = assembly.GetType($"ETModel.{this.st.ToString()}"); startConfig.AddComponent(type); } if (GUILayout.Button("删除组件", GUILayout.Height(16))) { Assembly assembly = Assembly.GetAssembly(typeof(Game)); Type type = assembly.GetType($"ETModel.{this.st.ToString()}"); startConfig.RemoveComponent(type); } if (GUILayout.Button("删除该行配置", GUILayout.Height(16))) { startConfig.GetParent <StartConfig>().Remove(startConfig); return(false); } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); if (this.isFold) { foreach (StartConfig child in startConfig.List) { if (child.GetComponent <StartConfigDrawer>()?.OnGUI() == false) { return(false); } } } return(true); }
private void OnGUI() { { GUILayout.BeginHorizontal(); string[] filesArray = this.files.ToArray(); this.selectedIndex = EditorGUILayout.Popup(this.selectedIndex, filesArray); string lastFile = this.fileName; this.fileName = this.files[this.selectedIndex]; if (this.fileName != lastFile) { this.LoadConfig(); } this.newFileName = EditorGUILayout.TextField("文件名", this.newFileName); if (GUILayout.Button("添加")) { this.ClearConfig(); this.startConfig = new StartConfig(); startConfig.AddComponent <StartConfigDrawer>(); this.fileName = this.newFileName; this.newFileName = ""; File.WriteAllText(this.GetFilePath(), MongoHelper.ToJson(this.startConfig)); this.files = this.GetConfigFiles(); this.selectedIndex = this.files.IndexOf(this.fileName); this.LoadConfig(); } if (GUILayout.Button("复制")) { this.fileName = $"{this.fileName}-copy"; this.Save(); this.files = this.GetConfigFiles(); this.selectedIndex = this.files.IndexOf(this.fileName); this.newFileName = ""; } if (GUILayout.Button("重命名")) { if (this.newFileName == "") { Log.Debug("请输入新名字!"); } else { File.Delete(this.GetFilePath()); this.fileName = this.newFileName; this.Save(); this.files = this.GetConfigFiles(); this.selectedIndex = this.files.IndexOf(this.fileName); this.newFileName = ""; } } if (GUILayout.Button("删除")) { File.Delete(this.GetFilePath()); this.files = this.GetConfigFiles(); this.selectedIndex = 0; this.newFileName = ""; } GUILayout.EndHorizontal(); } scrollPos = GUILayout.BeginScrollView(this.scrollPos, true, true); startConfig.GetComponent <StartConfigDrawer>()?.OnGUI(); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (GUILayout.Button("保存")) { this.Save(); } if (GUILayout.Button("启动")) { string arguments = $"--config={this.fileName}"; ProcessHelper.Run("App.exe", arguments, "../Bin/"); } if (GUILayout.Button("启动数据库")) { ProcessHelper.Run("mongod", @"--dbpath=db", "../Database/bin/"); } GUILayout.EndHorizontal(); }
//public StartConfig DBConfig { get; private set; } //public StartConfig RealmConfig { get; private set; } //public StartConfig LocationConfig { get; private set; } //public List<StartConfig> MapConfigs { get; private set; } //public List<StartConfig> GateConfigs { get; private set; } public void Awake(string path, int appId) { this.configDict = new Dictionary <int, StartConfig>(); //this.MapConfigs = new List<StartConfig>(); //this.GateConfigs = new List<StartConfig>(); try { var strData = File.ReadAllText(path, encoding: System.Text.Encoding.UTF8); JArray jsonArray = JsonConvert.DeserializeObject <JArray>(strData); foreach (JObject jsonData in jsonArray) { StartConfig startConfig = new StartConfig(); startConfig.AppId = jsonData["AppId"].Value <int>(); startConfig.AppType = Enum.Parse <AppType>(jsonData["AppType"].Value <string>(), true); startConfig.ServerIP = jsonData["ServerIP"].Value <string>(); var outerConfig = jsonData["OuterConfig"]?.Value <JObject>(); if (outerConfig != null) { OuterConfig cfg = new OuterConfig(); cfg.Host = outerConfig["Host"].Value <string>(); cfg.Port = outerConfig["Port"].Value <int>(); cfg.BeginInit(); cfg.EndInit(); startConfig.AddComponent(cfg); } var innerConfig = jsonData["InnerConfig"]?.Value <JObject>(); if (innerConfig != null) { InnerConfig cfg = new InnerConfig(); cfg.Host = innerConfig["Host"].Value <string>(); cfg.Port = innerConfig["Port"].Value <int>(); cfg.BeginInit(); cfg.EndInit(); startConfig.AddComponent(cfg); } var locationConfig = jsonData["LocationConfig"]?.Value <JObject>(); if (locationConfig != null) { LocationConfig cfg = new LocationConfig(); cfg.Host = locationConfig["Host"].Value <string>(); cfg.Port = locationConfig["Port"].Value <int>(); cfg.BeginInit(); cfg.EndInit(); startConfig.AddComponent(cfg); } var httpConfig = jsonData["HttpConfig"]?.Value <JObject>(); if (httpConfig != null) { HttpConfig cfg = new HttpConfig(); cfg.Url = httpConfig["Url"].Value <string>(); cfg.AppId = httpConfig["AppId"].Value <int>(); cfg.AppKey = httpConfig["AppKey"].Value <string>(); cfg.ManagerSystemUrl = httpConfig["ManagerSystemUrl"].Value <string>(); cfg.BeginInit(); cfg.EndInit(); startConfig.AddComponent(cfg); } var dbConfig = jsonData["DBConfig"]?.Value <JObject>(); if (dbConfig != null) { DBConfig cfg = new DBConfig(); cfg.ConnectionString = dbConfig["ConnectionString"].Value <string>(); cfg.DBName = dbConfig["DBName"].Value <string>(); cfg.BeginInit(); cfg.EndInit(); startConfig.AddComponent(cfg); } var clientConfig = jsonData["ClientConfig"]?.Value <JObject>(); if (clientConfig != null) { ClientConfig cfg = new ClientConfig(); cfg.Host = clientConfig["Host"].Value <string>(); cfg.Port = clientConfig["Port"].Value <int>(); cfg.BeginInit(); cfg.EndInit(); startConfig.AddComponent(cfg); } startConfig.BeginInit(); startConfig.EndInit(); this.configDict.Add(startConfig.AppId, startConfig); } } catch (Exception e) { Log.Error($"config错误: {path} {e}"); } this.StartConfig = this.Get(appId); }
public static void Awake(this DBProxyComponent self) { StartConfig dbStartConfig = StartConfigComponent.Instance.DBConfig; self.dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint; }
public void Add(StartConfig startConfig) { startConfig.parent = this; this.List.Add(startConfig); }
public void Remove(StartConfig startConfig) { this.List.Remove(startConfig); }
public void Awake() { StartConfig dbStartConfig = Game.Scene.GetComponent <StartConfigComponent>().DBConfig; dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint; }