Entry.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using CommandLine;
  5. using NLog;
  6. namespace ET.Server
  7. {
  8. public static class Entry
  9. {
  10. public static void Start()
  11. {
  12. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  13. {
  14. Log.Error(e.ExceptionObject.ToString());
  15. };
  16. ETTask.ExceptionHandler += Log.Error;
  17. // 异步方法全部会回掉到主线程
  18. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  19. Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof(Game).Assembly, typeof(Entry).Assembly, DllHelper.GetHotfixAssembly());
  20. Game.EventSystem.Add(types);
  21. MongoHelper.Register(Game.EventSystem.GetTypes());
  22. string[] args = System.Environment.GetCommandLineArgs();
  23. // 命令行参数
  24. Options options = null;
  25. Parser.Default.ParseArguments<Options>(args)
  26. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  27. .WithParsed(o => { options = o; });
  28. Options.Instance = options;
  29. Game.ILog = new NLogger(Game.Options.AppType.ToString());
  30. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  31. Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
  32. Game.EventSystem.Publish(Game.Scene, new ET.EventType.AppStart());
  33. }
  34. }
  35. }