SceneFactory.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // 云服务器中,一般来说router要单独部署,不过大家经常放在一起,那么下面要修改
  16. // startSceneConfig.OuterIPPort改成startSceneConfig.InnerIPOutPort
  17. // 然后云服务器防火墙把端口映射过来
  18. scene.AddComponent<RouterComponent, IPEndPoint, string>(startSceneConfig.InnerIPOutPort,
  19. startSceneConfig.StartProcessConfig.InnerIP
  20. );
  21. break;
  22. case SceneType.RouterManager: // 正式发布请用CDN代替RouterManager
  23. // 云服务器在防火墙那里做端口映射
  24. scene.AddComponent<HttpComponent, string>($"http://+:{startSceneConfig.OuterPort}/");
  25. break;
  26. case SceneType.Realm:
  27. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
  28. break;
  29. case SceneType.Game:
  30. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
  31. scene.AddComponent<PlayerComponent>();
  32. scene.AddComponent<GameSessionKeyComponent>();
  33. break;
  34. case SceneType.Map:
  35. scene.AddComponent<UnitComponent>();
  36. scene.AddComponent<AOIManagerComponent>();
  37. break;
  38. case SceneType.Location:
  39. scene.AddComponent<LocationComponent>();
  40. break;
  41. case SceneType.Robot:
  42. scene.AddComponent<RobotManagerComponent>();
  43. break;
  44. case SceneType.BenchmarkServer:
  45. scene.AddComponent<BenchmarkServerComponent>();
  46. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
  47. break;
  48. case SceneType.BenchmarkClient:
  49. scene.AddComponent<BenchmarkClientComponent>();
  50. break;
  51. }
  52. return scene;
  53. }
  54. }
  55. }