Program.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using Base;
  3. using Model;
  4. using NLog;
  5. using Object = Base.Object;
  6. namespace App
  7. {
  8. internal static class Program
  9. {
  10. private static void Main(string[] args)
  11. {
  12. try
  13. {
  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. IdGenerater.AppId = startConfig.AppId;
  20. LogManager.Configuration.Variables["appType"] = startConfig.AppType;
  21. LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString();
  22. Log.Info("server start........................");
  23. Game.Scene.AddComponent<EventComponent>();
  24. Game.Scene.AddComponent<TimerComponent>();
  25. InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
  26. Game.Scene.AddComponent<NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port);
  27. Game.Scene.AddComponent<MessageDispatherComponent, string>(startConfig.AppType);
  28. // 根据不同的AppType添加不同的组件
  29. OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
  30. switch (startConfig.AppType)
  31. {
  32. case AppType.Manager:
  33. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  34. Game.Scene.AddComponent<AppManagerComponent>();
  35. break;
  36. case AppType.Realm:
  37. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  38. Game.Scene.AddComponent<RealmGateAddressComponent>();
  39. break;
  40. case AppType.Gate:
  41. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  42. Game.Scene.AddComponent<GateSessionKeyComponent>();
  43. break;
  44. default:
  45. throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
  46. }
  47. while (true)
  48. {
  49. Object.ObjectManager.Update();
  50. }
  51. }
  52. catch (Exception e)
  53. {
  54. Log.Error(e.ToString());
  55. }
  56. }
  57. }
  58. }