Program.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Threading;
  3. using CommandLine;
  4. using NLog;
  5. namespace ET
  6. {
  7. internal static class Program
  8. {
  9. private static int Main(string[] args)
  10. {
  11. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  12. {
  13. Log.Error(e.ExceptionObject.ToString());
  14. };
  15. ETTask.ExceptionHandler += Log.Error;
  16. // 异步方法全部会回掉到主线程
  17. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  18. try
  19. {
  20. Game.EventSystem.Add(typeof(Game).Assembly);
  21. ProtobufHelper.Init();
  22. MongoHelper.Register(Game.EventSystem.GetTypes());
  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.Info($"server start........................ {Game.Scene.Id}");
  32. switch (Game.Options.AppType)
  33. {
  34. case AppType.ExcelExporter:
  35. {
  36. Game.Options.Console = 1;
  37. ExcelExporter.Export();
  38. return 0;
  39. }
  40. case AppType.Proto2CS:
  41. {
  42. Game.Options.Console = 1;
  43. Proto2CS.Export();
  44. return 0;
  45. }
  46. }
  47. }
  48. catch (Exception e)
  49. {
  50. Log.Console(e.ToString());
  51. }
  52. return 1;
  53. }
  54. }
  55. }