Program.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using Base;
  5. using Model;
  6. using Object = Base.Object;
  7. namespace App
  8. {
  9. internal static class Program
  10. {
  11. private static void Main(string[] args)
  12. {
  13. try
  14. {
  15. Log.Info("server start........................");
  16. Object.ObjectManager.Register("Base", typeof(Game).Assembly);
  17. Object.ObjectManager.Register("Model", typeof(ErrorCode).Assembly);
  18. Object.ObjectManager.Register("Controller", DllHelper.GetController());
  19. Options options = Game.Scene.AddComponent<OptionsComponent, string[]>(args).Options;
  20. Game.Scene.AddComponent<EventComponent>();
  21. Game.Scene.AddComponent<TimerComponent>();
  22. Game.Scene.AddComponent<NetworkComponent, NetworkProtocol, string, int>(options.Protocol, options.Host, options.Port);
  23. Game.Scene.AddComponent<MessageDispatherComponent, string>(options.AppType);
  24. // 根据不同的AppType添加不同的组件
  25. switch (options.AppType)
  26. {
  27. case AppType.Manager:
  28. Game.Scene.AddComponent<AppManagerComponent>();
  29. break;
  30. case AppType.Realm:
  31. Game.Scene.AddComponent<RealmGateAddressComponent>();
  32. break;
  33. case AppType.Gate:
  34. Game.Scene.AddComponent<GateSessionKeyComponent>();
  35. break;
  36. default:
  37. throw new Exception($"命令行参数没有设置正确的AppType: {options.AppType}");
  38. }
  39. while (true)
  40. {
  41. Object.ObjectManager.Update();
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Error(e.ToString());
  47. }
  48. }
  49. }
  50. }