SceneFactory.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, NetworkProtocol>(
  19. startSceneConfig.InnerIPOutPort,
  20. startSceneConfig.StartProcessConfig.InnerIP,
  21. NetworkProtocol.TCP
  22. );
  23. break;
  24. case SceneType.RouterManager: // 正式发布请用CDN代替RouterManager
  25. // 云服务器在防火墙那里做端口映射
  26. scene.AddComponent<HttpComponent, string>($"http://+:{startSceneConfig.OuterPort}/");
  27. break;
  28. case SceneType.Realm:
  29. scene.AddComponent<NetServerComponent, IPEndPoint, NetworkProtocol>(startSceneConfig.InnerIPOutPort, NetworkProtocol.KCP);
  30. scene.AddComponent<UserSessionComponent>();
  31. break;
  32. case SceneType.Game:
  33. ConstGame.GameServerId = startSceneConfig.Id;
  34. ConstGame.GameServerUUID = System.Guid.NewGuid().ToString();
  35. scene.AddComponent<NetServerComponent, IPEndPoint, NetworkProtocol>(startSceneConfig.InnerIPOutPort, NetworkProtocol.KCP);
  36. scene.AddComponent<GameTokenInfoComponent>();
  37. scene.AddComponent<GamePlayerComponent>();
  38. scene.AddComponent<GameMapComponent>();
  39. // 战斗服的Ice会话组件
  40. scene.AddComponent<BattleIceAgentComponent>();
  41. scene.AddComponent<ObjectWait>();
  42. break;
  43. case SceneType.Location:
  44. scene.AddComponent<LocationComponent>();
  45. break;
  46. case SceneType.Robot:
  47. scene.AddComponent<RobotManagerComponent>();
  48. break;
  49. case SceneType.BenchmarkServer:
  50. scene.AddComponent<BenchmarkServerComponent>();
  51. scene.AddComponent<NetServerComponent, IPEndPoint, NetworkProtocol>(startSceneConfig.InnerIPOutPort, NetworkProtocol.KCP);
  52. break;
  53. case SceneType.BenchmarkClient:
  54. scene.AddComponent<BenchmarkClientComponent>();
  55. break;
  56. }
  57. return scene;
  58. }
  59. }
  60. }