예제 #1
0
        public static void AdaptFolderPathsForLinuxContainersOnWindows()
        {
            // running Linux containers with Docker for Windows requires some "weird" path mapping
            // in the sense that we want to map Linux paths on the container to Windows paths on the host
            // following method call makes sure of that
            VmDirectories vmd = VmConfiguration.VmDirectories;

            vmd.GameSharedContentFolderContainer = replacePathForLinuxContainersOnWindows(vmd.GameSharedContentFolderContainer);
            vmd.GameLogsRootFolderContainer      = replacePathForLinuxContainersOnWindows(vmd.GameLogsRootFolderContainer);
            vmd.CertificateRootFolderContainer   = replacePathForLinuxContainersOnWindows(vmd.CertificateRootFolderContainer);
            vmd.GsdkConfigRootFolderContainer    = replacePathForLinuxContainersOnWindows(vmd.GsdkConfigRootFolderContainer);
            vmd.GsdkConfigFilePathContainer      = replacePathForLinuxContainersOnWindows(vmd.GsdkConfigFilePathContainer);
        }
예제 #2
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();
        }