示例#1
0
        private IEnumerator SetScoreRoutine(int score, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Set Score: " + score.ToString());

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            WWWForm form = new WWWForm();

            form.AddField("authentication_token", GetAuthenticationToken());
            form.AddField("score", score);
            var request = UnityWebRequest.Post(CloudLogin.GetBaseURL() + "/users/" + CurrentUser.id + "/set_score", form);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Set Score Success: " + score.ToString());

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                SetScoreInternal(Convert.ToInt32(json.GetNumber("score")));
            }

            CloudLoginUtilities.HandleCallback(request, "Score have been added to user", callback);
        }
示例#2
0
        private IEnumerator RemoveAttributeRoutine(string key, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Remove Attributes: " + key);

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            var parameters = "?authentication_token=" + GetAuthenticationToken() + "&game_user_attribute_key=" + key;
            var request    = UnityWebRequest.Get(CloudLogin.GetBaseURL() + "/users/" + CurrentUser.id + "/remove_game_user_attributes" + parameters);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Remove Attributes Success: " + key);

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                var        game_user_attributes = json.GetArray("game_user_attributes");

                attributes.Clear();
                foreach (var attribute in game_user_attributes)
                {
                    attributes.Add(attribute.Obj.GetString("key"), attribute.Obj.GetString("value"));
                }
            }

            CloudLoginUtilities.HandleCallback(request, "Attribute has been removed", callback);
        }
示例#3
0
        private IEnumerator SetUpGameRoutine(string gameId, string token, Action <string, bool> callback = null, bool seedStore = false)
        {
            var body = "game_id=" + gameId + "&game_token=" + token;

            if (seedStore)
            {
                body = body + "&seed_store=true";
            }
            Log("CloudLogin Setting Up Game Sending Request: " + baseURL + "/games/verify?" + body);
            var request = UnityWebRequest.Get(baseURL + "/games/verify?" + body);

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                Log("CloudLogin Setting Up Game Recieved Request Success: " + gameId + ": " + token);
                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                Instance.id          = json.GetNumber("id").ToString();
                Instance.name        = json.GetString("name");
                Instance.description = json.GetString("description");
                Instance.token       = json.GetString("token");
                DownloadStoreItemsPrivate(callback);
            }
            else
            {
                Log("CloudLogin Setting Up Game Recieved Request Failure: " + gameId + ": " + token);
                CloudLoginUtilities.HandleCallback(request, "Game has failed to set up!", callback);
            }
        }
示例#4
0
        private IEnumerator SignUpRoutine(string email, string password, string password_confirmation, string username, Action <string, bool> callback = null)
        {
            Log("CloudLogin Sign Up: " + email);

            if (GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with PainLessAuth.SetUpGame before signing up users");
            }

            WWWForm form = new WWWForm();

            form.AddField("email", email);
            form.AddField("password", password);
            form.AddField("password_confirmation", password_confirmation);
            form.AddField("username", username);

            form.AddField("game_id", GetGameId());
            form.AddField("game_token", GetGameToken());

            var request = UnityWebRequest.Post(baseURL + "/users", form);

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                Log("CloudLogin Sign Up Success: " + email);
                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                CloudLoginUser.CurrentUser.SetSignedInInternal();
                CloudLoginUser.CurrentUser.SetScoreInternal(Convert.ToInt32(json.GetNumber("score")));
                CloudLoginUser.CurrentUser.SetCreditsInternal(Convert.ToInt32(json.GetNumber("credits")));
                CloudLoginUser.CurrentUser.SetUsernameInternal(json.GetString("username"));
                CloudLoginUser.CurrentUser.SetLastLoginInternal(DateTime.Parse(json.GetString("last_login")));
                CloudLoginUser.CurrentUser.SetNumberOfLoginsInternal(Convert.ToInt32(json.GetNumber("number_of_logins")));
                CloudLoginUser.CurrentUser.SetAuthenticationTokenInternal(json.GetString("authentication_token"));
                CloudLoginUser.CurrentUser.SetIDInternal(Convert.ToInt32(json.GetNumber("id")));
                CloudLoginUser.CurrentUser.DownloadAttributes(true, callback); // Chain next request - download users attributes
            }
            else
            {
                Log("CloudLogin Sign Up Failure: " + email);
                CloudLoginUtilities.HandleCallback(request, "User could not sign up: " + request.error, callback);
            }
        }
示例#5
0
        private IEnumerator PurchaseStoreItemRoutine(int storeItemId, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Purchase Store Items: ");

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            WWWForm form = new WWWForm();

            form.AddField("authentication_token", GetAuthenticationToken());
            form.AddField("store_item_id", storeItemId.ToString());

            var request = UnityWebRequest.Post(CloudLogin.GetBaseURL() + "/users/" + CurrentUser.id + "/purchase_game_user_store_item", form);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Purchase Store Items Success: ");

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                var        game_user_store_items = json.GetArray("game_user_store_items");
                CurrentUser.SetCreditsInternal(Convert.ToInt32(json.GetNumber("credits")));
                purchasedStoreItems.Clear();

                foreach (var item in game_user_store_items)
                {
                    purchasedStoreItems.Add(new CloudLoginStoreItem(
                                                item.Obj.GetString("name"),
                                                item.Obj.GetString("category"),
                                                item.Obj.GetString("description"),
                                                Convert.ToInt32(item.Obj.GetNumber("cost")),
                                                Convert.ToInt32(item.Obj.GetNumber("id"))));
                }
            }

            CloudLoginUtilities.HandleCallback(request, "Store Item has been purchased by user", callback);
        }
示例#6
0
        private IEnumerator GetLeaderboardRoutine(int limit, bool onePerUser, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Get Leaderboard: " + limit.ToString());

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            var parameters = "?authentication_token=" + GetAuthenticationToken() + "&limit=" + limit.ToString() + "&one_per_user="******"/users/" + CurrentUser.id + "/leaderboard_entries" + parameters);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Get Leaderboard Success: : " + limit.ToString());

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                Debug.Log("got " + json);
                var storeItems = json.GetArray("leaderboard_entries");
                CloudLogin.Instance.leaderboardEntries.Clear();
                foreach (var storeItem in storeItems)
                {
                    CloudLogin.Instance.leaderboardEntries.Add(new CloudLoginLeaderboardEntry(
                                                                   storeItem.Obj.GetString("username"),
                                                                   Convert.ToInt32(storeItem.Obj.GetNumber("score")),
                                                                   storeItem.Obj.GetString("leaderboard_name"),
                                                                   storeItem.Obj.GetString("extra_attributes"),
                                                                   Convert.ToInt32(storeItem.Obj.GetNumber("game_user_id"))
                                                                   )
                                                               );
                }
            }

            CloudLoginUtilities.HandleCallback(request, "Store Item has been removed", callback);
        }
示例#7
0
        private IEnumerator DownloadStoreItemsRoutine(bool chainedFromLogin, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Download Store Items: ");

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            var parameters = "?authentication_token=" + GetAuthenticationToken();


            var request = UnityWebRequest.Get(CloudLogin.GetBaseURL() + "/users/" + CurrentUser.id + "/game_user_store_items" + parameters);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Download Store Items Success: ");

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                var        game_user_store_items = json.GetArray("game_user_store_items");
                purchasedStoreItems.Clear();

                foreach (var item in game_user_store_items)
                {
                    purchasedStoreItems.Add(new CloudLoginStoreItem(
                                                item.Obj.GetString("name"),
                                                item.Obj.GetString("category"),
                                                item.Obj.GetString("description"),
                                                Convert.ToInt32(item.Obj.GetNumber("cost")),
                                                Convert.ToInt32(item.Obj.GetNumber("id"))));
                }
            }

            CloudLoginUtilities.HandleCallback(request, chainedFromLogin ? "Users has been signed in successfully" : "Users store items have been downloaded", callback);
        }
示例#8
0
        private IEnumerator AddLeaderboardEntryRoutine(string leaderboardName, int score, Dictionary <string, string> extraAttributes, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Adding Leaderboard Entry: " + leaderboardName + ": " + score.ToString());

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            List <string> extraAttributesList = new List <string>();

            foreach (KeyValuePair <string, string> entry in extraAttributes)
            {
                extraAttributesList.Add("\"" + entry.Key.ToString() + "\": " + entry.Value.ToString());
            }

            string  extraAttributesJson = "{" + String.Join(", ", extraAttributesList.ToArray()) + "}";
            WWWForm form = new WWWForm();

            form.AddField("authentication_token", GetAuthenticationToken());
            form.AddField("leaderboard_name", leaderboardName);
            form.AddField("extra_attributes", extraAttributesJson);
            form.AddField("score", score);

            var request = UnityWebRequest.Post(CloudLogin.GetBaseURL() + "/users/" + CurrentUser.id + "/add_leaderboard_entry", form);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Add Leaderboard Entry: " + leaderboardName + ": " + score);

                var data = request.downloadHandler.text;
            }

            CloudLoginUtilities.HandleCallback(request, "Leaderboard Entry Has Been Added", callback);
        }
示例#9
0
        private IEnumerator DownloadStoreItemsRoutine(Action <string, bool> callback = null)
        {
            Log("CloudLogin Downloading Store Items");
            var body    = "game_id=" + id + "&game_token=" + token;
            var request = UnityWebRequest.Get(baseURL + "/games/store_items?" + body);

            if (CloudLoginUser.CurrentUser.GetAuthenticationToken() != null)
            {
                request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());
            }

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                Log("CloudLogin Downloading Store Items Success");

                var        data       = request.downloadHandler.text;
                JSONObject json       = JSONObject.Parse(data);
                var        storeItems = json.GetArray("store_items");
                store.Clear();
                foreach (var storeItem in storeItems)
                {
                    store.Add(new CloudLoginStoreItem(
                                  storeItem.Obj.GetString("name"),
                                  storeItem.Obj.GetString("category"),
                                  storeItem.Obj.GetString("description"),
                                  Convert.ToInt32(storeItem.Obj.GetNumber("cost")),
                                  Convert.ToInt32(storeItem.Obj.GetNumber("id"))));
                }
            }
            else
            {
                CloudLoginUtilities.HandleCallback(request, "Game has failed to set up!", callback);
                Log("CloudLogin Downloading Store Items FAiled");
            }

            CloudLoginUtilities.HandleCallback(request, "Game has been set up!", callback);
        }
示例#10
0
        private IEnumerator DownloadAttributesRoutine(bool chainedFromLogin, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Get Attributes");

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            var parameters = "?authentication_token=" + GetAuthenticationToken();


            var request = UnityWebRequest.Get(CloudLogin.GetBaseURL() + "/users/" + this.id + "/game_user_attributes" + parameters);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Get Attributes Success");

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                var        game_user_attributes = json.GetArray("game_user_attributes");

                attributes.Clear();
                foreach (var attribute in game_user_attributes)
                {
                    attributes.Add(attribute.Obj.GetString("key"), attribute.Obj.GetString("value"));
                }
                DownloadStoreItems(chainedFromLogin, callback);
            }
            else
            {
                CloudLoginUtilities.HandleCallback(request, chainedFromLogin ? "Users has been signed in successfully" : "Users attributes have been downloaded", callback);
            }
        }
示例#11
0
        private IEnumerator SetAttributeRoutine(string key, string value, Action <string, bool> callback = null)
        {
            CloudLogin.Log("CloudLoginUser Set Attributes: " + key);

            if (CloudLogin.GetGameId() == null)
            {
                throw new CloudLoginException("Please set up your game with CloudLogin.SetUpGame before modifying users");
            }

            WWWForm form = new WWWForm();

            form.AddField("authentication_token", GetAuthenticationToken());
            form.AddField("key", key);
            form.AddField("value", value);

            var request = UnityWebRequest.Post(CloudLogin.GetBaseURL() + "/users/" + CurrentUser.id + "/add_game_user_attribute", form);

            request.SetRequestHeader("authentication_token", CloudLoginUser.CurrentUser.GetAuthenticationToken());

            yield return(request.SendWebRequest());

            if (CloudLoginUtilities.RequestIsSuccessful(request))
            {
                CloudLogin.Log("CloudLoginUser Set Attributes Success: " + key);

                var        data = request.downloadHandler.text;
                JSONObject json = JSONObject.Parse(data);
                attributes.Add(key, value);
                foreach (var attribute in attributes)
                {
                    print(attribute.Key + "," + attribute.Value);
                }
            }

            CloudLoginUtilities.HandleCallback(request, "Attribute has been added to user", callback);
        }