Exemplo n.º 1
0
        /// <summary>
        /// Check whether a simple user currently exists with the details provided.
        /// </summary>
        /// <returns> If the simple user exists already, this method returns <see langword="true"/> </returns>
        public static bool SimpleUserIsRegistered(string gameId, string username, string email, string connectionId = "public")
        {
            if (string.IsNullOrEmpty(gameId))
            {
                throw new ArgumentException("A game ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(email))
            {
                throw new ArgumentException("A username or email must be specified in order to use this method.");
            }

            var response = true;

            try
            {
                PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(
                                          ("checkusername", "true"),
                                          ("username", username),
                                          ("email", email)
                                          ));
            }
            catch (PlayerIOError error)
            {
                if (error.ErrorCode == ErrorCode.UnknownUser)
                {
                    response = false;
                }
            }

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Authenticate with Facebook using the Access Token provided.
        /// </summary>
        public static Client FacebookConnect(string gameId, string accessToken, string connectionId = "public")
        {
            if (string.IsNullOrEmpty(gameId))
            {
                throw new ArgumentException("A game ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(accessToken))
            {
                throw new ArgumentException("A Facebook access token must be specified in order to use this method.");
            }

            return(PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(("accessToken", accessToken))));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Authenticate with ArmorGames using the userId and token provided.
        /// </summary>
        public static Client ArmorGamesConnect(string gameId, string userId, string token, string connectionId = "public")
        {
            if (string.IsNullOrEmpty(gameId))
            {
                throw new ArgumentException("A game ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentException("An ArmorGames userId must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentException("An ArmorGames auth token must be specified in order to use this method.");
            }

            return(PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(("userId", userId), ("authToken", token))));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Authenticate with Steam using the Steam App ID and Steam Session Ticket provided.
        /// </summary>
        public static Client SteamConnect(string gameId, string appId, string sessionTicket, string connectionId = "public")
        {
            if (string.IsNullOrEmpty(gameId))
            {
                throw new ArgumentException("A game ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentException("A Steam App ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(sessionTicket))
            {
                throw new ArgumentException("A Steam Session Ticket must be specified in order to use this method.");
            }

            return(PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(("steamSessionTicket", sessionTicket), ("steamAppId", appId))));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Change the email for a simple user with the provided username or email address, and valid password.
        /// </summary>
        /// <returns> If the change was successful, returns <see langword="true"/>. </returns>
        public static bool ChangeEmail(string gameId, string usernameOrEmail, string password, string newEmail, string connectionId = "public")
        {
            if (string.IsNullOrEmpty(gameId))
            {
                throw new ArgumentException("A game ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(usernameOrEmail))
            {
                throw new ArgumentException("A username or email must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(newEmail))
            {
                throw new ArgumentException("You must specify a new email to use for this method.");
            }

            var response = false;

            try
            {
                PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(
                                          ("changeemail", "true"),
                                          ("username", usernameOrEmail.Contains("@") ? null : usernameOrEmail),
                                          ("email", usernameOrEmail.Contains("@") ? usernameOrEmail : null),
                                          ("password", password),
                                          ("newemail", newEmail)
                                          ));
            }
            catch (PlayerIOError error)
            {
                if (error.ErrorCode == ErrorCode.GeneralError && error.Message.ToLower().Contains("email address changed"))
                {
                    response = true;
                }
            }

            return(response);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Authenticate with SimpleUser connection type using the username or email address and password provided.
        /// </summary>
        public static Client SimpleConnect(string gameId, string usernameOrEmail, string password, string connectionId = "public")
        {
            if (string.IsNullOrEmpty(gameId))
            {
                throw new ArgumentException("A game ID must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(usernameOrEmail))
            {
                throw new ArgumentException("A username or email must be specified in order to use this method.");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("A password must be specified in order to use this method.");
            }

            return(PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(
                                             ("username", usernameOrEmail.Contains("@") ? null : usernameOrEmail),
                                             ("email", usernameOrEmail.Contains("@") ? usernameOrEmail : null),
                                             ("password", password))));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Connects to a game based on Player.IO as the given user using basic authentiation.
 /// </summary>
 /// <param name="gameId">
 /// The 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="userId"> The ID of the user you wish to authenticate. </param>
 /// <param name="auth">
 /// If the connection identified by ConnectionIdentifier only accepts authenticated requests:
 /// The auth value generated based on 'userId'. You can generate an auth value using the
 /// CalcAuth256() method.
 /// </param>
 public static Client Connect(string gameId, string connectionId, string userId, string auth) =>
 PlayerIO.Authenticate(gameId, connectionId, DictionaryEx.Create(("userId", userId), ("auth", auth)));