Example #1
0
	void Start()
	{
		database = new CML();

		//lets create our first node...
		database.AddNode("Library");

		//for our second node, we are going to add a field to the node...
		database.AddNode("Section", "Cat=History");

		//for our third node, we are going to add a bunch of fields to our node.
		database.AddNode("Book", "name=myBad Studios, a History; price=199.99; author=DrDude");

		//and then we are going to add a bunch of strings to an unordered list...
		database.Last.AddToData("There once was a company called myBad Studios");
		database.Last.AddToData("They rocked!!!");

		// lets just store the Id of this node for later...
		int id = database.Last.ID;

		//just for fun, let's add subnodes to this Book node. Let's save checkout history...
		database.AddNode("checkout", "date=2012/12/13; person=id1234");

		//thanks to default values, you don't have to specify numbers with a value of 0 or
		//booleans with a value of false in order to use them later on... 
		//above I didn't specify the staff value. Here I do.
		//In both cases you can still use staff as a boolean value without getting an error.
		database.AddNode("checkout", "date=2013/01/12; person=id112; staff=true");

		//and now let's make a new book node...
		database.AddNode("Book", "name=CML for Dummies; price=9.95; author=DrDude");
		database.Last.AddToData("CML is so easy I don't know what to write in this book...");
		database.Last.AddToData("The end");

		//oh wait, I never ended off the first book.... Fortunately, I have the node index so...
		//let me add some more text to that other node directly. No navigation needed.
		database[id].AddToData("To be continued...");

		//so, let's see how many sections I have in this database...
		List<int> cats = database.AllNodesOfTypei("Section");
		Debug.Log ("There are " + cats.Count + " sections in this library");

		//so, let's see how many books I have in each section. I will be accessing the
		//sections directly via index, entirely skipping any node traversal requirements
		foreach(int i in cats)
		{
			//fetch all "Book" nodes as children of "Section" nodes
			List<cmlData> books = database.Children(i);

			//and let's find the most expensive one of them all...
			float price = 0f;
			int index = 0;

			//I fetch the price as a float and compare it to the stored price...
			if (null != books)
			foreach (cmlData book in books)
			{
				if (book.Float("price") > price)
				{
					price = book.Float("price");
					index = book.ID;
				}
			}

			//now that I've looked at all the Books in the History Section,
			//I have the ID of the node of the most expensive book so I can
			//again access the Book node directly and extract any string or float or whatever is there...
			if (index > 0)
			{
				Debug.Log("The most expensive book was: " + database[index].String("name") + " with a value of " + database[index].Float("price"));
				Debug.Log ("The contents of the book is:");
				foreach (string s in database[index].data)
					Debug.Log (s);

				//now, let's check out the checkout history.
				//let's start by fetching all "checkout" nodes. since they are all stored after the
				//relevant Book node, I can fetch them as children of the book so...
				bool staff = false;
				List<cmlData> checkout_history = database.Children(index);

				if (null == checkout_history)
				{
					Debug.Log("this book was never checked out!");
				} else {
					//let's print off the checkout dates for this book...
					foreach(cmlData history in checkout_history)
					{
						if (history.Bool("staff")) staff = true;
						Debug.Log ("This book was checked out on " + history.String("date"));
					}
					if (staff)
						Debug.Log ("This book has been checked out by staff");
					else
						Debug.Log ("This book has not passed quality control");
				}
			}
		}

		//and just for good measure, let's print out the entire file so you can see what CML looks like
		Debug.Log( database.ToString() );
	}
Example #2
0
		virtual public void onLogOutSuccess(CML data)
		{
			user_gravatar = null;
			logged_in = false;
			fetched_info = null;
		}
Example #3
0
		virtual public void onProfileImageFetched(CML data)
		{
			cmlData response = data[0];

			string gravatar_type_name = response.String("gravatar_type");
			WULGravatarTypes type = WULGravatarTypes.Blank;
			for (WULGravatarTypes t = WULGravatarTypes.MysteryMan; t < WULGravatarTypes.Blank; t++)
			{
				if (t.ToString().ToLower() == gravatar_type_name.ToLower())
					type = t;
			}
			StartCoroutine (ContactGravatar(response.String("gravatar"), type));
		}
Example #4
0
		//append another CML data file to the end of this one
		virtual public bool Join(CML other, CMLCopyMode copy_mode = CMLCopyMode.no_id) {
			if (null == other || other.Count == 0)
				return false;
			
			foreach(cmlData d in other) {
				Elements.Add( d.Copy(copy_mode, Elements.Count.ToString()) );
			}
			
			return true;
		}
Example #5
0
		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);
		}
Example #6
0
	void FindLogin(CML data)
	{
		login = FindObjectOfType<WUUGLoginGUI>();
	}
Example #7
0
	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);
					}
				}
			}
		}			
	}
Example #8
0
		virtual public void OnRegistered(CML data)
		{
			StatusMessage.Message = "Registration successful...";
			loginState.SetState(WULStates.LoginChallenge);
		}
Example #9
0
		virtual public void OnAccountInfoUpdated(CML data)
		{
			nickname = account_info.pages[0].Entries[2].value;
			display_name = account_info.pages[0].Entries[3].value;

			loginState.SetState(WULStates.AccountMenu);
		}
Example #10
0
		virtual public void OnPasswordChanged(CML data)
		{
			OnLoggedOut(data);
			StatusMessage.Message = "Password successfully changed";
		}
Example #11
0
		virtual public void OnAccountInfoReceived(CML data)
		{
			for(int p = 0; p < account_info.pages.Length; p++)
				for(int f = 0; f < account_info.pages[p].Entries.Length; f++)
					account_info.pages[p].Entries[f].value = data[0].String( account_info.pages[p].Entries[f].serverfield );
		}
Example #12
0
		virtual public void OnReset(CML data)
		{
			StatusMessage.Message = "Password reset emailed to your registered email address";
			loginState.SetState(WULStates.LoginMenu);
			pass_reset_challenge.Entries[0].value = pass_reset_challenge.Entries[1].value = string.Empty;
		}
Example #13
0
		virtual public void OnLoggedOut(CML data)
		{
			StatusMessage.Message = display_name + " logged out successfully";
			logged_in = false;
			nickname = display_name = string.Empty;
			loginState.SetState(WULStates.LoginMenu);
		}
Example #14
0
		//upon successful login, the fields you requested to be returned are stored in cmlData fetched_info
		//and are left available to you until logout.
		virtual public void OnLoggedIn(CML _data)
		{
			//remember the "Remember me" choice...
			PlayerPrefs.SetInt("Remember Me", attempt_auto_login ? 1 : 0);
			if (attempt_auto_login)
				PlayerPrefs.SetString("username",login_challenge.Entries[0].value);

			//remove the password from the textfield
			login_challenge.Entries[1].value = string.Empty;

			//and slide it out of view...
			displayArea.Deactivate();

			//You can actually delete this prefab now if you wanted to since login is complete...
			//I prefer to keep it open so I can easily get back to account management but that is
			//a matter or personal choice and performance so do what you feel is best...
			if (destroy_prefab_on_login)
				Destroy (gameObject);
		}