//! Get JSON for User
    IEnumerator GetUser(bool all)
    {
        UnityWebRequest uwr = UnityWebRequest.Get(Server.Address("read_user") + ZPlayerPrefs.GetString("id"));

        uwr.timeout = 10;
        yield return(uwr.SendWebRequest());

        if (uwr.isNetworkError)
        {
            Debug.Log("Error While Sending: " + uwr.error);
            NPBinding.UI.ShowToast("Communication Error. Please try again later.", eToastMessageLength.SHORT);
        }
        else
        {
            if (User.CreateUserFromJSON(uwr.downloadHandler.text).GetID() == "")
            {
                yield break;
            }
            UpdateSessions.JSON_Session("user", uwr.downloadHandler.text);
            if (all)
            {
                yield return(StartCoroutine(GetPlayer()));
            }
        }
        uwr.Dispose();
        StopCoroutine(GetUser(all));
    }
Пример #2
0
    //! PUT ideals into server for comparisons
    private IEnumerator PutIdeals(string json)
    {
        UnityWebRequest uwr = new UnityWebRequest(Server.Address("submit_ideals") + UserSession.user_session.user.GetID(), "PUT");

        byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
        uwr.uploadHandler   = (UploadHandler) new UploadHandlerRaw(jsonToSend);
        uwr.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        uwr.SetRequestHeader("Content-Type", "application/json");

        yield return(uwr.SendWebRequest());

        if (uwr.isNetworkError)
        {
            Debug.Log("Error While Sending: " + uwr.error);
            NPBinding.UI.ShowToast("Communication Error. Please try again later.", eToastMessageLength.SHORT);
        }
        else
        {
            if (uwr.downloadHandler.text == Server.fail_auth)
            {
                NPBinding.UI.ShowToast("Server Error. Please try again.", eToastMessageLength.SHORT);
            }
            else
            {
                UpdateSessions.JSON_Session("player", uwr.downloadHandler.text);
                NPBinding.UI.ShowToast("Welcome to The Battle Within!", eToastMessageLength.SHORT);
                gameObject.AddComponent <ChangeScene>().Forward("Overworld");
            }
        }
        StopCoroutine(PutIdeals(json));
    }
Пример #3
0
 //! Check if valid login, then update User object
 public static bool CheckLogin(string output)
 {
     if (output == null || output == "")
     {
         return(false);
     }
     else
     {
         UpdateSessions.JSON_Session("user", output);
         ZPlayerPrefs.SetString("id", UserSession.user_session.user.id);
     }
     return(true);
 }
Пример #4
0
    //! Keep checking if twitter linkage was OK - until timeout (4s after they return from twitter page)
    private IEnumerator TryTwitter()
    {
        int repeats = 0;

        while (repeats < 3)
        {
            UnityWebRequest uwr = UnityWebRequest.Get(Server.Address("read_user") + UserSession.user_session.user.GetID());
            yield return(uwr.SendWebRequest());

            if (uwr.isNetworkError)
            {
                Debug.Log("Error While Sending: " + uwr.error);
                NPBinding.UI.ShowToast("Communication Error. Please try again.", eToastMessageLength.SHORT);
                yield break;
            }
            else
            {
                UpdateSessions.JSON_Session("user", uwr.downloadHandler.text);
                if (Server.CheckTwitter())
                {
                    EndSession();
                    yield break;
                }
                else
                {
                    Debug.Log("Not registered yet: " + uwr.downloadHandler.text);
                    repeats++;
                    yield return(new WaitForSeconds(1.3f));
                }
            }

            if (repeats == 2 && !Server.CheckTwitter())
            {
                EndSession();
                ShowPopup("fail_connection");
            }
        }
        StopCoroutine(TryTwitter());
    }
    //! GET JSON for Player
    IEnumerator GetPlayer()
    {
        UnityWebRequest uwr = UnityWebRequest.Get(Server.Address("players") + ZPlayerPrefs.GetString("id"));

        uwr.timeout = 10;
        yield return(uwr.SendWebRequest());

        if (uwr.isNetworkError)
        {
            Debug.Log("Error While Sending: " + uwr.error);
            NPBinding.UI.ShowToast("Communication Error. Please try again later.", eToastMessageLength.SHORT);
        }
        else
        {
            UpdateSessions.JSON_Session("player", uwr.downloadHandler.text);
        }
        uwr.Dispose();

        Invoke("InvokableGetPlaysLeft", 0.3f);
        Invoke("InvokableGetRankPoints", 0.4f);

        StopCoroutine(GetPlayer());
    }