Esempio n. 1
0
        /// <summary>
        ///     Retrieves the login tokens for all active deployments that the player
        ///     can connect to via the anonymous authentication flow.
        /// </summary>
        /// <param name="workerType">The type of the worker that wants to connect.</param>
        /// <param name="playerIdentityToken">The player identity token of the player that wants to connect.</param>
        /// <returns>A list of all available login tokens and their deployments.</returns>
        protected virtual List <LoginTokenDetails> GetDevelopmentLoginTokens(string workerType, string playerIdentityToken)
        {
            var result = DevelopmentAuthentication.CreateDevelopmentLoginTokensAsync(
                RuntimeConfigDefaults.LocatorHost,
                RuntimeConfigDefaults.AnonymousAuthenticationPort,
                new LoginTokensRequest
            {
                WorkerType            = workerType,
                PlayerIdentityToken   = playerIdentityToken,
                UseInsecureConnection = false,
                DurationSeconds       = 120,
            }
                ).Get();

            if (!result.HasValue)
            {
                throw new AuthenticationFailedException("Did not receive any login tokens back.");
            }

            if (result.Value.Status != ConnectionStatusCode.Success)
            {
                throw new AuthenticationFailedException("Failed to retrieve any login tokens.\n" +
                                                        $"error code: {result.Value.Status}\nerror message: {result.Value.Error}");
            }

            return(result.Value.LoginTokens);
        }
 public override void StartState()
 {
     loginTokensResponse = DevelopmentAuthentication.CreateDevelopmentLoginTokensAsync(
         RuntimeConfigDefaults.LocatorHost,
         RuntimeConfigDefaults.AnonymousAuthenticationPort,
         new LoginTokensRequest
     {
         WorkerType            = WorkerUtils.UnityClient,
         PlayerIdentityToken   = Blackboard.PlayerIdentityToken,
         UseInsecureConnection = false,
         DurationSeconds       = 120,
     }
         );
 }
Esempio n. 3
0
        public static List <LoginTokenDetails> GetDevelopmentLoginTokens(string workerType, string pit)
        {
            var loginTokensResponse = DevelopmentAuthentication.CreateDevelopmentLoginTokensAsync(LOCATOR_HOST_NAME, LOCATOR_PORT,
                                                                                                  new LoginTokensRequest
            {
                PlayerIdentityToken   = pit,
                WorkerType            = workerType,
                UseInsecureConnection = false,
                DurationSeconds       = 300
            }).Get();

            if (loginTokensResponse.Status.Code != ConnectionStatusCode.Success)
            {
                throw new Exception($"Failed to retrieve any login tokens.\n" +
                                    $"error code: {loginTokensResponse.Status.Code}\n" +
                                    $"error message: {loginTokensResponse.Status.Detail}");
            }

            return(loginTokensResponse.LoginTokens);
        }
Esempio n. 4
0
        private List <LoginTokenDetails> GetLoginTokenDetails(string playerIdentityToken, int retries = 0)
        {
            var loginTokenDetailsResponse = DevelopmentAuthentication.CreateDevelopmentLoginTokensAsync(
                LocatorHost,
                LocatorPort,
                new LoginTokensRequest
            {
                PlayerIdentityToken   = playerIdentityToken,
                UseInsecureConnection = false,
                WorkerType            = workerType,
            }).Get();

            if (loginTokenDetailsResponse.Status == ConnectionStatusCode.Success)
            {
                return(loginTokenDetailsResponse.LoginTokens);
            }
            else if (retries < Utils.MaxRetries &&
                     (loginTokenDetailsResponse.Status == ConnectionStatusCode.Timeout || loginTokenDetailsResponse.Status == ConnectionStatusCode.NetworkError))
            {
                return(GetLoginTokenDetails(playerIdentityToken, retries + 1));
            }

            throw new System.Exception($"Failed to retrieve player identity token: {loginTokenDetailsResponse.Status}\n{loginTokenDetailsResponse.Error}");
        }
Esempio n. 5
0
        private static IEnumerable <LoginTokenDetails> GetDevelopmentLoginTokens(string host, ushort port, bool useInsecureConnection, string workerType, string pit)
        {
            using var tokens = DevelopmentAuthentication.CreateDevelopmentLoginTokensAsync(host, port,
                                                                                           new LoginTokensRequest
            {
                PlayerIdentityToken   = pit,
                WorkerType            = workerType,
                UseInsecureConnection = useInsecureConnection
            });

            var value = tokens.Get();

            if (!value.HasValue)
            {
                throw new AuthenticationException("Error received while retrieving Login Tokens: null result");
            }

            if (value.Value.Status.Code != ConnectionStatusCode.Success)
            {
                throw new AuthenticationException($"Error received while retrieving Login Tokens: {value.Value.Status.Detail}");
            }

            return(value.Value.LoginTokens);
        }