public void PublicPortMatchesContainerPort() { _vmConfiguration = new VmConfiguration(56001, TestVmId, new VmDirectories(_root), true); _sessionHostManager.Setup(x => x.LinuxContainersOnWindows).Returns(true); VmPathHelper.AdaptFolderPathsForLinuxContainersOnWindows(_vmConfiguration); _sessionHostsStartInfo.SessionHostType = SessionHostType.Container; _sessionHostsStartInfo.PortMappingsList = new List <List <PortMapping> >() { new List <PortMapping>() { new PortMapping() { GamePort = new Port() { Name = "port", Number = 80, Protocol = "TCP" }, PublicPort = 1234, NodePort = 56001 } } }; SessionHostContainerConfiguration sessionHostContainerConfiguration = new SessionHostContainerConfiguration(_vmConfiguration, _logger, _systemOperations, _dockerClient.Object, _sessionHostsStartInfo, shouldPublicPortMatchGamePort: true); IList <PortMapping> result = sessionHostContainerConfiguration.GetPortMappings(0); result[0].PublicPort.Should().Be(_sessionHostsStartInfo.PortMappingsList[0][0].PublicPort); result[0].GamePort.Number.Should().Be(result[0].PublicPort); }
public void TestEnvVariablesWithSessionLinuxContainerOnWindow() { _sessionHostManager.Setup(x => x.LinuxContainersOnWindows).Returns(true); VmPathHelper.AdaptFolderPathsForLinuxContainersOnWindows(_vmConfiguration); _sessionHostsStartInfo.SessionHostType = SessionHostType.Container; SessionHostContainerConfiguration sessionHostContainerConfiguration = new SessionHostContainerConfiguration(_vmConfiguration, _logger, _systemOperations, _dockerClient.Object, _sessionHostsStartInfo, isRunningLinuxContainersOnWindows: true); IDictionary <string, string> envVariables = sessionHostContainerConfiguration.GetEnvironmentVariablesForSessionHost(0, TestLogFolderId, _sessionHostManager.Object.VmAgentSettings); string containerPath = _VmDirectoryContainerRoot + "/GameLogs" + "/"; string sharedContentFolderPath = _VmDirectoryContainerRoot + "/GameSharedContent"; string gsdkConfigFilePath = _VmDirectoryContainerRoot + "/Config" + "/gsdkConfig.json"; string certificateFolderPath = _VmDirectoryContainerRoot + "/GameCertificates"; Assert.AreEqual(envVariables[LogsDirectoryEnvVariable], containerPath); Assert.AreEqual(envVariables[SharedContentFolderEnvVariable], sharedContentFolderPath); Assert.AreEqual(envVariables[ConfigFileEnvVariable], gsdkConfigFilePath); Assert.AreEqual(envVariables[CertificateFolderEnvVariable], certificateFolderPath); }
public void TestCreateLegacyGSDKConfigFileWithSessionLinuxContainer() { _vmConfiguration = new VmConfiguration(56001, TestVmId, new VmDirectories(_root), true); _sessionHostManager.Setup(x => x.LinuxContainersOnWindows).Returns(true); VmPathHelper.AdaptFolderPathsForLinuxContainersOnWindows(_vmConfiguration); _sessionHostsStartInfo.SessionHostType = SessionHostType.Container; _sessionHostsStartInfo.PortMappingsList = new List <List <PortMapping> >() { new List <PortMapping>() { new PortMapping() { GamePort = new Port() { Name = "port", Number = 80, Protocol = "TCP" }, PublicPort = 1234, NodePort = 56001 } } }; List <PortMapping> mockPortMapping = _sessionHostsStartInfo.PortMappingsList[0]; SessionHostContainerConfiguration sessionHostContainerConfiguration = new SessionHostContainerConfiguration(_vmConfiguration, _logger, _systemOperations, _dockerClient.Object, _sessionHostsStartInfo, true); sessionHostContainerConfiguration.Create(0, TestdDockerId, TestAgentIPaddress, _vmConfiguration, TestLogFolderId); string gsdkConfigFilePath = Path.Combine(_root, "Config", "SH0", "gsdkConfig.json"); GsdkConfiguration gsdkConfigExpected = new GsdkConfiguration() { HeartbeatEndpoint = $"{TestAgentIPaddress}:56001", SessionHostId = TestdDockerId, VmId = TestVmId, LogFolder = "/data/GameLogs/", CertificateFolder = "/data/GameCertificates", SharedContentFolder = "/data/GameSharedContent", GamePorts = mockPortMapping?.ToDictionary(x => x.GamePort.Name, x => x.GamePort.Number.ToString()), PublicIpV4Address = TestPublicIpV4Address, GameServerConnectionInfo = new GameServerConnectionInfo { PublicIpV4Adress = TestPublicIpV4Address, GamePortsConfiguration = new List <GamePort>() { new GamePort() { Name = mockPortMapping[0].GamePort.Name, ServerListeningPort = mockPortMapping[0].GamePort.Number, ClientConnectionPort = mockPortMapping[0].PublicPort } } } }; GsdkConfiguration gsdkConfig = JsonConvert.DeserializeObject <GsdkConfiguration>(File.ReadAllText(gsdkConfigFilePath)); gsdkConfig.Should().BeEquivalentTo(gsdkConfigExpected); }
public static async Task Main(string[] args) { string[] salutations = { "Have a nice day!", "Thank you for using PlayFab Multiplayer Servers", "Check out our docs at aka.ms/playfabdocs!", "Have a question? Check our community at community.playfab.com" }; Console.WriteLine(salutations[new Random().Next(salutations.Length)]); string debuggingUrl = "https://github.com/PlayFab/gsdkSamples/blob/master/Debugging.md"; Console.WriteLine($"Check this page for debugging tips: {debuggingUrl}"); // lcow stands for Linux Containers On Windows => https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/linux-containers Globals.GameServerEnvironment = args.Contains("-lcow") && RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? GameServerEnvironment.Linux : GameServerEnvironment.Windows; // LocalMultiplayerAgent is running only on Windows for the time being MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(File.ReadAllText("MultiplayerSettings.json")); settings.SetDefaultsIfNotSpecified(); MultiplayerSettingsValidator validator = new MultiplayerSettingsValidator(settings); if (!validator.IsValid()) { Console.WriteLine("The specified settings are invalid. Please correct them and re-run the agent."); Environment.Exit(1); } string vmId = $"xcloudwusu4uyz5daouzl:{settings.Region}:{Guid.NewGuid()}:tvmps_{Guid.NewGuid():N}{Guid.NewGuid():N}_d"; Console.WriteLine($"TitleId: {settings.TitleId}"); Console.WriteLine($"BuildId: {settings.BuildId}"); Console.WriteLine($"VmId: {vmId}"); Globals.Settings = settings; string rootOutputFolder = Path.Combine(settings.OutputFolder, "PlayFabVmAgentOutput", DateTime.Now.ToString("s").Replace(':', '-')); Console.WriteLine($"Root output folder: {rootOutputFolder}"); VmDirectories vmDirectories = new VmDirectories(rootOutputFolder); Globals.VmConfiguration = new VmConfiguration(settings.AgentListeningPort, vmId, vmDirectories, false); if (Globals.GameServerEnvironment == GameServerEnvironment.Linux && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { VmPathHelper.AdaptFolderPathsForLinuxContainersOnWindows(Globals.VmConfiguration); // Linux Containers on Windows requires special folder mapping } Directory.CreateDirectory(rootOutputFolder); Directory.CreateDirectory(vmDirectories.GameLogsRootFolderVm); Directory.CreateDirectory(Globals.VmConfiguration.VmDirectories.CertificateRootFolderVm); IWebHost host = new WebHostBuilder() .UseKestrel() .UseUrls($"http://*:{settings.AgentListeningPort}") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .Build(); await host.StartAsync(); Console.WriteLine($"Local Multiplayer Agent is listening on port {settings.AgentListeningPort}"); Globals.SessionConfig = settings.SessionConfig ?? new SessionConfig() { SessionId = Guid.NewGuid() }; Console.WriteLine($"{string.Join(", ", Globals.SessionConfig.InitialPlayers)}"); await new MultiplayerServerManager(SystemOperations.Default, Globals.VmConfiguration, Globals.MultiLogger, SessionHostRunnerFactory.Instance) .CreateAndStartContainerWaitForExit(settings.ToSessionHostsStartInfo()); await host.StopAsync(); }