Program.cs 1.9 KB

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