Init.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. MongoHelper.Init();
  33. ProtobufHelper.Init();
  34. Log.Info($"server start........................ {Root.Instance.Scene.Id}");
  35. switch (Options.Instance.AppType)
  36. {
  37. case AppType.ExcelExporter:
  38. {
  39. Options.Instance.Console = 1;
  40. ExcelExporter.Export();
  41. return 0;
  42. }
  43. case AppType.Proto2CS:
  44. {
  45. Options.Instance.Console = 1;
  46. Proto2CS.Export();
  47. return 0;
  48. }
  49. }
  50. }
  51. catch (Exception e)
  52. {
  53. Log.Console(e.ToString());
  54. }
  55. return 1;
  56. }
  57. }
  58. }