Exemplo n.º 1
0
        public void ValidateNumHeartbeats()
        {
            // test for NumHeartBeatsForActivateResponse
            dynamic config = GetValidConfig();

            config.NumHeartBeatsForActivateResponse = 0;
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();

            // test for NumHeartBeatsForTerminateResponse
            config = GetValidConfig();
            config.NumHeartBeatsForTerminateResponse = 0;
            settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());
            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();

            // test for NumHeartBeatsForTerminateResponse and NumHeartBeatsForActivateResponse
            config = GetValidConfig();
            config.NumHeartBeatsForTerminateResponse = 10;
            config.NumHeartBeatsForActivateResponse  = 10;
            settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());
            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();
        }
Exemplo n.º 2
0
        public void DefaultConfigIsInvalid()
        {
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(DefaultConfig);

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();
        }
Exemplo n.º 3
0
        public void ValidConfigReturnsValid()
        {
            dynamic             config   = GetValidConfig();
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeTrue();
        }
Exemplo n.º 4
0
        public void EmptyNodePortInContainerModeShouldFail()
        {
            dynamic config = GetValidConfig();

            config.RunContainer = true;
            config.PortMappingsList[0][0].NodePort = 0;
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();
        }
Exemplo n.º 5
0
        public void StartGameCommandThatContainsMountPathShouldSucceed(string startGameCommand)
        {
            dynamic config = GetValidConfig();

            config.RunContainer = true;
            config.AssetDetails[0].MountPath = "C:\\Assets";
            config.ContainerStartParameters.StartGameCommand = startGameCommand;
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeTrue();
        }
Exemplo n.º 6
0
        public void InvalidContainerStartCommandIsInvalid()
        {
            dynamic config = GetValidConfig();

            config.RunContainer = true;
            config.ContainerStartParameters.StartGameCommand = @"C:\Assets\<your_game_server_exe>";

            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();
        }
Exemplo n.º 7
0
        public void CertsNoExtensionPfxFails()
        {
            dynamic             config   = GetValidConfig();
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            settings.GameCertificateDetails = new[]
            {
                new GameCertificateDetails()
                {
                    Name = "cert1", Path = "C:\\test.pfxlala"
                },
                new GameCertificateDetails()
                {
                    Name = "cert2", Path = "C:\\test2.123"
                }
            };
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();
        }
Exemplo n.º 8
0
        public void CertsWithDifferentPathAndNameSucceeds()
        {
            dynamic             config   = GetValidConfig();
            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            settings.GameCertificateDetails = new[]
            {
                new GameCertificateDetails()
                {
                    Name = "test", Path = "C:\\mycert.pfx"
                },
                new GameCertificateDetails()
                {
                    Name = "test2", Path = "C:\\mycert2.pfx"
                }
            };
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeTrue();
        }
Exemplo n.º 9
0
        public void SessionHostStartWithProcess()
        {
            dynamic config = GetValidConfig();

            config.RunContainer = false;

            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeTrue();

            SessionHostsStartInfo startInfo = settings.ToSessionHostsStartInfo();

            startInfo.HostConfigOverrides.Should().BeNull();
            startInfo.SessionHostType.Should().Be(SessionHostType.Process);
            foreach (AssetDetail assetDetail in startInfo.AssetDetails)
            {
                assetDetail.MountPath.Should().BeNull();
            }
        }
Exemplo n.º 10
0
        public void SessionHostStartWithContainer()
        {
            dynamic config = GetValidConfig();

            config.RunContainer = true;

            MultiplayerSettings settings = JsonConvert.DeserializeObject <MultiplayerSettings>(config.ToString());

            settings.SetDefaultsIfNotSpecified();
            new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeTrue();

            SessionHostsStartInfo startInfo = settings.ToSessionHostsStartInfo();
            long expectedNanoCpus           = (long)((double)config.ContainerStartParameters.ResourceLimits.Cpus * 1_000_000_000);
            long expectedMemory             = config.ContainerStartParameters.ResourceLimits.MemoryGib * Math.Pow(1024, 3);

            startInfo.SessionHostType.Should().Be(SessionHostType.Container);
            startInfo.HostConfigOverrides.NanoCPUs.Should().Be(expectedNanoCpus);
            startInfo.HostConfigOverrides.Memory.Should().Be(expectedMemory);
            foreach (AssetDetail assetDetail in startInfo.AssetDetails)
            {
                assetDetail.MountPath.Should().NotBeNull();
            }
        }
Exemplo n.º 11
0
        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);
            if (Globals.GameServerEnvironment == GameServerEnvironment.Linux && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Globals.AdaptFolderPathsForLinuxContainersOnWindows();  // 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();
        }