SceneFactory.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Net;
  2. using System.Net.Sockets;
  3. namespace ET.Server
  4. {
  5. public static class SceneFactory
  6. {
  7. public static async ETTask<Scene> CreateServerScene(Entity parent, long id, long instanceId, int zone, string name, SceneType sceneType, StartSceneConfig startSceneConfig = null)
  8. {
  9. await ETTask.CompletedTask;
  10. Scene scene = EntitySceneFactory.CreateScene(id, instanceId, zone, sceneType, name, parent);
  11. scene.AddComponent<MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher);
  12. switch (scene.SceneType)
  13. {
  14. case SceneType.Router:
  15. scene.AddComponent<RouterComponent, IPEndPoint, string>(startSceneConfig.OuterIPPort,
  16. startSceneConfig.StartProcessConfig.InnerIP
  17. );
  18. break;
  19. case SceneType.RouterManager: // 正式发布请用CDN代替RouterManager
  20. // 云服务器在防火墙那里做端口映射
  21. scene.AddComponent<HttpComponent, string>($"http://+:{startSceneConfig.OuterPort}/");
  22. break;
  23. case SceneType.Realm:
  24. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
  25. scene.AddComponent<UserSessionComponent>();
  26. break;
  27. case SceneType.Gate:
  28. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
  29. scene.AddComponent<PlayerComponent>();
  30. scene.AddComponent<GateTokenInfoComponent>();
  31. scene.AddComponent<ObjectWait>();
  32. break;
  33. case SceneType.Map:
  34. scene.AddComponent<UnitComponent>();
  35. scene.AddComponent<AOIManagerComponent>();
  36. break;
  37. case SceneType.Location:
  38. scene.AddComponent<LocationComponent>();
  39. break;
  40. case SceneType.Robot:
  41. scene.AddComponent<RobotManagerComponent>();
  42. break;
  43. case SceneType.BenchmarkServer:
  44. scene.AddComponent<BenchmarkServerComponent>();
  45. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
  46. break;
  47. case SceneType.BenchmarkClient:
  48. scene.AddComponent<BenchmarkClientComponent>();
  49. break;
  50. }
  51. return scene;
  52. }
  53. }
  54. }