IEnumerator CheckIfGroupExists(string groupName, string password) { screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("exists/" + groupName + "/")); //yield return result = WWWUtils.DoWebRequestWithSpecificURL("http://localhost/contagotas/group/exists/" + groupName + "/" ); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR")) { screenManager.ShowErrorScreen("error creating group:" + result.text); yield break; } if (result.text == "true") { screenManager.ShowCreateScreen(); ShowGroupExistentErrorScreen(); } else { StartCoroutine(CreateGroup(groupName, password)); } }
IEnumerator HasGroup(int userID) { ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("hasGroup/" + userID + "/")); Debug.Log("url result = " + result.text); if (result.text == "true") { yield return(result = WWWUtils.DoWebRequest("list_by_user_id/" + userID + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR")) { ShowErrorScreen("error checking group:" + result.text); yield break; } else { string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <GroupData> account = JsonConvert.DeserializeObject <List <GroupData> >(json); groupInfo = account[0]; existingGroupScreenManager.ShowExistingGroup(groupInfo); } } else { inviteReceivedScreenManager.StartSearchForInvites(); } }
IEnumerator JoinWithPassword(int groupID, string password) { StringBuilder sb = new StringBuilder(); sb.Append("data={"); sb.Append("\"groupid\""); sb.Append(":\""); sb.Append(groupID); sb.Append("\""); sb.Append(","); sb.Append("\"userid\""); sb.Append(":\""); sb.Append(PlayerPrefs.GetInt("user_id")); sb.Append("\""); sb.Append(","); sb.Append("\"password\""); sb.Append(":\""); sb.Append(password); sb.Append("\""); sb.Append("}"); WWW result; screenManager.ShowLoadingScreen(); yield return(result = WWWUtils.DoWebRequest("join/", sb.ToString())); ConfirmJoinPasswordInput.text = ""; Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("Error joining group ->" + result.text); } else { string data = StringUtils.DecodeBytesForUTF8(result.bytes); if (data == "wrong password") { ConfirmJoinPasswordInput.text = ""; joinConfirmFeedback.text = LocalizationManager.GetTranslation("GroupWrongPass"); screenManager.ShowGroup(ScreenType.CONFIRM_JOIN_GROUP); Debug.Log("Wrong Password"); } else { List <GroupData> account = JsonConvert.DeserializeObject <List <GroupData> >(data); GroupData groupData = account[0]; PlayerPrefs.SetInt("group_id", groupData.Id); Retry(); } } }
IEnumerator HasGroup() { WWW result; yield return(result = WWWUtils.DoWebRequest("hasGroup/" + PlayerPrefs.GetInt("user_id") + "/")); Debug.Log("url result = " + result.text); if (result.text == "false") { StartCoroutine(CheckInvite()); } }
IEnumerator StartSearchGroup() { if (groupToSearchInput.text == "") { yield break; } screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("list_by_name/" + groupToSearchInput.text + "/")); Debug.Log("url result = " + result.text); if (result.text == "[]") { screenManager.ShowErrorScreen(LocalizationManager.GetTranslation("GroupNotFound")); yield break; } if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("error searching group:" + result.text); yield break; } screenManager.ShowGroup(ScreenType.JOIN_GROUP); string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <GroupData> foundGroups = JsonConvert.DeserializeObject <List <GroupData> >(json); foreach (var item in screenManager.temporaryObjsList) { Destroy(item); } screenManager.temporaryObjsList.Clear(); foreach (var group in foundGroups) { GameObject item = Instantiate(screenManager.GroupObjectPrefabs, searchResultParent); screenManager.temporaryObjsList.Add(item); GroupInfo groupInfoScript = item.GetComponent <GroupInfo>(); groupInfoScript.joinGroupClicked += HandleJoinClickWithPassword; groupInfoScript.SetupGroupInfo(group.Name, group.Score, group.Id, false); } }
IEnumerator AddScore(int groupid, int score) { WWW result; yield return(result = WWWUtils.DoWebRequest("score/" + groupid.ToString() + "/" + score.ToString() + "/" + PlayerPrefs.GetInt("user_id") + "/")); Debug.Log("url result = " + result.text); if (result.text == "success") { Debug.Log("Inserido score"); } else { Debug.Log("ERROR:" + result.text); } }
IEnumerator DeclineInvite(int inviteId) { WWW result; yield return(result = WWWUtils.DoWebRequest("invite/deny/" + inviteId + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("Error declining invite ->" + result.text); } else { screenManager.CheckIfHasGroup(); } }
IEnumerator SearchForInvites() { screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("invite/check/" + PlayerPrefs.GetInt("user_id") + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("error checking invite:" + result.text); yield break; } string jsonDecoded = StringUtils.DecodeBytesForUTF8(result.bytes); List <InviteData> invites = JsonConvert.DeserializeObject <List <InviteData> >(jsonDecoded); foreach (var obj in screenManager.temporaryObjsList) { Destroy(obj); } screenManager.temporaryObjsList.Clear(); if (invites.Count > 0) { foreach (var invite in invites) { GameObject item = Instantiate(InvitePrefab, InviteGroupParent); screenManager.temporaryObjsList.Add(item); InviteObject inviteObj = item.GetComponent <InviteObject> (); inviteObj.acceptButtonClicked += HandleAcceptInvite; inviteObj.declineButtonClicked += HandleDeclineInvite; inviteObj.closeButtonClicked += HandleCloseButtonClicked; inviteObj.SetupInviteInfo(invite.sender_name, invite.group_name, invite.id_invite); } screenManager.ShowGroup(ScreenType.RECEIVE_INVITES); } else { screenManager.ShowGroup(ScreenType.NEW_GROUP); } }
IEnumerator LoadRanking() { LoadingContent.SetActive(true); MyGroupContent.SetActive(false); RankingContent.SetActive(false); SetButtonOn(rankingButton); SetButtonOff(groupButton); WWW result; yield return(result = WWWUtils.DoWebRequest("score/top/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR")) { screenManager.ShowErrorScreen("error leaving group:" + result.text); yield break; } else { //clearing all texts for (int i = 0; i < 8; i++) { GroupsName [i].text = ""; GroupsScore [i].text = ""; } string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <GroupData> rankedGroups = JsonConvert.DeserializeObject <List <GroupData> >(json); int index = 0; foreach (var group in rankedGroups) { GroupsName [index].text = group.Name; GroupsScore [index].text = group.Score.ToString(); index++; } LoadingContent.SetActive(false); MyGroupContent.SetActive(false); RankingContent.SetActive(true); } }
IEnumerator GetGroupInfo() { SetButtonOn(groupButton); SetButtonOff(rankingButton); LoadingContent.SetActive(true); MyGroupContent.SetActive(false); RankingContent.SetActive(false); WWW result; yield return(result = WWWUtils.DoWebRequest("score/get_detailed/" + groupData.Id + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("error getting group info:" + result.text); yield break; } string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <PlayerInfo> foundPlayers = JsonConvert.DeserializeObject <List <PlayerInfo> >(json); foreach (var item in screenManager.temporaryObjsList) { Destroy(item); } screenManager.temporaryObjsList.Clear(); foreach (var player in foundPlayers) { GameObject item = Instantiate(PlayerDataObject, playerDataParentTransform); screenManager.temporaryObjsList.Add(item); PlayerDetailedInfo playerInfo = item.GetComponent <PlayerDetailedInfo>(); playerInfo.SetupPlayerInfo(player.Name, player.Score); } LoadingContent.SetActive(false); MyGroupContent.SetActive(true); RankingContent.SetActive(false); screenManager.ShowGroup(ScreenType.EXISTING_GROUP); }
IEnumerator LeaveGroup(int userID) { screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("leave/" + userID + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("SUCCESS")) { PlayerPrefs.DeleteKey("group_id"); screenManager.ShowGroup(ScreenType.NEW_GROUP); } else { screenManager.ShowErrorScreen("error leaving group:" + result.text); yield break; } }
IEnumerator CreateGroup(string groupName, string password) { StringBuilder sb = new StringBuilder(); sb.Append("data={"); sb.Append("\"name\""); sb.Append(":\""); sb.Append(groupName); sb.Append("\""); sb.Append(","); sb.Append("\"password\""); sb.Append(":\""); sb.Append(password); sb.Append("\""); sb.Append("}"); screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("create/", sb.ToString())); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR")) { screenManager.ShowErrorScreen("error creating group:" + result.text); yield break; } int groupID; if (!int.TryParse(result.text, out groupID)) { screenManager.ShowErrorScreen("error on group id:" + result.text); yield break; } StartCoroutine(joinManager.Join(groupID)); }
IEnumerator AcceptInvite(int inviteId) { screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("invite/accept/" + inviteId + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("Error accepting invite ->" + result.text); } else { string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <GroupData> account = JsonConvert.DeserializeObject <List <GroupData> >(json); GroupData groupData = account[0]; PlayerPrefs.SetInt("group_id", groupData.Id); Retry(); } }
public IEnumerator Join(int groupID) { screenManager.ShowLoadingScreen(); WWW result; yield return(result = WWWUtils.DoWebRequest("join/" + groupID + "/" + PlayerPrefs.GetInt("user_id") + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { screenManager.ShowErrorScreen("Error joining group ->" + result.text); } else { string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <GroupData> account = JsonConvert.DeserializeObject <List <GroupData> >(json); GroupData groupData = account[0]; PlayerPrefs.SetInt("group_id", groupData.Id); screenManager.ShowExistingGroup(groupData); } }
public IEnumerator CheckInvite() { WWW result; yield return(result = WWWUtils.DoWebRequest("invite/check/" + PlayerPrefs.GetInt("user_id") + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR") || result.text.ToUpper().Contains("TIMEOUT")) { Debug.LogError("error checking invite:" + result.text); yield break; } string jsonDecoded = StringUtils.DecodeBytesForUTF8(result.bytes); List <InviteData> invites = JsonConvert.DeserializeObject <List <InviteData> >(jsonDecoded); if (invites.Count > 0) { notificationAssets.SetActive(true); notificationNumber.text = invites.Count.ToString(); } }