/// <summary> /// Posts the player name, player university team to the corresponding account using account ID /// </summary> /// <returns></returns> IEnumerator UploadPlayerRoutine() { WWWForm form = new WWWForm(); form.AddField("player_name", GameSaveUtility.GetPlayerName()); form.AddField("player_team", GameSaveUtility.GetUniversity()); form.AddField("player_ID", GameSaveUtility.GetID()); using (UnityWebRequest www = UnityWebRequest.Post(path + "addplayer.php", form)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); StringBuilder sb = new StringBuilder(); foreach (System.Collections.Generic.KeyValuePair <string, string> dict in www.GetResponseHeaders()) { sb.Append(dict.Key).Append(": \t[").Append(dict.Value).Append("]\n"); } // Print Headers #if (UNITY_EDITOR) Debug.Log(sb.ToString()); #endif if (www.GetResponseHeaders().Count > 0 && www.GetResponseHeaders().ContainsKey("userAdded")) { if (www.GetResponseHeaders()["userAdded"] == "true") { Debug.Log("User added succesful"); } else { Debug.Log("User added failed"); } } else if (www.GetResponseHeaders().Count > 0 && www.GetResponseHeaders().ContainsKey("userUpdated")) { if (www.GetResponseHeaders()["userUpdated"] == "true") { Debug.Log("User updated succesful"); } else { Debug.Log("User updated failed"); } } } } }
/// <summary> /// Posts the earned stars to the player university using the account ID /// </summary> /// <returns></returns> IEnumerator UpdateLeaderboardRoutine() { WWWForm form = new WWWForm(); form.AddField("player_id", GameSaveUtility.GetID()); form.AddField("player_team", GameSaveUtility.GetUniversity()); form.AddField("earnedStars", ObjectiveUtility.EarnedStars); // php will add the earned stars to the total stars of the player using (UnityWebRequest www = UnityWebRequest.Post(path + "updateleaderboard.php", form)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); StringBuilder sb = new StringBuilder(); foreach (System.Collections.Generic.KeyValuePair <string, string> dict in www.GetResponseHeaders()) { sb.Append(dict.Key).Append(": \t[").Append(dict.Value).Append("]\n"); } // Print Headers #if (UNITY_EDITOR) Debug.Log(sb.ToString()); #endif if (www.GetResponseHeaders().Count > 0 && www.GetResponseHeaders().ContainsKey("leaderboardUpdated")) { if (www.GetResponseHeaders()["leaderboardUpdated"] == "true") { Debug.Log("Team score updating succesfully"); // Print Body #if (UNITY_EDITOR) Debug.Log(www.downloadHandler.text); #endif } else { Debug.Log("Score saving failed"); } } } } }