Example #1
0
        /// <summary>
        ///     Retrieves the player identity token needed to generate a login token when using
        ///     the anonymous authentication flow.
        /// </summary>
        /// <param name="authToken">The authentication token that you generated.</param>
        /// <param name="playerId">The id of the player that wants to connect.</param>
        /// <param name="displayName">The display name of the player that wants to connect.</param>
        /// <returns>The player identity token.</returns>
        protected virtual string GetDevelopmentPlayerIdentityToken(string authToken, string playerId, string displayName)
        {
            var result = DevelopmentAuthentication.CreateDevelopmentPlayerIdentityTokenAsync(
                RuntimeConfigDefaults.LocatorHost,
                RuntimeConfigDefaults.AnonymousAuthenticationPort,
                new PlayerIdentityTokenRequest
            {
                DevelopmentAuthenticationTokenId = authToken,
                PlayerId    = playerId,
                DisplayName = displayName,
            }
                ).Get();

            if (!result.HasValue)
            {
                throw new AuthenticationFailedException("Did not receive a player identity token.");
            }

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

            return(result.Value.PlayerIdentityToken);
        }
        /// <summary>
        ///     Retrieves a development player identity token using development authentication.
        /// </summary>
        /// <returns>The player identity token string.</returns>
        /// <exception cref="AuthenticationFailedException">Failed to get a development player identity token.</exception>
        protected virtual string GetDevelopmentPlayerIdentityToken()
        {
            var result = DevelopmentAuthentication.CreateDevelopmentPlayerIdentityTokenAsync(
                LocatorHost,
                LocatorPort,
                new PlayerIdentityTokenRequest
                {
                    DevelopmentAuthenticationToken = DevAuthToken,
                    PlayerId = GetPlayerId(),
                    DisplayName = GetDisplayName(),
                    UseInsecureConnection = UseInsecureConnection,
                }
            ).Get();

            if (!result.HasValue)
            {
                throw new AuthenticationFailedException("Did not receive a player identity token.");
            }

            if (result.Value.Status.Code != ConnectionStatusCode.Success)
            {
                throw new AuthenticationFailedException("Failed to retrieve a player identity token.\n" +
                    $"error code: {result.Value.Status.Code}\nerror message: {result.Value.Status.Detail}");
            }

            return result.Value.PlayerIdentityToken;
        }
Example #3
0
        private string GetPlayerIdentityToken(string developmentAuthToken, int retries = 0)
        {
            var playerIdentityTokenResponse = DevelopmentAuthentication.CreateDevelopmentPlayerIdentityTokenAsync(
                LocatorHost,
                LocatorPort,
                new PlayerIdentityTokenRequest
            {
                DevelopmentAuthenticationTokenId = developmentAuthToken,
                DisplayName           = workerType,
                PlayerId              = workerType,
                UseInsecureConnection = false,
            }).Get();

            if (playerIdentityTokenResponse.Status == ConnectionStatusCode.Success)
            {
                return(playerIdentityTokenResponse.PlayerIdentityToken);
            }

            if (retries < Utils.MaxRetries &&
                (playerIdentityTokenResponse.Status == ConnectionStatusCode.Timeout || playerIdentityTokenResponse.Status == ConnectionStatusCode.NetworkError))
            {
                return(GetPlayerIdentityToken(developmentAuthToken, retries + 1));
            }

            throw new System.Exception($"Failed to retrieve player identity token: {playerIdentityTokenResponse.Status}\n{playerIdentityTokenResponse.Error}");
        }
Example #4
0
        private static string GetDevelopmentPlayerIdentityToken(string host, ushort port, bool useInsecureConnection, string authToken, string playerId, string displayName)
        {
            using var pit = DevelopmentAuthentication.CreateDevelopmentPlayerIdentityTokenAsync(
                      host, port,
                      new PlayerIdentityTokenRequest
            {
                DevelopmentAuthenticationToken = authToken,
                PlayerId              = playerId,
                DisplayName           = displayName,
                UseInsecureConnection = useInsecureConnection
            });
            var value = pit.Get();

            if (!value.HasValue)
            {
                throw new AuthenticationException("Error received while retrieving a Player Identity Token: null result");
            }

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

            return(value.Value.PlayerIdentityToken);
        }
Example #5
0
 public override void StartState()
 {
     pitResponse = DevelopmentAuthentication.CreateDevelopmentPlayerIdentityTokenAsync(
         RuntimeConfigDefaults.LocatorHost,
         RuntimeConfigDefaults.AnonymousAuthenticationPort,
         new PlayerIdentityTokenRequest
     {
         DevelopmentAuthenticationToken = Blackboard.DevAuthToken,
         PlayerId    = Blackboard.PlayerName,
         DisplayName = string.Empty,
     }
         );
 }
Example #6
0
        public static string GetDevelopmentPlayerIdentityToken(string devAuthToken, string clientName)
        {
            var pitResponse = DevelopmentAuthentication.CreateDevelopmentPlayerIdentityTokenAsync("locator.improbable.io", 444,
                                                                                                  new PlayerIdentityTokenRequest
            {
                DevelopmentAuthenticationToken = devAuthToken,
                PlayerId    = clientName,
                DisplayName = clientName
            }).Get();

            if (pitResponse.Status.Code != ConnectionStatusCode.Success)
            {
                throw new Exception($"Failed to retrieve player identity token.\n" +
                                    $"error code: {pitResponse.Status.Code}\n" +
                                    $"error message: {pitResponse.Status.Detail}");
            }

            return(pitResponse.PlayerIdentityToken);
        }