示例#1
0
文件: Program.cs 项目: zwinter/ET
        private static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Log.Error(e.ExceptionObject.ToString());
            };

            ETTask.ExceptionHandler += Log.Error;

            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);

            try
            {
                Game.EventSystem.Add(typeof(Game).Assembly);

                ProtobufHelper.Init();
                MongoRegister.Init();

                // 命令行参数
                Options options = null;
                Parser.Default.ParseArguments <Options>(args)
                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
                .WithParsed(o => { options = o; });

                Options.Instance = options;

                Log.ILog = new NLogger(Game.Options.AppType.ToString());
                LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";

                Log.Info($"server start........................ {Game.Scene.Id}");

                switch (Game.Options.AppType)
                {
                case AppType.ExcelExporter:
                {
                    Game.Options.Console = 1;
                    ExcelExporter.Export();
                    return(0);
                }

                case AppType.Proto2CS:
                {
                    Game.Options.Console = 1;
                    Proto2CS.Export();
                    return(0);
                }
                }
            }
            catch (Exception e)
            {
                Log.Console(e.ToString());
            }
            return(1);
        }
示例#2
0
        protected override async ETTask Run(EventType.AppStart args)
        {
            switch (Game.Options.AppType)
            {
            case AppType.ExcelExporter:
            {
                Game.Options.Console = 1;
                ExcelExporter.Export();
                return;
            }

            case AppType.Proto2CS:
            {
                Game.Options.Console = 1;
                Proto2CS.Export();
                return;
            }
            }

            Game.Scene.AddComponent <ConfigComponent>();
            await ConfigComponent.Instance.LoadAsync();

            StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Game.Options.Process);

            Game.Scene.AddComponent <TimerComponent>();
            Game.Scene.AddComponent <OpcodeTypeComponent>();
            Game.Scene.AddComponent <MessageDispatcherComponent>();
            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 <NetThreadComponent>();

            switch (Game.Options.AppType)
            {
            case AppType.Server:
            {
                Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);

                var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
                foreach (StartSceneConfig startConfig in processScenes)
                {
                    await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
                                              startConfig.Type, startConfig);
                }

                break;
            }

            case AppType.Watcher:
            {
                StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
                WatcherComponent   watcherComponent   = Game.Scene.AddComponent <WatcherComponent>();
                watcherComponent.Start(Game.Options.CreateScenes);
                Game.Scene.AddComponent <NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
                break;
            }

            case AppType.GameTool:
                break;
            }

            if (Game.Options.Console == 1)
            {
                Game.Scene.AddComponent <ConsoleComponent>();
            }
        }