IEnumerator LoadUserRanking() { WWW result; yield return(result = WWWUtils.DoWebRequestWithSpecificURL("http://www.contagotas.online/services/user/score/check/" + PlayerPrefs.GetInt("user_id").ToString() + "/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR")) { screenManager.ShowErrorScreen("error loading user score:" + result.text); yield break; } else { string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <PlayerData> player = JsonConvert.DeserializeObject <List <PlayerData> >(json); playerName.text = player[0].playerName; playerScore.text = player[0].playerPoints.ToString(); UserData.userData.playerData.playerPoints = player[0].playerPoints; UserData.userData.Save(); StartCoroutine(LoadRanking()); } }
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(); } }
private static void BuilderPost(string uri, Hashtable data) { var statusUrl = EnvironmentUtils.Get("BUILD_STATUS_URL", string.Empty); if (!string.IsNullOrEmpty(statusUrl)) { var jsonData = EB.Encoding.GetBytes(EB.JSON.Stringify(data)); var url = statusUrl + uri; //Hashtable headers = new Hashtable(); //headers["Content-Type"] = "application/json"; System.Collections.Generic.Dictionary <string, string> headers = new System.Collections.Generic.Dictionary <string, string>(); headers.Add("Content-Type", "application/json"); //headers["Content-Length"] = jsonData.Length; // moko: unity 4.3 will handle www raw data lenght for you //EB.Debug.Log("Headers: {0}", headers); var www = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST); www.uploadHandler = (UploadHandler) new UploadHandlerRaw(jsonData); www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); www.SetRequestHeader("Content-Type", "application/json"); //var www = new WWW(url, jsonData, headers); //EB.Debug.Log("Status: " + www.url); WWWUtils.WaitOnWWW(www, false); //EB.Debug.Log("result: " + www.text); } else { Debug.LogWarning("Can not fetch env var 'BUILD_STATUS_URL' for posting builder email"); } }
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)); } }
public static bool UploadTranslations() { string stoken = WWWUtils.AdminLogin(); if (string.IsNullOrEmpty(stoken)) { return(false); } var url = WWWUtils.AdminUrl("/localization/upload/english"); EB.Localizer.Clear(); var result = LoadAllFromResources(EB.Language.English, new string[] { "all" }); // fixup all the \n var data = new Hashtable(); foreach (var entry in result) { data[entry.Key] = entry.Value.Trim().Replace("\n", "\\n"); } EB.Debug.Log(" source string count: " + data.Count); var form = new WWWForm(); form.AddField("body", EB.JSON.Stringify(data)); form.AddField("stoken", stoken); form.AddField("format", "json"); return(WWWUtils.PostJson(url, form) != null); }
public static Dictionary <EB.Language, string> DownloadTranslations() { string stoken = WWWUtils.AdminLogin(); if (string.IsNullOrEmpty(stoken)) { return(null); } var transData = new Dictionary <EB.Language, string>(); var langs = new List <EB.Language>(); langs.Add(EB.Language.English); langs.Add(EB.Language.ChineseSimplified); langs.Add(EB.Language.ChineseTraditional); foreach (var lang in langs) { var code = EB.Localizer.GetSparxLanguageCode(lang); var url = WWWUtils.AdminUrl(string.Format("/localization/export/{0}?stoken={1}&format=csv&status=1&code=1", code, stoken)); var csv = WWWUtils.Get(url); if (string.IsNullOrEmpty(csv)) { Debug.LogWarning("LocalizationUtils.WWWUtils.Get(" + url + ") = null"); continue; } csv = csv.Replace(@"\\n", @"\n"); transData.Add(lang, csv); } return(transData); }
static void UploadContentManifest(WWWUtils.Environment env, string url, int enabled) { var stoken = WWWUtils.AdminLogin(env); var postUrl = WWWUtils.GetAdminUrl(env) + "/bundlemanager/content/from-manifest?stoken=" + stoken; var form = new WWWForm(); form.AddField("url", url); form.AddField("enabled", enabled); WWWUtils.Post(postUrl, form); }
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); } }
public static string PutData(byte[] bytes, string name, string path) { var key = Path.Combine(BasePath, path); Debug.LogFormat("S3 Put: {0} -> {1}:/{2}", name, Bucket, key); if (string.IsNullOrEmpty(Bucket)) { return(string.Empty); } WWWForm form = new WWWForm(); form.AddField("key", key); form.AddField("acl", "public-read"); form.AddField("AWSAccessKeyId", AccessKeyId); form.AddField("Policy", Policy); form.AddField("Signature", Signature); form.AddBinaryData("file", bytes, name); var contentType = MimeUtils.GetMimeType(Path.GetExtension(name)); if (!string.IsNullOrEmpty(contentType)) { form.AddField("Content-Type", contentType); } // make sure to upload the md5 form.AddField("Content-MD5", CalculateMD5(bytes)); var url = "http://" + Bucket + ".s3.amazonaws.com/"; var result = WWWUtils.Post(url, form); Debug.LogFormat("key {0} result: {1}", key, result); if (result.Contains("Error")) { throw new System.Exception("S3 upload failed! key: " + key + " result: " + result); } // GC System.GC.Collect(); // return the url return(url + key); }
IEnumerator AddUserScore(int score) { WWW result; yield return(result = WWWUtils.DoWebRequestWithSpecificURL("http://www.contagotas.online/services/user/score/" + PlayerPrefs.GetInt("user_id").ToString() + "/" + score.ToString() + "/")); Debug.Log("url result = " + result.text); if (result.text == "success") { ///save player points UserData.userData.playerData.playerPoints += score; UserData.userData.Save(); } else { Debug.Log("ERROR:" + result.text); } }
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); }
static void UploadApkFiles(string apkPath, WWWUtils.Environment env) { try { var tmpDir = "/tmp/apk"; GeneralUtils.DeleteDirectory(tmpDir, true); // mko: cleaning up build folder Directory.CreateDirectory(tmpDir); // unzip var res = CommandLineUtils.Run("/usr/bin/unzip", string.Format("-d {0} {1}", tmpDir, apkPath)); Debug.Log(res); // generate the app.dll var files = new List <string>(Directory.GetFiles("/tmp/apk/assets/bin/Data/Managed", "*.dll", SearchOption.TopDirectoryOnly)); files.Sort(System.StringComparer.OrdinalIgnoreCase); List <byte> bytes = new List <byte>(); foreach (string filePath in files) { Debug.Log("Adding file " + filePath); bytes.AddRange(File.ReadAllBytes(filePath)); } Debug.Log("MSIL size is " + EB.Localizer.FormatNumber(bytes.Count, true)); WWWForm form = new WWWForm(); form.AddBinaryData("data", bytes.ToArray(), "data"); form.AddField("version", EB.Version.GetVersion()); form.AddField("platform", "android"); form.AddField("sha1", EB.Encoding.ToBase64String(EB.Digest.Sha1().Hash(bytes.ToArray()))); var stoken = WWWUtils.AdminLogin(env); var postUrl = WWWUtils.GetAdminUrl(env) + "/protect/upload?stoken=" + stoken; res = WWWUtils.Post(postUrl, form); Debug.Log("version: " + res); } catch (System.Exception e) { Debug.Log("Build Failed: exception: " + e.ToString()); Failed(e); } }
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); } }
private IEnumerator DownloadIntoOrLoadWebPFromFolderRoutine(string folderPath, MonoBehaviour context, string url, Image image, Action onSuccess = null, Action <string> onError = null) { yield return(new WaitForEndOfFrame()); string filePath = ImageDownloader.GetImageFilePathFromUrl(url, folderPath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (File.Exists(filePath)) { LoadTextureFromWebP(File.ReadAllBytes(filePath)); onSuccess?.Invoke(); } else { WWWUtils.LoadBinaryFromWWW(this, url, bytes => { LoadTextureFromWebP(bytes); File.WriteAllBytes(filePath, bytes); onSuccess?.Invoke(); }); } }
IEnumerator LoadRanking() { WWW result; yield return(result = WWWUtils.DoWebRequestWithSpecificURL("http://www.contagotas.online/services/user/score/top10/")); Debug.Log("url result = " + result.text); if (result.text.ToUpper().Contains("ERROR")) { screenManager.ShowErrorScreen("error loading user ranking:" + result.text); yield break; } else { //clearing all texts for (int i = 0; i < 10; i++) { PlayersName [i].text = ""; PlayersScore [i].text = ""; } string json = StringUtils.DecodeBytesForUTF8(result.bytes); List <PlayerData> rankedPlayers = JsonConvert.DeserializeObject <List <PlayerData> >(json); int index = 0; foreach (var playerData in rankedPlayers) { PlayersName [index].text = playerData.playerName; PlayersScore [index].text = playerData.playerPoints.ToString(); index++; } screenManager.ShowScreen(PlayerRankingScreenType.PLAYER_RANKING_SCREEN); } }
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(); } }