SceneFactory.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.OuterIPPort,
  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. scene.AddComponent<UserSessionComponent>();
  29. break;
  30. case SceneType.Game:
  31. ConstGame.GameServerId = startSceneConfig.Id;
  32. ConstGame.GameServerUUID = System.Guid.NewGuid().ToString();
  33. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
  34. scene.AddComponent<GameTokenInfoComponent>();
  35. scene.AddComponent<GamePlayerComponent>();
  36. scene.AddComponent<GameMapComponent>();
  37. //战斗服的Ice会话组件
  38. scene.AddComponent<BattleIceAgentComponent>();
  39. scene.AddComponent<ObjectWait>();
  40. break;
  41. case SceneType.Location:
  42. scene.AddComponent<LocationComponent>();
  43. break;
  44. case SceneType.Robot:
  45. scene.AddComponent<RobotManagerComponent>();
  46. break;
  47. case SceneType.BenchmarkServer:
  48. scene.AddComponent<BenchmarkServerComponent>();
  49. scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
  50. break;
  51. case SceneType.BenchmarkClient:
  52. scene.AddComponent<BenchmarkClientComponent>();
  53. break;
  54. }
  55. return scene;
  56. }
  57. }
  58. }