// Obtem o resultado do vinculo com o Facebook private IEnumerator handleLink() { #if UNITY_IPHONE EtceteraBinding.hideActivityView(); #elif UNITY_ANDROID EtceteraAndroid.hideProgressDialog(); #endif //GameGUI.game_native.stopLoading(); // Numero maximo de tentativas int max_attempts = 5; WWW conn = null; WWWForm form = new WWWForm(); form.AddField("token", Save.GetString(PlayerPrefsKeys.TOKEN.ToString())); form.AddField("device", SystemInfo.deviceUniqueIdentifier.Replace("-", "")); while (max_attempts > 0) { conn = new WWW(Flow.URL_BASE + "login/facebook/fblresult.php", form); yield return(conn); if (conn.error != null || conn.text != "") { break; } max_attempts--; yield return(new WaitForSeconds(1)); } if (max_attempts == 0 || conn.error != null) { Debug.LogError("Server error: " + conn.error); sendToCallback(GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE, null); yield break; } JSonReader reader = new JSonReader(); IJSonObject data = reader.ReadAsJSonObject(conn.text); // Salva o token if (data.Contains("token")) { GameToken.save(data); } // Verifica se houve erro if (data == null || data.Contains("error")) { Debug.LogError("Json error: " + conn.text); string message; switch (data["error"].ToString()) { case "access_denied": message = "You have to authorize our app on Facebook."; break; case "facebook_already_used": message = "Your Facebook is already in use on another account."; break; case "different_account": message = "Your account already has another Facebook linked."; break; default: message = GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE; break; } sendToCallback(message, null); yield break; } data = data["result"]; Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), data["fbtoken"].ToString(), true); sendToCallback(null, data); }
// Obtem as informacoes do Facebook no servidor private IEnumerator GetFacebookInfo() { Debug.Log("pegando info face"); // Numero maximo de tentativas int max_attempts = 5; WWW conn = null; WWWForm form = new WWWForm(); form.AddField("device", SystemInfo.deviceUniqueIdentifier.Replace("-", "")); form.AddField("authentication", authentication); while (max_attempts > 0) { conn = new WWW(Flow.URL_BASE + "login/facebook/fbinfo.php", form); yield return(conn); if (conn.error != null || conn.text != "") { break; } max_attempts--; yield return(new WaitForSeconds(1)); } Flow.game_native.stopLoading(); if (max_attempts == 0 || conn.error != null) { Debug.LogError("Server error: " + conn.error); Flow.game_native.showMessage("Error", GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE); yield break; } JSonReader reader = new JSonReader(); IJSonObject data = reader.ReadAsJSonObject(conn.text); if (data == null || data.Contains("error")) { Debug.LogError("Json error: " + conn.text); Flow.game_native.showMessage("Error", GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE); yield break; } Debug.Log("data: " + data); GameToken.save(data); Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), data["fbtoken"].ToString(), true); Save.Set(PlayerPrefsKeys.NAME.ToString(), data["username"].ToString(), true); Save.Set(PlayerPrefsKeys.ID.ToString(), data["user_id"].ToString(), true); if (!data["email"].IsNull) { Save.Set(PlayerPrefsKeys.EMAIL.ToString(), data["email"].ToString(), true); } if (!data["first_name"].IsNull) { Save.Set(PlayerPrefsKeys.FIRST_NAME.ToString(), data["first_name"].ToString(), true); } if (!data["last_name"].IsNull) { Save.Set(PlayerPrefsKeys.LAST_NAME.ToString(), data["last_name"].ToString(), true); } if (!data["location"].IsNull) { Save.Set(PlayerPrefsKeys.LOCATION.ToString(), data["location"].ToString(), true); } if (!data["gender"].IsNull) { Save.Set(PlayerPrefsKeys.GENDER.ToString(), data["gender"].ToString(), true); } if (data["new_account"].StringValue == "1") { Flow.header.coins += Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsFacebook; } if (!data["birthday"].IsNull) { string day, month, year; string[] separator = { "-" }; string[] birthday = data["birthday"].StringValue.Split(separator, System.StringSplitOptions.None); day = birthday[2]; month = birthday[1]; year = birthday[0]; Save.Set(PlayerPrefsKeys.DATE_DAY.ToString(), day, true); Save.Set(PlayerPrefsKeys.DATE_MONTH.ToString(), month, true); Save.Set(PlayerPrefsKeys.DATE_YEAR.ToString(), year, true); } // Atualiza token da FacebookAPI if (Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) { facebook.SetToken(Save.GetString(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())); } Save.SaveAll(); if (buttonCliked == EndLevelButtonClicked.Like) { StartLike(); } else { FixScreenButtons(); } buttonCliked = EndLevelButtonClicked.None; }
// Obtem as informacoes do Facebook no servidor private IEnumerator getLoginResult(string auth, object state, LoginCallback callback) { // Numero maximo de tentativas int max_attempts = 5; WWW conn = null; WWWForm form = new WWWForm(); form.AddField("device", SystemInfo.deviceUniqueIdentifier.Replace("-", "")); form.AddField("authentication", auth); while (max_attempts > 0) { conn = new WWW(Flow.URL_BASE + "login/facebook/fbinfo.php", form); yield return(conn); if (conn.error != null || conn.text != "") { break; } max_attempts--; yield return(new WaitForSeconds(1)); } if (max_attempts == 0 || conn.error != null) { Debug.LogError("Server error: " + conn.error); yield break; } JSonReader reader = new JSonReader(); IJSonObject data = reader.ReadAsJSonObject(conn.text); if (data == null || data.Contains("error")) { Debug.LogError("Json error: " + conn.text); yield break; } GameToken.save(data); // Verifica se houve erro if (data.Contains("fb_error_reason") && data["fb_error_reason"].ToString() == "user_denied") { // Up Top Fix Me //GameGUI.game_native.showMessage("Error", "You need to authorize our app on Facebook."); // Redireciona para o login caso necessario // Up Top Fix Me //if (Scene.GetCurrent() != GameGUI.components.login_scene) //Scene.Login.Load(Info.firstScene); yield break; } // Salva o token do Facebook Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), data["fbtoken"].ToString(), true); // Atualiza token da FacebookAPI FacebookAPI facebook = new FacebookAPI(); facebook.UpdateToken(); if (callback != null) { callback(state); } }
// Processa o resultado da conexao de login private void connectionResult(string error, WWW data) { //Debug.Log("resultado chegou"); JSonReader reader = new JSonReader(); IJSonObject json = null; //Debug.Log("data: "+data.text); // Tenta ler o retorno if (data == null) { error = "json_error"; } else { try { if (error == null) { json = reader.ReadAsJSonObject(data.text); } } catch (JSonReaderException) { error = "json_error"; } } // Verifica se houve erro if (error == null && json.Contains("error")) { error = json["error"].ToString(); } Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; // Trata o erro if (error != null) { switch (error) { case "empty_email": error = "Please inform an e-mail."; break; case "invalid_email": error = "Invalid e-mail. Please try another account."; break; default: error = GameJsonAuthConnection.DEFAULT_ERROR_MESSAGE; break; } Flow.game_native.showMessage("Error", error); return; } if (json.Contains("ask") && json["ask"].ToString() == "password") { passwordDialog.SetActive(true); UIManager.instance.FocusObject = passwordField; return; } else if (json.Contains("ask") && json["ask"].ToString() == "wrong_password") { passwordDialog.SetActive(true); UIManager.instance.FocusObject = passwordField; passwordDialog.transform.FindChild("BackgroundBorder").FindChild("BackgroundTitle").FindChild("TitlePanel").FindChild("Title").GetComponent <SpriteText>().Text = "Wrong password"; // If you don't remember it, check your email or email us at [email protected]"; return; } Debug.Log(json); GameToken.save(json); Save.Set(PlayerPrefsKeys.EMAIL.ToString(), email, true); Save.Set(PlayerPrefsKeys.PASSWORD.ToString(), password, true); Save.Set(PlayerPrefsKeys.NAME.ToString(), json["username"].ToString(), true); Save.Set(PlayerPrefsKeys.ID.ToString(), json["user_id"].ToString(), true); if (!json["first_name"].IsNull) { Save.Set(PlayerPrefsKeys.FIRST_NAME.ToString(), json["first_name"].ToString(), true); } if (!json["last_name"].IsNull) { Save.Set(PlayerPrefsKeys.LAST_NAME.ToString(), json["last_name"].ToString(), true); } if (!json["location"].IsNull) { Save.Set(PlayerPrefsKeys.LOCATION.ToString(), json["location"].ToString(), true); } if (!json["gender"].IsNull) { Save.Set(PlayerPrefsKeys.GENDER.ToString(), json["gender"].ToString(), true); } if (!json["birthday"].IsNull) { string day, month, year; string[] separator = { "-" }; string[] birthday = json["birthday"].StringValue.Split(separator, System.StringSplitOptions.None); day = birthday[2]; month = birthday[1]; year = birthday[0]; Save.Set(PlayerPrefsKeys.DATE_DAY.ToString(), day, true); Save.Set(PlayerPrefsKeys.DATE_MONTH.ToString(), month, true); Save.Set(PlayerPrefsKeys.DATE_YEAR.ToString(), year, true); } // Verifica se possui Facebook if (json.Contains("fbtoken") && json.Contains("facebook_id")) { Save.Set(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString(), json["fbtoken"].ToString(), true); Save.Set(PlayerPrefsKeys.FACEBOOK_ID.ToString(), json["facebook_id"].ToString(), true); } // Atualiza token da FacebookAPI if (Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) { FacebookAPI facebook = new FacebookAPI(); facebook.SetToken(Save.GetString(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())); } ConfigManager.offlineUpdater.UpdateOfflineItems(); // Verifica se e uma conta nova if (json["new_account"].ToString() != "0") { //messageOkDialog.transform.FindChild("ConfirmButtonPanel").FindChild("ConfirmButton").GetComponent<UIButton>().methodToInvoke = "BringInInvite"; Flow.game_native.showMessage("Hello!", "Hi! You've registered with us! We've emailed you your password."); } // Redireciona a proxima cena panelManager.BringIn(Flow.panelAfterLogin); }