Entry.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. StartAsync().Coroutine();
  13. }
  14. private static async ETTask StartAsync()
  15. {
  16. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  17. {
  18. Log.Error(e.ExceptionObject.ToString());
  19. };
  20. ETTask.ExceptionHandler += Log.Error;
  21. // 异步方法全部会回掉到主线程
  22. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  23. CodeLoader.Instance.LoadHotfix();
  24. MongoHelper.Register(Game.EventSystem.GetTypes());
  25. string[] args = System.Environment.GetCommandLineArgs();
  26. // 命令行参数
  27. Options options = null;
  28. Parser.Default.ParseArguments<Options>(args)
  29. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  30. .WithParsed(o => { options = o; });
  31. Options.Instance = options;
  32. Game.ILog = new NLogger(Game.Options.AppType.ToString());
  33. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  34. Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
  35. await Game.EventSystem.Callback<ETTask>(CallbackType.InitShare);
  36. await Game.EventSystem.Callback<ETTask>(CallbackType.InitServer);
  37. }
  38. }
  39. }