예제 #1
0
        /// <summary> Connects to Player.IO using as the given user </summary>
        /// <param name="gameId"> The game ID of the game you wish to connect to. This value can be found in the admin panel </param>
        /// <param name="connectionId"> The ID of the connection, as given in the settings section of the admin panel. 'public' should be used as the default </param>
        /// <param name="authenticationArguments"> A dictionary of arguments for the given connection. </param>
        /// <param name="playerInsightSegments"> Custom segments for the user in PlayerInsight. </param>
        /// <param name="successCallback"> A callback called when successfully connected. </param>
        /// <param name="errorCallback"> A callback called instead of <paramref name="successCallback"/> when an error occurs during connection. </param>
        public static void Authenticate(string gameId, string connectionId, Dictionary <string, string> authenticationArguments = null, string[] playerInsightSegments = null, Callback <Client> successCallback = null, Callback <PlayerIOError> errorCallback = null)
        {
            var authenticationOutput = Channel.Request <AuthenticateArgs, AuthenticateOutput, PlayerIOError>(13, new AuthenticateArgs
            {
                GameId                  = gameId,
                ConnectionId            = connectionId,
                AuthenticationArguments = Converter.Convert(authenticationArguments ?? new Dictionary <string, string>()),
                PlayerInsightSegments   = playerInsightSegments?.ToList() ?? new List <string>(),
                ClientAPI               = GetClientAPI(),
                ClientInfo              = Converter.Convert(GetClientInfo()),
                PlayCodes               = GetPlayCodes()
            }, errorCallback);

            if (authenticationOutput != null)
            {
                PlayerIO.ServerApiEndpoints = authenticationOutput.ApiServerHosts;
                PlayerIO.ServerApiSecurity  = authenticationOutput.ApiSecurity;

                // TODO: Don't want to overwrite any custom user-set endpoint...
                PlayerIO.SetAPIEndpoint(PlayerIO.ServerApiEndpoints[0]);

                successCallback(new Client(Channel, gameId,
                                           authenticationOutput.GameFSRedirectMap,
                                           authenticationOutput.Token,
                                           authenticationOutput.UserId,
                                           authenticationOutput.ShowBranding,
                                           authenticationOutput.IsSocialNetworkUser, null));
            }
        }
예제 #2
0
        /// <summary>Connects to Player.IO using as the given user</summary>
        /// <param name="gameId">The game id of the game you wish to connect to. This value can be found in the admin panel</param>
        /// <param name="connectionId">The id of the connection, as given in the settings section of the admin panel. 'public' should be used as the default</param>
        /// <param name="authenticationArguments">A dictionary of arguments for the given connection.</param>
        /// <param name="playerInsightSegments">Custom segments for the user in PlayerInsight.</param>
        public static Client Authenticate(string gameId, string connectionId, Dictionary <string, string> authenticationArguments = null, string[] playerInsightSegments = null)
        {
            if (authenticationArguments?.ContainsKey("secureSimpleUserPasswordsOverHttp") == true && authenticationArguments["secureSimpleUserPasswordsOverHttp"] == "true")
            {
                var identifier = SimpleUserGetSecureLoginInfo();
                authenticationArguments["password"] = PlayerIO.SimpleUserPasswordEncrypt(identifier.PublicKey, authenticationArguments["password"]);
                authenticationArguments["nonce"]    = identifier.Nonce;
            }

            var identifier2 = Authenticate(gameId, connectionId, authenticationArguments ?? null, playerInsightSegments?.ToList() ?? null, PlayerIO.GetClientAPI(), PlayerIO.GetClientInfo(), PlayerIO.GetPlayCodes());

            PlayerIO.ServerApiEndpoints = identifier2.ApiServerHosts;
            PlayerIO.ServerApiSecurity  = identifier2.ApiSecurity;

            // TODO: Don't want to overwrite any custom user-set end-point...
            PlayerIO.SetAPIEndpoint(PlayerIO.ServerApiEndpoints[0]);

            return(new Client(Channel, gameId, identifier2.GameFSRedirectMap, identifier2.Token, identifier2.UserId, identifier2.ShowBranding, identifier2.IsSocialNetworkUser, null));
        }