private IEnumerator Post() { WWWForm form = new WWWForm(); form.AddField("username", PhotonNetwork.LocalPlayer.NickName); form.AddField("score", _score); form.AddField("token", PhotonNetwork.LocalPlayer.CustomProperties["token"] as string); UnityWebRequest request = UnityWebRequest.Post(Data.SERVER_URL + "submit.php", form); yield return(request.SendWebRequest()); InformationPopup popup = PopupManagement.Instance.Add("PopupInformation", true) as InformationPopup; if (request.error != null) { popup.Initialize("Oops!", "Something went wrong...\r\nError: " + request.error); } else { if (request.downloadHandler.text != "-1") { PopupManagement.Instance.Remove(this); popup.Initialize("Success", "Your score was submitted!"); PhotonNetwork.Disconnect(); } else { popup.Initialize("Error", "Could not submit score."); Debug.Log(request.downloadHandler.text); } } }
private IEnumerator GetData() { WWWForm form = new WWWForm(); form.AddField("username", PhotonNetwork.LocalPlayer.NickName); UnityWebRequest request = UnityWebRequest.Post(Data.SERVER_URL + "get_account.php", form); yield return(request.SendWebRequest()); if (request.error != null) { InformationPopup popup = PopupManagement.Instance.Add("PopupInformation", true) as InformationPopup; popup.Initialize("Oops!", "Something went wrong...\r\nError: " + request.error); } else { if (request.downloadHandler.text != "-1") { _labelUsername.text = PhotonNetwork.LocalPlayer.NickName; _labelScore.text = request.downloadHandler.text; } } }
private IEnumerator Register() { WWWForm form = new WWWForm(); form.AddField("username", _inputName.text); form.AddField("password", Encryption.Md5Sum(_inputPassword.text)); UnityWebRequest request = UnityWebRequest.Post(Data.SERVER_URL + "register.php", form); yield return(request.SendWebRequest()); InformationPopup popup = PopupManagement.Instance.Add("PopupInformation", true) as InformationPopup; if (request.error != null) { popup.Initialize("Oops!", "Something went wrong...\r\nError: " + request.error); } else { if (request.downloadHandler.text == "1") { PopupManagement.Instance.Remove(this); popup.Initialize("Success", "You registered your username!"); } else { popup.Initialize("Unavailable", "Username is already in use."); } } }
private IEnumerator Login() { WWWForm form = new WWWForm(); form.AddField("username", _inputName.text); form.AddField("password", Encryption.Md5Sum(_inputPassword.text)); UnityWebRequest request = UnityWebRequest.Post(Data.SERVER_URL + "login.php", form); yield return(request.SendWebRequest()); if (request.error != null) { InformationPopup popup = PopupManagement.Instance.Add("PopupInformation", true) as InformationPopup; popup.Initialize("Oops!", "Something went wrong...\r\nError: " + request.error); } else { if (request.downloadHandler.text != "-1") { PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable { { "token", request.downloadHandler.text } }); PopupManagement.Instance.Remove(this); PopupManagement.Instance.Add("PopupConnection", true); PhotonNetwork.LocalPlayer.NickName = _inputName.text; PhotonNetwork.ConnectUsingSettings(); } else { InformationPopup popup = PopupManagement.Instance.Add("PopupInformation", true) as InformationPopup; popup.Initialize("Invalid credentials", "Username and/or password is incorrect."); } } }
private IEnumerator Get(string type) { _type = type; _buttonRefresh.interactable = false; _buttonAll.interactable = false; _buttonWeekly.interactable = false; _buttonMonthly.interactable = false; _buttonPersonal.interactable = false; _labelInfo.text = ""; UnityWebRequest request; if (type == "get_personal.php") { WWWForm form = new WWWForm(); form.AddField("username", PhotonNetwork.LocalPlayer.NickName); request = UnityWebRequest.Post(Data.SERVER_URL + _type, form); } else { request = UnityWebRequest.Get(Data.SERVER_URL + _type); } yield return(request.SendWebRequest()); if (request.error != null) { InformationPopup popup = PopupManagement.Instance.Add("PopupInformation") as InformationPopup; popup.Initialize("Oops!", "Unfortunately the highscores were unable to be retrieved from the server.\r\nError: " + request.error); } else { foreach (Transform entry in _content) { Destroy(entry.gameObject); } if (request.downloadHandler.text != "-1") { JSONNode json = JSON.Parse(request.downloadHandler.text); for (int i = 0; i < json.Count; i++) { GameObject go = Instantiate(Resources.Load <GameObject>("UIHighscoreEntry"), _content); UIHighscoreEntry ui = go.GetComponent <UIHighscoreEntry>(); ui.Initialize(i + 1 + ".", json[i]["username"], json[i]["score"]); } } else { _labelInfo.text = "No records available."; } } _buttonRefresh.interactable = true; _buttonAll.interactable = true; _buttonWeekly.interactable = true; _buttonMonthly.interactable = true; _buttonPersonal.interactable = true; }