static public void ContactServer( string action, string filepath, string wuss_kit, cmlData data = null, Action<CML> response = null, Action<cmlData> failedresponse=null ) { Instance.StartCoroutine( CallServer(action, filepath, wuss_kit, data, response, failedresponse) ); }
public void RegisterAccount(cmlData fields) { WPServer.ContactServer(WULActions.SubmitRegistration.ToString(),login_filepath, LOGINConstant, fields, onRegistered, onRegistrationFailed); }
public cmlData ChallengeToCMLData(bool allow_empty) { cmlData fields = new cmlData(); foreach (TabbedServerDataCapturePage page in pages) foreach (ServerDataCapture field in page.Entries) if (field.fieldType != eFieldType.Verify) if (field.value != "" || allow_empty) fields.Set( field.serverfield, field.value ); return fields; }
public cmlData ChallengeToCMLData(ref ServerDataCapture[] challenge_text, bool allow_empty) { cmlData fields = new cmlData(); foreach (ServerDataCapture field in challenge_text) if (field.fieldType != eFieldType.Verify) if (field.value != "" || allow_empty) fields.Set( field.serverfield, field.value ); return fields; }
public void FetchProfileImage(System.Action<Texture2D> response, WULGravatarTypes gravatar_type) { onProfileImageReceived = response; if (null == onProfileImageReceived) return; cmlData data = new cmlData(); data.Set("gravatar_type", gravatar_type.ToString()); WPServer.ContactServer(WULActions.FetchUserEmail.ToString(),login_filepath, LOGINConstant, data, onProfileImageFetched); }
void onLoginSuccess(CML data) { fetched_info = data.GetFirstNodeOfType(LOGINConstant).Copy(); fetched_info.Remove("success"); logged_in = true; user_gravatar = null; if (email != string.Empty) FetchProfileImage(__SetProfileImage, gravatar_type); }
virtual public bool PositionAtLastNode() { if (Count > 0) Node = Elements[Count-1]; else return false; return true; }
public void AttemptAutoLogin() { cmlData data = new cmlData(); data.Set("wul_fields", FieldsToFetch); WPServer.ContactServer(WULActions.VerifyLogin.ToString(),login_filepath, LOGINConstant, data, onLoggedIn); }
virtual public bool ParseFile(string data) { if (data == string.Empty) return false; Initialize(); string[] lines = data.Split('\n'); foreach (string line in lines) { //find and remove comments from the parser //take into account URL strings '://' string l = line; int commentIndex = l.IndexOf("//"); if (commentIndex > -1) { int urlIndex = 0; if (commentIndex > 0) { while (l.IndexOf("://", urlIndex) == commentIndex - 1) { urlIndex = commentIndex + 1; commentIndex = l.IndexOf("//", urlIndex); } } if (commentIndex > -1) l = l.Substring(0, commentIndex); } l = l.Trim(); //if the line is empty, do nothing with it... //ignore lines that close off data blocks... if (l == string.Empty //|| l.IndexOf("</") == 0 ) continue; //be default add data to the last datatype created int tagopen = l.IndexOf('['); int tagclose = l.IndexOf(']'); if (tagclose > 1 && tagopen == 0) { if (null != Last) { string keyname = l.Substring(1, tagclose - 1).Trim(); l = l.Substring(tagclose+1, l.Length - (tagclose + 1) ).Trim(); if (null != Last) { Last.Set(keyname, l); } } } else { //check to see if this is the definition of a new datatype's constant fields //or wether this is new data for a particular datatype tagopen = l.IndexOf('<'); tagclose = l.IndexOf('>'); if (tagclose > 1 && tagopen == 0) { string key_name = l.Substring(1, tagclose - 1).Trim(); string key_value = l.Substring(tagclose+1, l.Length - (tagclose + 1) ); AddNode(key_name, key_value); } else { //else add it as raw data... if (null != Last) Last.AddToData(l); } } } Node = (Count > 0) ? First : null; return true; }
//add a whole cmlData variable to the CML data virtual public bool CopyNode(cmlData existing) { cmlData copy = existing.Copy(); Elements.Add( new cmlData( Elements.Count ) ); Last.data_type = copy.data_type; foreach (var key in copy.defined) Last.defined.Add(key.Key, key.Value); foreach (string s in copy.data) Last.data.Add(s); return true; }
//clears the CML data virtual public void Initialize() { Node = null; if (null != Elements) Elements.Clear(); Elements = new List<cmlData>(); }
//returns a duplicate of this cmlData object virtual public cmlData Copy(CMLCopyMode mode = CMLCopyMode.no_id, string id_value="-1") { cmlData result = new cmlData(); result.data_type = this.data_type; foreach (var data in this.defined) { if (data.Key != "id") { result.Set(data.Key, data.Value); } else { switch (mode) { //keep the original id.... case CMLCopyMode.old_id: result.Set("id", data.Value); break; case CMLCopyMode.new_id : result.Set("id", id_value); break; case CMLCopyMode.no_id : result.Remove("id"); break; } } } foreach (string s in this.data) result.data.Add(s); return result; }
static public IEnumerator CallServer(string action, string filepath, string wuss_kit, cmlData data, Action<CML> response, Action<cmlData> failedresponse) { if (null == data) data = new cmlData(); if (data.String("gid") == string.Empty || data.Int("gid") < 0) data.Seti("gid", GameID); data.Seti("unity", 1); data.Set ("action", action); data.Set ("wuss", wuss_kit); string get = string.Empty; WWWForm f = new WWWForm(); foreach(string s in data.Keys) { f.AddField(s, data.String(s) ); get += "&"+s+"="+data.String(s); } get = "?" + get.Substring(1); if (null == serverState) InitServerState(); serverState.SetState(WULServerState.Contacting); WWW w = newWWW(Instance.URL(filepath)+get, f); yield return w; serverState.SetState(WULServerState.None); if (w.error != null) { StatusMessage.Message = "Connection error: " + w.error; if (null != failedresponse) { cmlData error = new cmlData(); error.Set("message", w.error); failedresponse(error); } } else { string result_string = w.text; int warning_index = result_string.IndexOf( "<br />" ); if ( warning_index > 0) { string server_error = result_string.Substring(warning_index + 6); StatusMessage.Message = server_error; Debug.Log (server_error); result_string = result_string.Substring(0, warning_index ); } result_string = Encoder.Base64Decode(result_string); CML results = new CML(); results.ParseFile(result_string); if (Instance.print_response_headers) foreach(var x in w.responseHeaders) Debug.Log(x.Key + " = " + x.Value + " : " + x.GetType() ) ; if (action == WULActions.DoLogin.ToString() || action == WULActions.VerifyLogin.ToString()) { WUCookie.ExtractCookie( w.responseHeaders ); } else if (action == WULActions.Logout.ToString()) { WUCookie.ClearCookie(); WUCookie.StoreCookie(); } if (results.Count == 0) { StatusMessage.Message = "No results returned"; if (null != failedresponse) { cmlData error = new cmlData(); error.Set("message", "No results returned"); failedresponse(error); } } else { //should only ever be one but for the sake of demonstration, let's test for multiple... List<cmlData> errors = results.NodesWithField("success", "false"); if (null != errors) { if (action != WULActions.VerifyLogin.ToString()) { if (null != failedresponse) { foreach(cmlData error in errors) { StatusMessage.Message = "Error: " + error.String("message"); cmlData _error = new cmlData(); _error.Set("message", error.String("message")); failedresponse(_error); } } } } else //if there were no errors, pass the resuls along to the response delegate, if any { if (action == WULActions.FetchUserEmail.ToString() ) { int i = results.GetFirstNodeOfTypei("LOGIN"); results[i].Set("gravatar_type", data.String("gravatar_type")); } if (null != response) { response(results); } } } } }
public void ResetPassword(cmlData fields) { WPServer.ContactServer(WULActions.PasswordReset.ToString(),login_filepath, LOGINConstant, fields, onReset, onResetFailed); }
//CML files are supposed to have sequential nodes but since the //data author can override this, do a test to see if the specified //node is the one requested or else go look for it. //Since a single file can have multiple sections and each section //could start it's index from 1, you can also provide the section's //node index as an offset from which to start searching virtual public bool PositionAtNode(int index, int offset = 0) { if (index + offset < 0 || index + offset >= Count) return false; if (Elements [ index + offset ].ID == index) { Node = Elements[index + offset]; return true; } int found_index = FindNodeByID(index, offset); if (found_index < 0) return false; Node = Elements[ found_index ]; return true; }
public void ChangePassword(cmlData fields) { WPServer.ContactServer(WULActions.PasswordChange.ToString(),login_filepath, LOGINConstant, fields, onPasswordChanged, onPasswordChangeFail); }
//position the marker at a node with a specific ID, even if it is //not at the correct array index. Use when you have multiple CML //files loaded into the same CML variable or if you manually change //the ID values of nodes. NOTE: never do that ! virtual public bool PositionAtID(int id) { if (id < 0) return false; int index = FindNodeByID(id); if (index == -1) return false; Node = Elements[index]; return true; }
public void AttemptToLogin(cmlData fields) { WUCookie.ClearCookie(); WUCookie.StoreCookie(); fields.Set("wul_fields", FieldsToFetch); WPServer.ContactServer(WULActions.DoLogin.ToString(),login_filepath, LOGINConstant, fields, onLoggedIn, onLoginFailed); }
//remove the node at index virtual public bool RemoveNode(int index) { if ( Count <= index) return false; //position Node on the next node if (null != Node) if (Node.ID == index) if (index < Count - 1) Node = Elements[index + 1]; else //if there isn't a "next" node, first check if there is a "previous" node //and go there if there is... if (Node.ID == 0) Node = null; else Node = Elements[index - 1]; Elements.RemoveAt(index); for (int i = index; i < Elements.Count; i++) Elements[i].ID = i; return true; }
public void UpdatePersonalInfo(cmlData fields) { if (fields.String("descr") != string.Empty) fields.Set ("descr", Encoder.Base64Encode(fields.String ("descr") ) ); WPServer.ContactServer(WULActions.UpdateAccountDetails.ToString(),login_filepath, LOGINConstant, fields, onInfoUpdated, onInfoUpdateFail); }
//add a node a specific index virtual public bool InsertNode(int index, string data_type, string add_data="") { if (data_type == string.Empty) return false; if (Count == 0) return AddNode(data_type, add_data); Elements.Insert(index, new cmlData( index ) ); Node = Elements[index]; Node.data_type = data_type; Node.ProcessCombinedFields(add_data); for (int i = index + 1; i < Count; i++) Elements[i].ID = i; return true; }
virtual public void onLogOutSuccess(CML data) { user_gravatar = null; logged_in = false; fetched_info = null; }
void OnLoginFail(cmlData response) { Debug.Log("Error message from failed login: "******"message")); }