Program.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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("Model", typeof(Game).Assembly);
  16. Object.ObjectManager.Register("Controller", DllHelper.GetController());
  17. StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string[]>(args).MyConfig;
  18. IdGenerater.AppId = startConfig.AppId;
  19. LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString();
  20. LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString();
  21. Log.Info("server start........................");
  22. Game.Scene.AddComponent<EventComponent>();
  23. Game.Scene.AddComponent<TimerComponent>();
  24. InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
  25. Game.Scene.AddComponent<NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port);
  26. Game.Scene.AddComponent<MessageDispatherComponent, AppType>(startConfig.AppType);
  27. // 根据不同的AppType添加不同的组件
  28. OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
  29. switch (startConfig.AppType)
  30. {
  31. case AppType.Manager:
  32. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  33. Game.Scene.AddComponent<AppManagerComponent>();
  34. break;
  35. case AppType.Realm:
  36. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  37. Game.Scene.AddComponent<RealmGateAddressComponent>();
  38. break;
  39. case AppType.Gate:
  40. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  41. Game.Scene.AddComponent<GateSessionKeyComponent>();
  42. break;
  43. case AppType.AllServer:
  44. Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
  45. Game.Scene.AddComponent<AppManagerComponent>();
  46. Game.Scene.AddComponent<RealmGateAddressComponent>();
  47. Game.Scene.AddComponent<GateSessionKeyComponent>();
  48. break;
  49. case AppType.Robot:
  50. Game.Scene.AddComponent<RobotComponent>();
  51. break;
  52. default:
  53. throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
  54. }
  55. while (true)
  56. {
  57. Object.ObjectManager.Update();
  58. }
  59. }
  60. catch (Exception e)
  61. {
  62. Log.Error(e.ToString());
  63. }
  64. }
  65. }
  66. }