Init.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using CommandLine;
  5. namespace ET.Server
  6. {
  7. internal static class Init
  8. {
  9. private static int Main(string[] args)
  10. {
  11. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  12. {
  13. Log.Error(e.ExceptionObject.ToString());
  14. };
  15. try
  16. {
  17. // 异步方法全部会回掉到主线程
  18. Game.AddSingleton<MainThreadSynchronizationContext>();
  19. // 命令行参数
  20. Parser.Default.ParseArguments<Options>(args)
  21. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  22. .WithParsed(Game.AddSingleton);
  23. Game.AddSingleton<TimeInfo>();
  24. Game.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
  25. Game.AddSingleton<ObjectPool>();
  26. Game.AddSingleton<IdGenerater>();
  27. Game.AddSingleton<EventSystem>();
  28. Game.AddSingleton<Root>();
  29. ETTask.ExceptionHandler += Log.Error;
  30. Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly);
  31. EventSystem.Instance.Add(types);
  32. MongoRegister.Init();
  33. Log.Info($"server start........................ {Root.Instance.Scene.Id}");
  34. switch (Options.Instance.AppType)
  35. {
  36. case AppType.ExcelExporter:
  37. {
  38. Options.Instance.Console = 1;
  39. ExcelExporter.Export();
  40. return 0;
  41. }
  42. case AppType.Proto2CS:
  43. {
  44. Options.Instance.Console = 1;
  45. Proto2CS.Export();
  46. return 0;
  47. }
  48. }
  49. }
  50. catch (Exception e)
  51. {
  52. Log.Console(e.ToString());
  53. }
  54. return 1;
  55. }
  56. }
  57. }