using System; using System.Diagnostics; using System.IO; using System.Threading; using CommandLine; using NLog; namespace ETModel { internal static class Program { 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(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { Game.Options = o; }); IdGenerater.AppId = Game.Options.Id; // 启动配置 StartConfig allConfig = MongoHelper.FromJson(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(allConfig, startConfig.Id); Log.Info($"server start........................ {Game.Scene.Id}"); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); Game.Scene.AddComponent(); // 发送普通actor消息 Game.Scene.AddComponent(); // 发送location actor消息 Game.Scene.AddComponent(); // 访问location server的组件 Game.Scene.AddComponent(); Game.Scene.AddComponent(); // 数值订阅组件 Game.Scene.AddComponent(); // 控制台组件 Game.Scene.AddComponent(); OuterConfig outerConfig = startConfig.GetComponent(); if (outerConfig != null) { // 外网消息组件 Game.Scene.AddComponent(outerConfig.Address); } InnerConfig innerConfig = startConfig.GetComponent(); if (innerConfig != null) { // 内网消息组件 Game.Scene.AddComponent(innerConfig.Address); } DBConfig dbConfig = startConfig.GetComponent(); if (dbConfig != null) { Game.Scene.AddComponent(dbConfig); } // 先加这里,后面删掉 Game.EventSystem.Run(EventIdType.AfterScenesAdd); while (true) { try { Thread.Sleep(1); OneThreadSynchronizationContext.Instance.Update(); Game.EventSystem.Update(); } catch (Exception e) { Log.Error(e); } } } catch (Exception e) { Log.Error(e); } } } }