/// <summary> /// Init constructor. /// </summary> public BayeuxAdvice(IJSonObject data) { if (data == null) throw new ArgumentNullException("data"); if (data.Contains("reconnect")) Reconnect = ParseReconnect(data["reconnect"].StringValue); if (data.Contains("interval")) Interval = data["interval"].Int32Value; Data = data; }
public static void CheckResponseError(IJSonObject e) { if (e == null) { return; } if (e.Contains("message")) { if (e["message"].StringValue.Equals("Please specify a correct Application Id.")) { Deployment.Current.Dispatcher.BeginInvoke( () => { var res = MessageBox.Show((string)Application.Current.Resources["VersionKeyErrorMessage"], (string)Application.Current.Resources["GeneralErrorTitle"], MessageBoxButton.OK); if (res == MessageBoxResult.OK || res == MessageBoxResult.None) { Application.Current.Terminate(); } }); } } }
protected override void ReadOptionalFields(IJSonObject input) { // reset field values: SupportedConnectionTypes = BayeuxConnectionTypes.None; // read additional data: if (input.Contains("supportedConnectionTypes")) { IJSonObject supportedTypes = input["supportedConnectionTypes"]; if (supportedTypes == null) { throw new MissingMemberException("Missing 'supportedConnectionTypes' field"); } if (!supportedTypes.IsArray) { throw new FormatException("Expected supportedConnectionTypes to be an array"); } BayeuxConnectionTypes types = BayeuxConnectionTypes.None; foreach (IJSonObject connectionType in supportedTypes.ArrayItems) { types |= BayeuxConnectionTypesHelper.Parse(connectionType.StringValue); } } }
protected override void ReadOptionalFields(IJSonObject input) { // reset field values: SubscriptionChannel = null; if (input.Contains("subscription")) SubscriptionChannel = input["subscription"].StringValue; }
private string ReadSharedFieldsSingleRequest(IJSonObject r) { ClientID = r["clientId", ClientID].StringValue; if (r.Contains("ext")) { Token = r["ext"]["token", Token].StringValue; } return(r["id", (string)null].StringValue); }
/// <summary> /// Init constructor. /// </summary> public BayeuxAdvice(IJSonObject data) { if (data == null) { throw new ArgumentNullException("data"); } if (data.Contains("reconnect")) { Reconnect = ParseReconnect(data["reconnect"].StringValue); } if (data.Contains("interval")) { Interval = data["interval"].Int32Value; } Data = data; }
protected override void ReadOptionalFields(IJSonObject input) { // reset field values: SubscriptionChannel = null; if (input.Contains("subscription")) { SubscriptionChannel = input["subscription"].StringValue; } }
// Obtem o resultado da conexao private void handleConnection(WWW conn, string id, object state, byte[] form_data, Hashtable headers) { // Verifica se houve erro if (conn.error != null) { if (url.Contains(Flow.URL_BASE) && url.EndsWith(".picture.php")) { return; } Debug.Log(url); Debug.Log("Internal server error to url (" + url + "): " + conn.error); sendToCallbackPersistent(conn.error, conn, state, id, conn.url, form_data, headers); return; } // Verifica se pediu senha try { JSonReader reader = new JSonReader(); IJSonObject data = reader.ReadAsJSonObject(conn.text); if (data != null && data.Contains("ask")) { // Caso peca senha, avisa o erro if (data["ask"].ToString() == "password") { sendToCallbackPersistent(DEFAULT_ERROR_MESSAGE + "r", null, state, id, conn.url, form_data, headers); } // Obtem o token do Facebook, caso necessario else if (data["ask"].ToString() == "fb_token") { GameFacebook facebook = new GameFacebook(); facebook.login(); sendToCallbackPersistent(DEFAULT_FB_TOKEN_ERROR_MESSAGE, null, state, id, conn.url, form_data, headers); } // Refaz a conexao caso necessario e possivel //if (redo && GameGUI.components != null) GameGUI.components.StartCoroutine(startConnection(form, state, false)); //else Application.LoadLevel(GameGUI.components.login_scene); return; } } catch (JSonReaderException) { } sendToCallbackPersistent(conn.error, conn, state, id, conn.url, form_data, headers); }
// Funcao para checar se o usuario curtiu alguma pagina public IEnumerator IsLikedPage(string pageId, FacebookAPI.IsLikedPageCallback callback, int tries = 0) { // Cria URL do request string url = GRAPH_URL + "me/likes/" + pageId + "/?"; url += "access_token=" + facebookToken; WWW like = new WWW(url); yield return(like); // Se houver algum erro, enviar erro para o callback if (like.error != null) { if (callback != null) { callback(like.error, false, pageId); } yield break; } // Caso contrario, decodar JSON recebido e validar conexão else { IJSonObject data = like.text.ToJSon(); // Se o JSON recebido for invalido, retornar e enviar para o callback if (data.IsEmpty() || data.IsError()) { if (callback != null) { callback("Invalid JSon: " + like.text, false, pageId); } yield break; } // Valida conexão e envia para o callback if (callback != null) { callback(null, ( data.Contains("data") && data["data"].Count > 0 && data["data"][0].GetString("id") == pageId ), pageId); } } yield break; }
private static void ToObjectSetProperty(IJSonObject source, object destination, Type oType, JSonSerializableAttribute jsonAttribute, PropertyInfo propertyInfo) { // there must be a getter defined: if (!propertyInfo.CanWrite) { return; } JSonIgnoreAttribute ignore = ReflectionHelper.GetCustomAttribute <JSonIgnoreAttribute>(propertyInfo); if (ignore != null) { return; } JSonMemberAttribute attr = ReflectionHelper.GetCustomAttribute <JSonMemberAttribute>(propertyInfo); if (attr == null && !jsonAttribute.AllowAllProperties) { return; } string name = attr != null && !string.IsNullOrEmpty(attr.Name) ? attr.Name : propertyInfo.Name; Type type = attr != null && attr.ReadAs != null ? attr.ReadAs : propertyInfo.PropertyType; if (source.Contains(name)) { propertyInfo.SetValue(destination, ToObject(source[name], type), null); } else if (attr != null) { if (attr.DefaultValue != null) { propertyInfo.SetValue(destination, ToObject(attr.DefaultValue, type), null); } else if (!attr.SuppressThrowWhenMissing && !attr.SkipWhenNull) { throw new JSonMemberMissingException("Missing required property", oType, name); } } else if (!jsonAttribute.SuppressThrowWhenMissing) { throw new JSonMemberMissingException("Property value not provided", oType, name); } }
private static void ToObjectSetField(IJSonObject source, object destination, Type oType, JSonSerializableAttribute jsonAttribute, FieldInfo fieldInfo) { if (fieldInfo.IsLiteral) { return; } JSonIgnoreAttribute ignore = ReflectionHelper.GetCustomAttribute <JSonIgnoreAttribute>(fieldInfo); if (ignore != null) { return; } JSonMemberAttribute attr = ReflectionHelper.GetCustomAttribute <JSonMemberAttribute>(fieldInfo); if (attr == null && !jsonAttribute.AllowAllFields) { return; } string name = attr != null && !string.IsNullOrEmpty(attr.Name) ? attr.Name : fieldInfo.Name; Type type = attr != null && attr.ReadAs != null ? attr.ReadAs : fieldInfo.FieldType; if (source.Contains(name)) { fieldInfo.SetValue(destination, ToObject(source[name], type)); } else if (attr != null) { if (attr.DefaultValue != null) { fieldInfo.SetValue(destination, ToObject(attr.DefaultValue, type)); } else if (!attr.SuppressThrowWhenMissing && !attr.SkipWhenNull) { throw new JSonMemberMissingException("Missing required field", oType, name); } } else if (!jsonAttribute.SuppressThrowWhenMissing) { throw new JSonMemberMissingException("Field value not provided", oType, name); } }
protected override void ReadOptionalFields(IJSonObject input) { // reset field values: SupportedConnectionTypes = BayeuxConnectionTypes.None; // read additional data: if (input.Contains("supportedConnectionTypes")) { IJSonObject supportedTypes = input["supportedConnectionTypes"]; if (supportedTypes == null) throw new MissingMemberException("Missing 'supportedConnectionTypes' field"); if (!supportedTypes.IsArray) throw new FormatException("Expected supportedConnectionTypes to be an array"); BayeuxConnectionTypes types = BayeuxConnectionTypes.None; foreach (IJSonObject connectionType in supportedTypes.ArrayItems) { types |= BayeuxConnectionTypesHelper.Parse(connectionType.StringValue); } } }
// 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 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); } }
/// <summary> /// Reads the response from given JSON object. /// </summary> public void Read(IJSonObject input) { _jsonResponse = input; // reset all fields to their default values: Channel = null; ClientID = null; Successful = false; Timestamp = DateTime.MinValue; ID = null; Data = null; Error = null; Advice = null; Ext = null; // stop processing, if there is no input data given: if (input == null) { return; } // now read the Bayeux mandatory fields: Channel = input["channel"].StringValue; if (!BayeuxChannel.IsValid(Channel)) { throw new FormatException("Invalid channel format"); } if (input.Contains("clientId")) { ClientID = input["clientId"].StringValue; } // for meta channels, this field is required, // however it's optional for others (like events) if (Channel.StartsWith("/meta")) { Successful = input["successful"].BooleanValue; } else { if (input.Contains("successful")) { Successful = input["successful"].BooleanValue; } } // parse optional fields: if (input.Contains("timestamp")) { Timestamp = input["timestamp"].DateTimeValue; } if (input.Contains("id")) { ID = input["id"].StringValue; } if (input.Contains("data")) { Data = input["data"]; } if (input.Contains("error")) { Error = new BayeuxError(input["error"].StringValue); } if (input.Contains("advice")) { Advice = new BayeuxAdvice(input["advice"]); } if (input.Contains("ext")) { Ext = input["ext"]; } ReadOptionalFields(input); }
// 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; }
private string ReadSharedFieldsSingleRequest(IJSonObject r) { ClientID = r["clientId", ClientID].StringValue; if (r.Contains("ext")) Token = r["ext"]["token", Token].StringValue; return r["id", (string) null].StringValue; }
// 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); }
public static IJSonObject Get(this IJSonObject json, string key) { return(json.Contains(key) ? json[key] : Empty()); }
/// <summary> /// Reads the response from given JSON object. /// </summary> public void Read(IJSonObject input) { _jsonResponse = input; // reset all fields to their default values: Channel = null; ClientID = null; Successful = false; Timestamp = DateTime.MinValue; ID = null; Data = null; Error = null; Advice = null; Ext = null; // stop processing, if there is no input data given: if (input == null) return; // now read the Bayeux mandatory fields: Channel = input["channel"].StringValue; if (!BayeuxChannel.IsValid(Channel)) throw new FormatException("Invalid channel format"); if (input.Contains("clientId")) ClientID = input["clientId"].StringValue; // for meta channels, this field is required, // however it's optional for others (like events) if (Channel.StartsWith("/meta")) Successful = input["successful"].BooleanValue; else { if (input.Contains("successful")) Successful = input["successful"].BooleanValue; } // parse optional fields: if (input.Contains("timestamp")) Timestamp = input["timestamp"].DateTimeValue; if (input.Contains("id")) ID = input["id"].StringValue; if (input.Contains("data")) Data = input["data"]; if (input.Contains("error")) Error = new BayeuxError(input["error"].StringValue); if (input.Contains("advice")) Advice = new BayeuxAdvice(input["advice"]); if (input.Contains("ext")) Ext = input["ext"]; ReadOptionalFields(input); }