/// <summary>
    /// Remove Character from Server.
    /// </summary>
    /// <param name="char_name">Character name.</param>
    /// <returns></returns>
    private IEnumerator DeleteCharacter(string char_name)
    {
        /*Create string disctionary to pass as arguments in the request body. */
        Dictionary <string, string> formFields = new Dictionary <string, string>();

        formFields.Add("uID", PlayerProfile.uID);
        formFields.Add("char_name", char_name);

        /* Create WebRequest and append token in order to access protected routes. */
        UnityWebRequest http = new UnityWebRequest();

        http = UnityWebRequest.Post(PlayerProfile.GetLoginServerAddress().ToString() + "/deleteCharacter", formFields);
        http.SetRequestHeader("Authorization", "Bearer " + PlayerProfile.token);

        /* Await for response. */
        yield return(http.SendWebRequest());

        if (http.isNetworkError || http.isHttpError)
        {
            Debug.Log(http.error);
        }
        else
        {
            ServerAssertion log = JsonUtility.FromJson <ServerAssertion>(http.downloadHandler.text);
        }
    }
    /// <summary>
    /// Upload new Character data to Server.
    /// </summary>
    /// <returns></returns>
    private IEnumerator Upload()
    {
        /*  Create Dictionary of strings to pass as arguments in the request body. */
        Dictionary <string, string> formFields = new Dictionary <string, string>();

        formFields.Add("username", PlayerProfile.uID);
        formFields.Add("char_name", charNameInputField.text);
        formFields.Add("char_hairId", hairStyle.ToString());
        formFields.Add("char_clothesId", clothes.ToString());
        formFields.Add("char_bodyId", body.ToString());


        // Create http post request
        UnityWebRequest http = UnityWebRequest.Post(PlayerProfile.GetLoginServerAddress().ToString() + "/createCharacter", formFields);

        http.SetRequestHeader("Authorization", "Bearer " + PlayerProfile.token);

        // Await for response
        yield return(http.SendWebRequest());

        if (http.isNetworkError || http.isHttpError)
        {
            /* Log error. */
            Debug.Log(http.error);
        }
        else
        {
            /* Parse Server response. */
            ServerAssertion log = JsonUtility.FromJson <ServerAssertion>(http.downloadHandler.text);

            /* If Server response is successfull return to previous menu. */
            if (log.success == true)
            {
                SceneManager.LoadScene("PlayerAccountScene");
            }
            else
            {
                /* TODO: Notify player. */
                Debug.Log(log.msg);
            }
        }
    }
Example #3
0
        public static IReadOnlyList <ClosedCompetitionEntity> GetClosedCompetitions(this ServerAssertion assertion)
        {
            var closedCompetitions = assertion.MainServices.GetRequiredService <IDataTable <LuckyDrawDataTablesSettings, ClosedCompetitionEntity> >() as InMemoryDataTable <LuckyDrawDataTablesSettings, ClosedCompetitionEntity>;

            return(closedCompetitions.AllEntities);
        }
Example #4
0
        public static List <UpdatedMessage> GetUpdatedMessages(this ServerAssertion assertion)
        {
            var factory = assertion.MainServices.GetRequiredService <IBotClientFactory>() as SimpleBotClientFactory;

            return(factory.UpdatedMessages);
        }