using System.Net; using System.Net.Sockets; namespace ET.Server { public static class SceneFactory { public static async ETTask CreateServerScene(Entity parent, long id, long instanceId, int zone, string name, SceneType sceneType, StartSceneConfig startSceneConfig = null) { await ETTask.CompletedTask; Scene scene = EntitySceneFactory.CreateScene(id, instanceId, zone, sceneType, name, parent); scene.AddComponent(MailboxType.UnOrderMessageDispatcher); switch (scene.SceneType) { case SceneType.Router: // 云服务器中,一般来说router要单独部署,不过大家经常放在一起,那么下面要修改 // startSceneConfig.OuterIPPort改成startSceneConfig.InnerIPOutPort // 然后云服务器防火墙把端口映射过来 scene.AddComponent( startSceneConfig.InnerIPOutPort, startSceneConfig.StartProcessConfig.InnerIP, NetworkProtocol.TCP ); break; case SceneType.RouterManager: // 正式发布请用CDN代替RouterManager // 云服务器在防火墙那里做端口映射 scene.AddComponent($"http://+:{startSceneConfig.OuterPort}/"); break; case SceneType.Realm: scene.AddComponent(startSceneConfig.InnerIPOutPort, NetworkProtocol.KCP); scene.AddComponent(); break; case SceneType.Game: ConstGame.GameServerId = startSceneConfig.Id; ConstGame.GameServerUUID = System.Guid.NewGuid().ToString(); scene.AddComponent(startSceneConfig.InnerIPOutPort, NetworkProtocol.KCP); scene.AddComponent(); scene.AddComponent(); scene.AddComponent(); // 战斗服的Ice会话组件 scene.AddComponent(); scene.AddComponent(); // 抖音AccessToken组件 if (Options.Instance.InitAccessToken == 1) { scene.AddComponent(); } break; case SceneType.Location: scene.AddComponent(); break; case SceneType.Robot: scene.AddComponent(); break; case SceneType.BenchmarkServer: scene.AddComponent(); scene.AddComponent(startSceneConfig.InnerIPOutPort, NetworkProtocol.KCP); break; case SceneType.BenchmarkClient: scene.AddComponent(); break; } return scene; } } }