Example #1
0
        /// <summary>
        ///     Creates a Receptionist configuration.
        /// </summary>
        /// <remarks>
        ///     If in a standalone build, will use the command line arguments.
        /// </remarks>
        /// <remarks>
        ///    A worker ID is auto-generated if in the Unity Editor or if one is not provided over the command line.
        /// </remarks>
        /// <param name="workerType">The type of the worker to create.</param>
        /// <returns>The Receptionist connection configuration</returns>
        protected virtual ReceptionistConfig GetReceptionistConfig(string workerType)
        {
            ReceptionistConfig config;

            if (Application.isEditor)
            {
                config = new ReceptionistConfig
                {
                    WorkerType    = workerType,
                    WorkerId      = CreateNewWorkerId(workerType),
                    UseExternalIp = UseExternalIp
                };
            }
            else
            {
                var commandLineArguments = Environment.GetCommandLineArgs();
                var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
                config               = ReceptionistConfig.CreateConnectionConfigFromCommandLine(commandLineArgs);
                config.WorkerType    = workerType;
                config.UseExternalIp = UseExternalIp;
                if (!commandLineArgs.ContainsKey(RuntimeConfigNames.WorkerId))
                {
                    config.WorkerId = CreateNewWorkerId(workerType);
                }
            }

            return(config);
        }
Example #2
0
        protected override ReceptionistConfig GetReceptionistConfig(string workerType)
        {
            if (Application.isEditor)
            {
                return(new ReceptionistConfig
                {
                    ReceptionistHost = RuntimeConfigDefaults.ReceptionistHost,
                    ReceptionistPort = RuntimeConfigDefaults.ReceptionistPort,
                    WorkerId = CreateNewWorkerId(workerType)
                });
            }

            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);

            return(new ReceptionistConfig
            {
                ReceptionistHost = CommandLineUtility.GetCommandLineValue(
                    commandLineArgs, RuntimeConfigNames.ReceptionistHost, RuntimeConfigDefaults.ReceptionistHost),
                ReceptionistPort = CommandLineUtility.GetCommandLineValue(
                    commandLineArgs, RuntimeConfigNames.ReceptionistPort, RuntimeConfigDefaults.ReceptionistPort),
                WorkerId = CommandLineUtility.GetCommandLineValue(
                    commandLineArgs, RuntimeConfigNames.WorkerId, CreateNewWorkerId(workerType)),
            });
        }
Example #3
0
        protected override LocatorConfig GetLocatorConfig()
        {
            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);

            var projectName = CommandLineUtility.GetCommandLineValue(
                commandLineArgs, RuntimeConfigNames.ProjectName, string.Empty);

            if (string.IsNullOrEmpty(projectName))
            {
                throw new ConnectionFailedException("Project name is not set. Can't connect via the Locator.", ConnectionErrorReason.InvalidConfig);
            }

            var loginToken = CommandLineUtility.GetCommandLineValue(
                commandLineArgs, RuntimeConfigNames.LoginToken, string.Empty);
            var steamDeploymentTag = CommandLineUtility.GetCommandLineValue(
                commandLineArgs, RuntimeConfigNames.SteamDeploymentTag, string.Empty);
            var steamTicket = CommandLineUtility.GetCommandLineValue(
                commandLineArgs, RuntimeConfigNames.SteamTicket, string.Empty);


            LocatorCredentialsType credentialType;

            if (!string.IsNullOrEmpty(loginToken))
            {
                credentialType = LocatorCredentialsType.LoginToken;
            }
            else if (!string.IsNullOrEmpty(steamDeploymentTag) && !string.IsNullOrEmpty(steamTicket))
            {
                credentialType = LocatorCredentialsType.Steam;
            }
            else
            {
                throw new ConnectionFailedException("Neither steam credentials nor login token is set. Can't connect via the Locator.", ConnectionErrorReason.InvalidConfig);
            }

            return(new LocatorConfig
            {
                DeploymentListCallback = SelectDeploymentName,
                LocatorHost = CommandLineUtility.GetCommandLineValue(
                    commandLineArgs, RuntimeConfigNames.LocatorHost, RuntimeConfigDefaults.LocatorHost),
                LocatorParameters = new LocatorParameters
                {
                    CredentialsType = credentialType,
                    LoginToken = new LoginTokenCredentials
                    {
                        Token = loginToken,
                    },
                    Steam = new SteamCredentials
                    {
                        DeploymentTag = steamDeploymentTag,
                        Ticket = steamTicket,
                    },
                    ProjectName = projectName,
                }
            });
        }
Example #4
0
        /// <summary>
        ///     Creates the Locator configuration.
        /// </summary>
        /// <remarks>
        ///     If in a standalone build, will use the command line arguments.
        /// </remarks>
        /// <param name="workerType">The type of the worker to create.</param>
        /// <returns>The Locator connection configuration</returns>
        protected virtual LocatorConfig GetLocatorConfig(string workerType)
        {
            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
            var config = LocatorConfig.CreateConnectionConfigFromCommandLine(commandLineArgs);

            config.WorkerType = workerType;
            config.WorkerId   = CreateNewWorkerId(workerType);
            return(config);
        }
Example #5
0
        protected virtual bool ShouldUseLocator()
        {
            if (Application.isEditor)
            {
                return(false);
            }

            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);

            return(commandLineArgs.ContainsKey(RuntimeConfigNames.LoginToken));
        }
Example #6
0
        /// <summary>
        ///     Determines whether to connect via the locator.
        /// </summary>
        /// <returns>True, if should connect via the Locator, false otherwise.</returns>
        protected override bool ShouldUseLocator()
        {
            if (Application.isEditor)
            {
                return(false);
            }

            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
            var shouldUseLocator     = commandLineArgs.ContainsKey(RuntimeConfigNames.LoginToken) ||
                                       commandLineArgs.ContainsKey(RuntimeConfigNames.SteamDeploymentTag) ||
                                       commandLineArgs.ContainsKey(RuntimeConfigNames.SteamTicket);

            return(shouldUseLocator);
        }
Example #7
0
        protected override ConnectionService GetConnectionService()
        {
            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);

            if (commandLineArgs.ContainsKey(RuntimeConfigNames.SteamDeploymentTag) ||
                commandLineArgs.ContainsKey(RuntimeConfigNames.SteamTicket))
            {
                return(ConnectionService.Locator);
            }

            if (commandLineArgs.ContainsKey(RuntimeConfigNames.LoginToken))
            {
                return(commandLineArgs.ContainsKey(RuntimeConfigNames.PlayerIdentityToken)
                    ? ConnectionService.AlphaLocator
                    : ConnectionService.Locator);
            }

            return(ConnectionService.Receptionist);
        }
Example #8
0
        protected override AlphaLocatorConfig GetAlphaLocatorConfig(string workerType)
        {
            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);

            return(new AlphaLocatorConfig
            {
                LocatorHost = CommandLineUtility.GetCommandLineValue(
                    commandLineArgs, RuntimeConfigNames.LocatorHost, RuntimeConfigDefaults.LocatorHost),
                LocatorParameters = new Alpha.LocatorParameters
                {
                    PlayerIdentity = new Alpha.PlayerIdentityCredentials
                    {
                        PlayerIdentityToken = CommandLineUtility.GetCommandLineValue(
                            commandLineArgs, RuntimeConfigNames.PlayerIdentityToken, string.Empty),
                        LoginToken = CommandLineUtility.GetCommandLineValue(
                            commandLineArgs, RuntimeConfigNames.LoginToken, string.Empty)
                    },
                },
            });
        }
Example #9
0
        protected override ConnectionParameters GetConnectionParameters(string workerType, ConnectionService service)
        {
            // UseExternalIp needs to be true when using the locator
            var useExternalIp = service == ConnectionService.Locator ||
                                service == ConnectionService.AlphaLocator ||
                                UseExternalIp;

            if (Application.isEditor)
            {
                return(new ConnectionParameters
                {
                    WorkerType = workerType,
                    Network =
                    {
                        ConnectionType = RuntimeConfigDefaults.LinkProtocol,
                        UseExternalIp  = useExternalIp,
                    },
                    EnableProtocolLoggingAtStartup = false,
                    DefaultComponentVtable = new ComponentVtable(),
                });
            }

            var commandLineArguments = Environment.GetCommandLineArgs();
            var commandLineArgs      = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
            var linkProtocol         = CommandLineUtility.GetCommandLineValue(
                commandLineArgs, RuntimeConfigNames.LinkProtocol, RuntimeConfigDefaults.LinkProtocol);

            return(new ConnectionParameters
            {
                WorkerType = CommandLineUtility.GetCommandLineValue(
                    commandLineArgs, RuntimeConfigNames.WorkerType, workerType),
                Network =
                {
                    ConnectionType = linkProtocol,
                    UseExternalIp  = useExternalIp,
                },
                EnableProtocolLoggingAtStartup = false,
                DefaultComponentVtable = new ComponentVtable()
            });
        }