Program.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5. using CommandLine;
  6. using NLog;
  7. namespace ET
  8. {
  9. internal static class Program
  10. {
  11. private static void Main(string[] args)
  12. {
  13. // 异步方法全部会回掉到主线程
  14. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  15. try
  16. {
  17. Game.EventSystem.Add(typeof(Game).Assembly);
  18. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  19. ProtobufHelper.Init();
  20. MongoHelper.Init();
  21. // 命令行参数
  22. Options options = null;
  23. Parser.Default.ParseArguments<Options>(args)
  24. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  25. .WithParsed(o => { options = o; });
  26. Game.Options = options;
  27. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}";
  28. Log.Info($"server start........................ {Game.Scene.Id}");
  29. Game.EventSystem.Publish(new EventType.AppStart());
  30. while (true)
  31. {
  32. try
  33. {
  34. Thread.Sleep(1);
  35. ThreadSynchronizationContext.Instance.Update();
  36. Game.EventSystem.Update();
  37. }
  38. catch (Exception e)
  39. {
  40. Log.Error(e);
  41. }
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Error(e);
  47. }
  48. }
  49. }
  50. }