public ConfigStatus ToLaunchGameRequest(
            LaunchParams parameters, out LaunchGameRequest request)
        {
            ConfigStatus status =
                _queryParametersParser.ParametersToDictionary(
                    parameters.QueryParams, out IDictionary <string, string> parametersDict);

            status = status.Merge(
                _queryParametersParser.ParseToParameters(parametersDict, parameters));
            ISdkConfig sdkConfig = _sdkConfigFactory.LoadGgpSdkConfigOrDefault();

            status = status.Merge(
                EnvironmentVariables(parameters, out IDictionary <string, string> envVariables));
            status = status.Merge(CommandLineArguments(parameters, out string[] cmdArgs));

            if ((parameters.Endpoint == StadiaEndpoint.PlayerEndpoint ||
                 parameters.Endpoint == StadiaEndpoint.AnyEndpoint) &&
                !string.IsNullOrEmpty(parameters.TestAccount))
            {
                status.AppendWarning(
                    ErrorStrings.TestAccountsNotSupported(parameters.TestAccountGamerName));
                parameters.TestAccount = null;
            }

            request = new LaunchGameRequest
            {
                Parent                   = Parent(sdkConfig, parameters),
                GameletName              = parameters.GameletName,
                ApplicationName          = parameters.ApplicationName,
                ExecutablePath           = ExecutablePath(parameters),
                CommandLineArguments     = cmdArgs,
                EnvironmentVariablePairs = envVariables,
                SurfaceEnforcementMode   = parameters.SurfaceEnforcementMode,
                Debug = parameters.Debug,
                EnableDeveloperResumeOffer = parameters.Endpoint == StadiaEndpoint.AnyEndpoint
            };

            status = status.Merge(
                _queryParametersParser.ParseToLaunchRequest(parametersDict, request));

            status = status.Merge(
                _queryParametersParser.GetFinalQueryString(parametersDict, out string queryString));
            parameters.QueryParams = queryString;

            if ((parameters.Endpoint == StadiaEndpoint.PlayerEndpoint ||
                 parameters.Endpoint == StadiaEndpoint.AnyEndpoint) &&
                !string.IsNullOrEmpty(queryString))
            {
                status.AppendWarning(ErrorStrings.QueryParamsNotSupported(queryString));
            }

            return(status);
        }
示例#2
0
        ConfigStatus ParseLaunchRequestVulkanDriverVariant(LaunchGameRequest launchRequest,
                                                           IDictionary <string, string> queryParams)
        {
            ConfigStatus status = ConfigStatus.OkStatus();

            if (queryParams.ContainsKey(QueryParamMapping.VulkanDriverVariant))
            {
                string driverVariant = "GGP_DEV_VK_DRIVER_VARIANT";
                if (!launchRequest.EnvironmentVariablePairs.ContainsKey(driverVariant))
                {
                    var allowedValues = new[] { "opt", "optprintasserts", "dbgtrapasserts" };
                    if (!allowedValues.Contains(queryParams[QueryParamMapping.VulkanDriverVariant]
                                                .ToLower()))
                    {
                        status.AppendWarning(ErrorStrings.InvalidEnumValue(
                                                 QueryParamMapping.VulkanDriverVariant,
                                                 queryParams[QueryParamMapping.VulkanDriverVariant],
                                                 allowedValues));
                    }
                    else
                    {
                        launchRequest.EnvironmentVariablePairs.Add(
                            driverVariant,
                            queryParams[QueryParamMapping.VulkanDriverVariant].ToLower());
                    }
                }
            }

            return(status);
        }
        ConfigStatus EnvironmentVariables(LaunchParams parameters,
                                          out IDictionary <string, string> envVariables)
        {
            ConfigStatus status          = ConfigStatus.OkStatus();
            string       variablesString = parameters.GameletEnvironmentVars ?? string.Empty;

            envVariables = variablesString.Split(';')
                           .Select(v => v.Trim())
                           .Where(v => !string.IsNullOrWhiteSpace(v)).Select(v =>
            {
                List <string> parts = v.Split('=').ToList();

                if (string.IsNullOrWhiteSpace(parts[0]))
                {
                    status.AppendWarning(ErrorStrings.InvalidEnvironmentVariable(v));
                    return(Tuple.Create(string.Empty, string.Empty));
                }

                return(Tuple.Create(parts[0], string.Join("=", parts.Skip(1))));
            }).Where(t => !string.IsNullOrEmpty(t.Item1)).GroupBy(tuple => tuple.Item1).Select(
                tuple =>
            {
                if (tuple.Count() > 1)
                {
                    status.AppendWarning(
                        ErrorStrings.MultipleEnvironmentVariableKeys(tuple.Key));
                }

                return(tuple);
            }).ToDictionary(t => t.Key, t => t.Last().Item2);
            status = status.Merge(AddFlagsEnvironmentVariables(parameters, envVariables));
            if (!status.IsOk)
            {
                status.AppendWarning(ErrorStrings.EditEnvironmentVariables);
            }

            return(status);
        }
        ConfigStatus AddFlagsEnvironmentVariables(
            LaunchParams parameters, IDictionary <string, string> variables)
        {
            ConfigStatus status = ConfigStatus.OkStatus();
            var          flagEnvironmentVariables = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(parameters.VulkanDriverVariant))
            {
                flagEnvironmentVariables.Add("GGP_DEV_VK_DRIVER_VARIANT",
                                             parameters.VulkanDriverVariant);
            }
            if (parameters.RenderDoc)
            {
                flagEnvironmentVariables.Add("ENABLE_VULKAN_RENDERDOC_CAPTURE", "1");
                flagEnvironmentVariables.Add("RENDERDOC_TEMP", "/mnt/developer/ggp");
                flagEnvironmentVariables.Add("RENDERDOC_DEBUG_LOG_FILE", "/var/game/RDDebug.log");
            }
            if (parameters.Rgp)
            {
                flagEnvironmentVariables.Add("GGP_INTERNAL_LOAD_RGP", "1");
                flagEnvironmentVariables.Add("RGP_DEBUG_LOG_FILE", "/var/game/RGPDebug.log");
            }

            foreach (string key in flagEnvironmentVariables.Keys)
            {
                if (variables.ContainsKey(key))
                {
                    status.AppendWarning(ErrorStrings.EnvironmentVariableOverride(key));
                    continue;
                }
                variables.Add(key, flagEnvironmentVariables[key]);
            }

            if (parameters.Rgp)
            {
                if (!variables.ContainsKey("LD_PRELOAD"))
                {
                    variables.Add("LD_PRELOAD", string.Empty);
                }
                variables["LD_PRELOAD"] += (string.IsNullOrEmpty(variables["LD_PRELOAD"])
                    ? string.Empty
                    : ":") + "librgpserver.so";
            }

            return(status);
        }