Пример #1
0
    public IEnumerator storeDataRequest(string _email, string _password, Player _player)
    {
        // Create a form object
        WWWForm form = new WWWForm();

        form.AddField("email", _email);
        form.AddField("password", _password);
        form.AddField("userdata", _player.userdata);
        form.AddField("action", "store");

        // Create a download object
        WWW returned = new WWW(account_api, form);

        // Wait until the download is done
        yield return(returned);

        if (!string.IsNullOrEmpty(returned.error))
        {
            Debug.Log("Error downloading: " + returned.error);
            yield break;
        }
        // Debug.Log(returned.text);
        NetworkResponse             response = JsonUtility.FromJson <NetworkResponse>(returned.text);
        Dictionary <string, string> results  = response.ToDictionary();

        if (results["success"] != "true")
        {
            Debug.Log(results["errors"]);
        }
    }
Пример #2
0
    IEnumerator sendRegisterRequest(string email, string username, string password, string password_confirm)
    {
        // Create a form object
        WWWForm form = new WWWForm();

        form.AddField("email", email);
        form.AddField("username", username);
        form.AddField("password", password);
        form.AddField("password_confirm", password_confirm);
        form.AddField("action", "register");

        // Create a download object
        WWW returned = new WWW(account_api, form);

        // Wait until the download is done
        yield return(returned);

        //blank password fields
        input_register_password.text        = "";
        input_register_confirmPassword.text = "";

        if (!string.IsNullOrEmpty(returned.error))
        {
            //Account Not Created, another error occurred
            goToPart(1);  //back to register UI
            register_error.text = "Database Error. Try again later.";
            Debug.Log("Error downloading: " + returned.error);
            yield break;
        }
        //   Debug.Log(returned.text);
        NetworkResponse             response = JsonUtility.FromJson <NetworkResponse>(returned.text);
        Dictionary <string, string> results  = response.ToDictionary();

        if (results["success"] == "true" && response.user != null)
        {
            //Account created successfully

            blankErrors();
            goToPart(2);  //show logged in UI

            string userdata = string.IsNullOrEmpty(response.user.userdata) ? "{\"kills\":0,\"deaths\":0}" : response.user.userdata;
            //blank username field
            input_register_username.text = "";

            UserAccountManager.singleton.LogIn(response.user.email, response.user.username, password, userdata);
        }
        else
        {
            register_error.text = results["errors"];
            goToPart(1);  //back to register UI
        }
    }
Пример #3
0
    public IEnumerator getDataRequest(string _email, string _password, DataReceivedEvent onUserData)
    {
        // Create a form object
        WWWForm form = new WWWForm();

        form.AddField("email", _email);
        form.AddField("password", _password);
        form.AddField("action", "login");

        // Create a download object
        WWW returned = new WWW(account_api, form);

        // Wait until the download is done
        yield return(returned);

        if (!string.IsNullOrEmpty(returned.error))
        {
            Debug.Log("Error downloading: " + returned.error);
            yield break;
        }
        //  Debug.Log(returned.text);
        NetworkResponse             response = JsonUtility.FromJson <NetworkResponse>(returned.text);
        Dictionary <string, string> results  = response.ToDictionary();

        if (results["success"] == "true" && response.user != null)
        {
            Dictionary <string, string> userData = new Dictionary <string, string>();
            int kills  = 0;
            int deaths = 0;
            if (response.user.userdata.Length > 0)
            {
                UserInfo _userData = JsonUtility.FromJson <UserInfo>(response.user.userdata);
                kills  = _userData.getKills();
                deaths = _userData.getDeaths();
            }
            userData["kills"]  = kills.ToString();
            userData["deaths"] = deaths.ToString();
            onUserData.Invoke(userData);
        }
    }