<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Persistent Browser-Based Games Blog</title>
	<link>http://www.pbbgblog.com</link>
	<description>The blog that's dedicated to PBBGs.</description>
	<pubDate>Tue, 19 Aug 2008 08:00:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>PBBG Basics</title>
		<link>http://www.pbbgblog.com/2008/08/19/pbbg-basics/</link>
		<comments>http://www.pbbgblog.com/2008/08/19/pbbg-basics/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 08:00:41 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[PBBG General]]></category>

		<category><![CDATA[Theory]]></category>

		<category><![CDATA[game]]></category>

		<category><![CDATA[pbbg]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/08/19/pbbg-basics/</guid>
		<description><![CDATA[In this article, I will explain the basics of how PBBGs work.
One basic, essential component of games are forms. HTML forms. They provide a simple-to-use interface for the user to interact with the game. Forms allow the player to register, login, buy units, allocate resources, etc. by sending information from the player to the server. [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, I will explain the basics of how PBBGs work.</p>
<p>One basic, essential component of games are forms. HTML forms. They provide a simple-to-use interface for the user to interact with the game. Forms allow the player to register, login, buy units, allocate resources, etc. by sending information from the player to the server. Interaction can also be done with links (sending data through URL parameters), AJAX, and more, but forms are probably the most common.</p>
<p>Forms are used to add or make changes to the player, whatever they control, and maybe global game variables. These changes are the backbone of the gameplay, and provide the user with control/choice, and gives the server some information to work with.</p>
<p>There are two common ways that this information is used. One way is that the player submits forms, and that submitted information changes certain variables. They might also be able to submit commands, which will be performed on the next <u>tick</u>. That&#8217;s right, I&#8217;m talking about tick-based games. Ticks occur in time intervals, and on each tick, the server takes all the new data (that the player changed) and calculates the result for everybody all in one go. The tick will also execute the commands submitted by the player (eg. build a house). In this way, changes to the entire game world happen on the tick, while individual changes to player data happen when the players submit forms.</p>
<p>Another way is that the information is used immediately, and a result is shown to the user. These are generally real-time games. For example, a user selects which units they want to send to attack another player, and submit the form. The server takes that information, processes it, and displays the result to the player on the next page without any delay.</p>
<p>This poses a problem. In tick-based games, the &#8217;speed&#8217; of the game and of the players is limited by the ticks. Players can only do so much in one tick that they need to wait until the next tick before they have resources available again. This keeps the game at a steady pace, and allows slower players a chance to keep up with the others. However, in a real-time game, players can keep playing without any limits. To restrict players, many games use &#8216;turns&#8217;. Every action in the game takes up a number of turns, and when their turns are used up, they need to wait until they have more turns. (Turns are usually given/recharged in time intervals, similar to ticks.)</p>
<p>Another way to limit the speed of the game is to put a cost on certain actions, and introduce currency/resources. If particular actions use up resources, and resources are not infinite, then those actions are also limited.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/08/19/pbbg-basics/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tip of the Week</title>
		<link>http://www.pbbgblog.com/2008/04/04/tip-of-the-week-2/</link>
		<comments>http://www.pbbgblog.com/2008/04/04/tip-of-the-week-2/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 18:02:31 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[PBBG General]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[pbbg]]></category>

		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/04/04/tip-of-the-week-2/</guid>
		<description><![CDATA[Here&#8217;s the &#8216;tip of the week&#8217;! (Even though there hasn&#8217;t been a new post in weeks :P)
Do you want to display item/unit/building information on your PBBG, but find that your tables are getting too big, and your divs are cluttering up the page? Use tooltips to display this information in a compact and stylish way!
There [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the &#8216;tip of the week&#8217;! (Even though there hasn&#8217;t been a new post in weeks :P)</p>
<p>Do you want to display item/unit/building information on your PBBG, but find that your tables are getting too big, and your divs are cluttering up the page? Use tooltips to display this information in a compact and stylish way!</p>
<p>There are several ways to do this, and of course you can customize your tooltips so they fit right into your PBBG. There are already a few javascript libraries available on the internet which will allow you to use tooltips easily, so I will introduce two of these libraries. If you don&#8217;t like them, I&#8217;m sure there are more on the Internet!</p>
<p><strong><a href="http://boxover.swazz.org/" target="_blank">BoxOver</a><br />
</strong>This is a javascript library that is used by Google on <a href="http://sites.google.com/" target="_blank">Google Sites</a> (read more about BoxOver on its <a href="http://en.wikipedia.org/wiki/BoxOver" target="_blank">wikipedia article</a>). Unfortunately, at the time of writing the official BoxOver website is not available. I did find a copy of the <a href="http://www.koders.com/javascript/fid8780CBE6D1BEE164FC239AA55DCB13A53B3536E8.aspx" target="_blank">Javascript file</a> however. With this library, you set all the tooltip texts/header/styles/other options by using the title attribute in your HTML tags, so it is possible to use these tooltips on many HTML elements.<br />
Examples: <a href="http://www.norfolk.gov/cultural_affairs/boxover/example.html" target="_blank">http://www.norfolk.gov/cultural_affairs/boxover/example.html</a><strong><br />
</strong></p>
<p><a href="http://www.walterzorn.com/tooltip/tooltip_e.htm" target="_blank"><strong>Walter Zorn Tooltip</strong></a><br />
This library is a bit more advanced than the BoxOver library, and allows you to write your own <a href="http://www.walterzorn.com/tooltip/extensions.htm" target="_blank">extensions</a> to create amazing tooltips! However, it may be slightly harder to use/set up, as you must use the onmouseover and onmouseout triggers to display/close tooltips.</p>
<p>Here are some ideas you might want to try out when using tooltips:</p>
<ul>
<li>Create your own tooltip! Make it match your game&#8217;s style and theme so it will be unique!</li>
<li>You could also try using AJAX to directly fetch information from a database, so that the information you present will never be out of date and will require little maintenance!</li>
<li>Use HTML! The libraries I introduced above allow HTML in the actual tooltip text, so don&#8217;t hesitate to add images and tables.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/04/04/tip-of-the-week-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Call for Collaboration</title>
		<link>http://www.pbbgblog.com/2008/03/06/call-for-collaboration/</link>
		<comments>http://www.pbbgblog.com/2008/03/06/call-for-collaboration/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 14:36:06 +0000</pubDate>
		<dc:creator>mobeamer</dc:creator>
		
		<category><![CDATA[Game Ideas]]></category>

		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[Theory]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/03/06/call-for-collaboration/</guid>
		<description><![CDATA[A Call for Collaboration
The idea of sharing characters, objects and user information across multiple games and environments has always interested me.
I&#8217;ve got a simplistic idea on how this could be done and wanted to share it.
Some assumptions:
	Let&#8217;s assume we have 3 environments (games) Game A, B and C. They are similar in some concepts and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A Call for Collaboration</strong></p>
<p>The idea of sharing characters, objects and user information across multiple games and environments has always interested me.</p>
<p>I&#8217;ve got a simplistic idea on how this could be done and wanted to share it.</p>
<p><strong><font>Some assumptions:</font></strong></p>
<blockquote><p>	Let&#8217;s assume we have 3 environments (games) Game A, B and C. They are similar in some concepts and vastly different in others.</p>
<p>Let&#8217;s assume we have one user, Joe, who wants to play in all three environments.</p></blockquote>
<p><strong><font>Step 1:</font></strong></p>
<p>Joe signs up for Game A and plays it. All information is stored within Game A as normal.</p>
<p>When Joe logs out of Game A. He is given a url that will contain all his information.<br />
www.GameA.com/userInfo.php?userID=10</p>
<p><strong><font>Next Step:</font></strong></p>
<p>Joe now wants to play Game B. He has the option of entering in his url or registering as normal.</p>
<p>Once given a url Game B will request Joe&#8217;s information from Game A.</p>
<p>Game A will response with pair values, like so:</p>
<blockquote><p>		UserName=Joe<br />
Email=joe@somewhere.com<br />
Score=1000<br />
Money=500<br />
CharacterName=Killer<br />
CharacterHP=50<br />
CharacterMagic=40<br />
etc&#8230;<br />
etc&#8230;</p></blockquote>
<p>Game A will also record the fact that Game B requested information. This will come into play when Joe goes back to playing Game A.</p>
<p>Game B will take the values it can use and create/update Joe&#8217;s account within it&#8217;s game environment. Such as UserName, Score and Money. (Maybe this game does not have characters)</p>
<p><strong><font>Next Step:</font></strong></p>
<p>Joe is done playing Game B. As he logs out he is given the opportunity to get a new URL or he can update Game A.</p>
<p>If Joe decided to update Game A, Game B will send a request to Game A letting it know the url it can find an update at.<br />
www.GameB.com/userInfo.php?userID=99</p>
<p>Game A will go to that url and process all of Joe&#8217;s information, updating it&#8217;s stats as needed.</p>
<p><strong><font>Thoughts:</font></strong></p>
<p>One of the advantages of this system is that if Site A were to disappear or be unavailable, Joe still retains all the information from Game B. It&#8217;s even possible for him to save information from Game A, if the site does disappear, if Game B has it saved.</p>
<p>For those who are worried about malicious use of the system, it would be quite easy to code the update process to only allow updates from certain game sites. If you did not want to see updates from Game C, you could exclude that site from your updates by looking at the request url.</p>
<p>Alternatively someone could offer a service where &#8220;trusted&#8221; games can exchange information.</p>
<p>The user information could be in an XML document, but I have found that the ease with which you can build key pair values is easier to build and search then XML documents. I know the advantages, I personally don&#8217;t think the advantages out weigh the disadvantages in this case.</p>
<p>This is a stab in the dark any thoughts and comments are appreciated.</p>
<p><em><strong> mobeamer</strong></em></p>
<p><img src="http://www.battleforcesonline.com/images/LongBanner.jpg" alt="Battle Forces Online" height="60" width="468" /><br />
<a href="http://www.BattleForcesOnline.com" title="Battle Forces Online">www.BattleForcesOnline.com</a><br />
<a href="http://mobeamer.blogspot.com/" title="Personal Blog">blogspot.mobeamer.com</a><br />
<em>I am no author but I do have somethings to share.  </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/03/06/call-for-collaboration/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Formatting User-Submitted Text</title>
		<link>http://www.pbbgblog.com/2008/03/02/formatting-user-submitted-text/</link>
		<comments>http://www.pbbgblog.com/2008/03/02/formatting-user-submitted-text/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 19:51:14 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[pbbg]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/03/02/formatting-user-submitted-text/</guid>
		<description><![CDATA[If you are a PHP and/or a PBBG developer, then I&#8217;m sure you know about the problems associated with user-submitted text. If not sanitized properly, your website could be the victim of XSS attacks and SQL injections. In this article I will discuss what methods I use to protect my sites.
nl2br()
PHP already has several useful [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a PHP and/or a PBBG developer, then I&#8217;m sure you know about the problems associated with user-submitted text. If not sanitized properly, your website could be the victim of <a href="http://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank">XSS attacks</a> and <a href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">SQL</a> injections. In this article I will discuss what methods <em>I</em> use to protect my sites.</p>
<p><strong><a href="http://www.php.net/manual/en/function.nl2br.php" target="_blank">nl2br()</a></strong></p>
<p>PHP already has several useful functions that can be used to sanitize strings. The first function I want to talk about is <a href="http://www.php.net/manual/en/function.nl2br.php" target="_blank">nl2br()</a>. It doesn&#8217;t really help in security, but it is great for readability when you need to display stuff. It inserts a <em>br</em> tag at the end of each new line.</p>
<p><strong>When it should be used:</strong> This tag should only be used when data is being displayed in a non-editable form, such as in a forum or a user profile. When it is displayed in an editable form such as a <em>textarea</em>, or when it is being added into the database, you don&#8217;t want to use this function because you want to preserve the original text. If the text is being edited by a user, they might be wondering why there are suddenly HTML tags all over their text.</p>
<p><strong><a href="http://www.php.net/manual/en/function.strip-tags.php" target="_blank">strip_tags()</a></strong></p>
<p>If you want to get rid of HTML in text, you can use this function. <a href="http://www.php.net/manual/en/function.strip-tags.php" target="_blank">strip_tags()</a> will attempt to remove all HTML and PHP tags. You can also set which tags to allow! However, this function is not reliable, and can have unwanted side-effects. Even if you allow only &#8217;safe&#8217; tags, attributes of HTML tags will not be altered, and can still be dangerous by adding attributes such as &#8216;onmouseover&#8217;.</p>
<p><strong>When it should be used:</strong> If you really are not picky about security, you could use this function as a very primitive form of removing HTML whenever the formatted text is being inserted into the database. There is no need to &#8216;only&#8217; use this function when the text is being displayed to the user, since the HTML tags are not meant to be preserved, but removed permanently. However, this function still cannot protect you from SQL injections or XSS attacks.</p>
<p><strong><a href="http://www.php.net/manual/en/function.htmlentities.php" target="_blank">htmlentities()</a> and <a href="http://www.php.net/manual/en/function.htmlspecialchars.php" target="_blank">htmlspecialchars()</a></strong></p>
<p>If you don&#8217;t want to remove the HTML tags, but instead <em>display them</em>, you can use either of these functions. They will convert characters into their corresponding HTML entities. The difference between the two functions is that htmlspecialchars() will only convert a limited set of characters (see PHP manual), while htmlentities() will attempt to convert <em>everything</em>.</p>
<p><strong>When it should be used:</strong> These functions should be used when the text is being displayed, not processed, for the same reasons as for nl2br() - you&#8217;ll probably want to preserve the original text. Remember to add ENT_NOQUOTES as a parameter of the functions to convert double and single quotes.</p>
<p><strong><a href="http://www.php.net/manual/en/function.addslashes.php" target="_blank">addslashes()</a></strong></p>
<p>This function will add backslashes to text to escape all quotes and backslashes.</p>
<p><strong>When it should be used:</strong> addslashes() should be used on GET/POST/REQUEST/COOKIE data <u>if</u> <a href="http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc" target="_blank">magic_quotes_gpc</a> is off. If it is on, backslashes will be added automatically. addslashes() should be used when you are inserting data in the database. This function is useful because it escapes quotes, which could potentially break out of any SQL queries you run with the original data.</p>
<p><strong><a href="http://www.php.net/manual/en/function.stripslashes.php" target="_blank">stripslashes()</a></strong></p>
<p>stripslashes() will remove backslashes from your message. Double backslashes will become a single backslash.</p>
<p><strong>When it should be used:</strong> stripslashes() should be used on all GET/POST/REQUEST/COOKIE data <u>if and only if</u> <a href="http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc" target="_blank">magic_quotes_gpc</a> is on and you want to display that data immediately. Otherwise, stripslashes() should be used when you are displaying data from the database which have already had their quotes escaped (with addslashes() or magic quotes).</p>
<p><strong><a href="http://www.php.net/manual/en/function.mysql-real-escape-string.php" target="_blank">mysql_real_escape_string()</a></strong></p>
<p>This function is supposed to take care of SQL injections. It will escape all special characters in any values/queries that you pass a parameter.</p>
<p><strong>When it should be used:</strong> This function should be used when you are inserting user-submitted text into the database. This function should not be used in conjunction with addslashes(). Any quote escaping will be done automatically by this function. I haven&#8217;t personally used this function before so I don&#8217;t know how effective it is.</p>
<p><strong><a href="http://htmlpurifier.org/" target="_blank">HTMLPurifier</a></strong></p>
<p>HTMLPurifier is a library for cleaning up HTML. You choose which tags to allow, or none at all, and the library will take care of the rest. I like to think of this as an advanced and more useful strip_tags() function.</p>
<p><strong>When it should be used:</strong> HTMLPurifier&#8217;s functions should be used whenever data is being processed and added into the database, so that when the text is displayed, there won&#8217;t be any faulty code or hidden HTML tags. HTMLPurifier is very useful for protection against XSS attacks, and is also very flexible, allowing your users to use HTML tags safely.</p>
<p>Of course, these aren&#8217;t the only solutions available! There are plenty of other functions, and you could also make your own functions to sanitize strings.<br />
If you have your own methods of sanitizing user-submitted text, please leave a comment and share your methods with us! <img src='http://www.pbbgblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/03/02/formatting-user-submitted-text/feed/</wfw:commentRss>
		</item>
		<item>
		<title>2 Non-PHP PBBGs</title>
		<link>http://www.pbbgblog.com/2008/02/25/2-non-php-pbbgs/</link>
		<comments>http://www.pbbgblog.com/2008/02/25/2-non-php-pbbgs/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 05:41:26 +0000</pubDate>
		<dc:creator>knuts</dc:creator>
		
		<category><![CDATA[PBBG Websites]]></category>

		<category><![CDATA[pbbg]]></category>

		<category><![CDATA[Perl]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[Pioneers of Aethora]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[WMD Tank Battle]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/02/25/2-non-php-pbbgs/</guid>
		<description><![CDATA[So many browser games are written in PHP that it is easy to forget that they can be built in any language. PHP has great features for web game development and it is widely available, but it is not the only option out there.
To make this point (and as a shameless plug)  I want [...]]]></description>
			<content:encoded><![CDATA[<p>So many browser games are written in PHP that it is easy to forget that they can be built in any language. PHP has great features for web game development and it is widely available, but it is not the only option out there.</p>
<p>To make this point (and as a shameless plug)  I want to mention two : my game <a href="http://wmdtb.com" title="WMD Tank Battle">WMD Tank Battle</a>, a multiplayer conquest game written in Perl, and RangerSheck&#8217;s <a href="http://aethora.com" title="pioneers of aethora">Pioneers of Aethora</a>, a tactical RPG written in Ruby on Rails.</p>
<p>Perl and mod_perl are old workhorses of the web, and Ruby on Rails is the latest greatest world-changing web framework, but both games make heavy use of shiny techniques like AJAX to minimize page loading and provide other features - Aethora has a built in chat, and uses the <a href="http://prototypejs.org/"> Prototype </a> and <a href="http://script.aculo.us/"> Scriptaculous </a> libraries for a great tactical map and drag/drop inventories. WMD Tank Battle uses <a href="http://ajaxpatterns.org/wiki/index.php?title=Sprite#Solutions">CSS Sprites</a> and javascript vector graphics for silly 2d animation and a real-time &#8220;missile command&#8221; game.</p>
<p>There are others around too - <a href="http://urbandead.com">Urban Dead </a> is one of the most popular web games ever and it&#8217;s sporting the &#8220;.cgi&#8221; extension. Know any other good ones ? Please comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/02/25/2-non-php-pbbgs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MyMiniCity</title>
		<link>http://www.pbbgblog.com/2008/02/23/myminicity/</link>
		<comments>http://www.pbbgblog.com/2008/02/23/myminicity/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 12:01:43 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
		
		<category><![CDATA[PBBG General]]></category>

		<category><![CDATA[PBBG Websites]]></category>

		<category><![CDATA[game]]></category>

		<category><![CDATA[pbbg]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/02/23/myminicity/</guid>
		<description><![CDATA[Want to create your own city? MyMiniCity allows you to do just that!
MyMiniCity is a simple &#8216;game&#8217; where you can pick a country, name your city and start getting people to click on your link. Every time somebody clicks on your link, your city will increase in population, and so your city grows. As your [...]]]></description>
			<content:encoded><![CDATA[<p>Want to create your own city? <a href="http://www.myminicity.com/" target="_blank">MyMiniCity</a> allows you to do just that!</p>
<p>MyMiniCity is a simple &#8216;game&#8217; where you can pick a country, name your city and start getting people to click on your link. Every time somebody clicks on your link, your city will increase in population, and so your city grows. As your city becomes bigger, you get more links to manage unemployment, transport, crime and pollution, so just getting citizens isn&#8217;t enough!</p>
<p>Your city is ranked against other cities in the same country, and the largest cities have huge skyscrapers and buildings, while you start off with a simple house in the middle of nowhere. As your city grows, so will its land, and more buildings will be added, and older buildings will become bigger.</p>
<p>There isn&#8217;t really any skill involved in the game, except a skill of getting people to click your links. You can check in from time to time to see how your city is doing.</p>
<p>To see a demo of what MyMiniCity is like, I registered a city called PBBG Blog. You can view it here: <a href="http://pbbg.myminicity.com/" target="_blank">http://pbbg.myminicity.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/02/23/myminicity/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Defeating SQL Injection</title>
		<link>http://www.pbbgblog.com/2008/02/20/defeating-sql-injection/</link>
		<comments>http://www.pbbgblog.com/2008/02/20/defeating-sql-injection/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 14:19:54 +0000</pubDate>
		<dc:creator>mobeamer</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[PBBG General]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[pbbg]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/02/20/defeating-sql-injection/</guid>
		<description><![CDATA[Your code is the walls which protect your intellectual ideas. The best attack your enemy has is SQL injection. Are your walls providing a suitable defense? (*groan* That was a horrible intro but it was the best I could do)
A few comments on this blog were made on SQL Injection, so I thought I&#8217;d post [...]]]></description>
			<content:encoded><![CDATA[<p>Your code is the walls which protect your intellectual ideas. The best attack your enemy has is SQL injection. Are your walls providing a suitable defense? (*groan* That was a horrible intro but it was the best I could do)</p>
<p>A few comments on this blog were made on SQL Injection, so I thought I&#8217;d post some thoughts. There are many articles about how to prevent SQL injection, I am going to cover just a few techniques.</p>
<p><strong>The Problem</strong><br />
If you don&#8217;t know what SQL Injection is Google it, but quite simply it is a way for external forces to execute SQL statements on your database. Statements like:</p>
<blockquote><p>delete from user (scary)<br />
update user set life = 100000000 (hacker)</p></blockquote>
<p>Most of these types of hacks happen when a user types specific things into a text box or address bar. This being the case you want to &#8220;clean&#8221; all incoming input. Rule of Thumb: Very rarely trust and always verify. (Trust but verify?)</p>
<p>The reason this hack works is because when you use a variable in a sql statement it can contain malicious code. For example the following piece of codes is suspect to SQL Injection:</p>
<blockquote><p>$sql = &#8220;Select * from user where username = &#8216;$username&#8217; and password = &#8216;$password&#8217;;&#8221;<br />
mysql_execute_query($sql);</p></blockquote>
<p>If the user uses the following as their username &#8216;;delete from user; it will delete all users from your tables.</p>
<p><strong>The Solution</strong><br />
Clean all your variables. I run all variables, regardless of how I use them through a clean function. The clean function is responsible for removing quotes and cleaning up odd characters.</p>
<p>This takes a variable, cleans it and returns it. If you use this code, please add your own steps to ensure protection of your data, this is a simplistic clean function. Below is some of the function:</p>
<blockquote><p>function clean($value)<br />
{<br />
$value = trim($value);</p>
<p>$value = strip_tags($value);</p>
<p>$value = mysql_real_escape_string($value);</p>
<p>if (!get_magic_quotes_gpc())<br />
{<br />
$value = addslashes($value);<br />
}</p>
<p>$value = rtrim($value);</p>
<p>return $value;<br />
}</p></blockquote>
<p>I use this function like so:</p>
<blockquote><p>$sql = &#8220;Select * from user where username = &#8216;&#8221; . clean($username) . &#8220;&#8216; and password = &#8216;&#8221; . clean($password) . &#8220;&#8216;;&#8221;<br />
mysql_execute_query($sql);</p></blockquote>
<p><strong>Another Solution</strong><br />
The other step I take is that I have overwritten the mysql_query function so that it replaces my table names. I want to make it difficult for people to guess my table names, so I have the following function:</p>
<blockquote><p>function executeQuery($sql)<br />
{<br />
$sql = str_replace(&#8221;s_&#8221;, &#8220;game_&#8221;, $sql);<br />
$q = mysql_query($sql) or die(&#8221;SQL Error on $PHP_SELF: &#8221; . $sql);</p>
<p>return $q;<br />
}</p></blockquote>
<p>This replaces any s_ with game_, I might name my table &#8220;game_user&#8221; however my sql would be select * from s_user.</p>
<p>Hopefully this helps those who have questions about SQL Injection. And again, this certainly does not fully cover the topic.</p>
<p><em><strong> mobeamer</strong></em></p>
<p><img src="http://www.battleforcesonline.com/images/LongBanner.jpg" alt="Battle Forces Online" height="60" width="468" /><br />
<a href="http://www.BattleForcesOnline.com" title="Battle Forces Online">www.BattleForcesOnline.com</a><br />
<a href="http://mobeamer.blogspot.com/" title="Personal Blog">blogspot.mobeamer.com</a><br />
<em>I am no author but I do have somethings to share.  </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/02/20/defeating-sql-injection/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SQL Select Statements Kept Simple</title>
		<link>http://www.pbbgblog.com/2008/02/15/sql-select-statements-kept-simple/</link>
		<comments>http://www.pbbgblog.com/2008/02/15/sql-select-statements-kept-simple/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 15:12:41 +0000</pubDate>
		<dc:creator>mobeamer</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[Theory]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/02/15/sql-select-statements-kept-simple/</guid>
		<description><![CDATA[This is a quick article on writing simple and complex select SQL statements. This primer can be used for mySQL and many other database systems. Please keep in mind this is a primer, please research and read other materials to enhance your knowledge.
For those of you who are wondering, mySQL is used in browser based [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick article on writing simple and complex select SQL statements. This primer can be used for mySQL and many other database systems. Please keep in mind this is a primer, please research and read other materials to enhance your knowledge.</p>
<p>For those of you who are wondering, mySQL is used in browser based game design quite often.</p>
<p><strong>Select Statement</strong></p>
<p>The select statement is used to get information from the database. It consists of 3 parts. The Fields the tables and the where clause.</p>
<blockquote><p>SELECT [TABLE].[FIELDS]<br />
FROM [TABLE]<br />
WHERE [TABLE].[FIELD] = [VALUE]</p></blockquote>
<p>select user.email<br />
from user<br />
where user.username = &#8216;mobeamer&#8217;</p>
<ul>
<li>Fields - Can contain a list of fields that you want to select.</li>
<li>Table - will contain one, possibly more tables that hold the fields</li>
<li>Where - This will allow you to restrict the information you receive.</li>
</ul>
<p>Notice that I surrounded mobeamer with quotes, this is needed for strings and is good practice for other data types. A good rule of thumb is when in doubt add quotes.</p>
<p>Notice that I fully qualified the fields by putting the table name in front of the field name. This is not needed when writing a simple select but it is considered good form AND it will come in handy when you decide to &#8220;upgrade&#8221; your SQL statement (see joins).</p>
<p><strong>Inner Join</strong></p>
<p>An inner join will allow you to pull information from multiple tables with one query. The syntax for an inner join is as follows:</p>
<blockquote><p>SELECT [TABLE].[FIELDS]<br />
FROM [TABLE]<br />
INNER JOIN [TABLE] ON [TABLE].[FIELD] = [TABLE].[FIELD]<br />
WHERE [TABLE].[FIELD] = [VALUE]</p></blockquote>
<p>Let&#8217;s say you have a user table which contains all the player&#8217;s information. You also have a units table that contains all the units that a player can have. You need a select statement which will get the player&#8217;s name and the unit&#8217;s name. In this instance my unit table has a column called ownerID which holds the userID of the owner.</p>
<blockquote><p>select user.username, unit.unitname<br />
from user<br />
inner join unit on unit.ownerID = user.userID<br />
where user.username=&#8217;mobeamer&#8217;</p></blockquote>
<p>Another example:</p>
<blockquote><p> select user.username, unit.unitname<br />
from user<br />
inner join unit on unit.ownerID = user.userID<br />
where unit.class = &#8216;Warrior&#8217;</p></blockquote>
<p>In most cases your joining field will be named the same in both tables, but I wanted to show how this was not necessary.</p>
<p>Notice, that you must fully qualify fields that exists in both tables. You should be aware when using an inner join, as in the first example, if the user does NOT have any units they will NOT appear in the result set.</p>
<p>Be very careful with inner joins as they ALWAYS restrict the result set. (See outer joins)</p>
<p><strong>Outer Join</strong></p>
<p>An outer join works in the same fashion as an inner join with one exception. The join will NOT restrict the returned set For example, in the example above, a player may not have a unit. In this case, an inner join would not pick up that player&#8217;s name. An outer join on the other hand would pickup this player.</p>
<blockquote><p>select user.username, unit.unitname<br />
from user<br />
outer join unit on unit.ownerID = user.userID<br />
where user.username=&#8217;mobeamer&#8217;</p></blockquote>
<p>This will get all user, regardless of how many units they have.</p>
<p>Notice, the first table in the select statment begins the result set. Every outer join from there on can only add rows or columns to the recordset.</p>
<p>A good rule of thumb is to always use an outer join as you will never lose data with an outer join.</p>
<p><strong>How I do It</strong></p>
<p>This is how I write a complicated sql statement, this may not be best practices but I think it may add some context.</p>
<p>I wanted to create a page, which displays a player&#8217;s profile. I knew I needed a number of fields from the player&#8217;s table, unit&#8217;s table and item&#8217;s table. (Items are things that the unit holds)</p>
<p>I knew I wanted to display all players that had registered, so I started there.</p>
<blockquote><p>Select user.username, user.numKills<br />
from user<br />
where user.isRegistered = &#8216;Y&#8217;</p></blockquote>
<p>I then wanted to display the unit&#8217;s name, class and life</p>
<blockquote><p> Select user.username<br />
, user.numKills<br />
, unit.unitName<br />
, unit.class<br />
, unit.life<br />
from user<br />
left outer join unit on unit.ownerID = user.userID<br />
where user.isRegistered = &#8216;Y&#8217;</p></blockquote>
<p>I then wanted to display all the items that the unit held, and the item&#8217;s description</p>
<blockquote><p>Select user.username<br />
, user.numKills<br />
, unit.unitName<br />
, unit.class<br />
, unit.life<br />
, item.itemName<br />
, item.itemDescription<br />
from user<br />
left outer join unit on unit.ownerID = user.userID<br />
left outer join item on item.unitID = unit.unitID<br />
where user.isRegistered = &#8216;Y&#8217;</p></blockquote>
<p>This was the sql that I ended with.</p>
<p><strong>Further Articles</strong><br />
Good ideas to follow this up with:</p>
<ul>
<li>Updates, Inserts and Deletes</li>
<li>Restricting an inner or outer join</li>
<li>Links and Resources</li>
</ul>
<p><em><strong> mobeamer</strong></em></p>
<p><img src="http://www.battleforcesonline.com/images/LongBanner.jpg" alt="Battle Forces Online" height="60" width="468" /><br />
<a href="http://www.BattleForcesOnline.com" title="Battle Forces Online">www.BattleForcesOnline.com</a><br />
<a href="http://mobeamer.blogspot.com/" title="Personal Blog">blogspot.mobeamer.com</a><br />
<em>I am no author but I do have somethings to share.  </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/02/15/sql-select-statements-kept-simple/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tip of the Week</title>
		<link>http://www.pbbgblog.com/2008/02/13/tip-of-the-week/</link>
		<comments>http://www.pbbgblog.com/2008/02/13/tip-of-the-week/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 18:26:01 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[pbbg]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/02/13/tip-of-the-week/</guid>
		<description><![CDATA[Do you use the header() function to redirect users?


&#60;?php
header&#40;&#34;Location: http://www.example.com&#34;&#41;;
?&#62;


Here&#8217;s a little tip: use the exit statement right after you redirect.
Why? Imagine this: You have some code that runs after the redirect (the user was redirected because he did not have the correct permissions to view the page), and that code updates the user table [...]]]></description>
			<content:encoded><![CDATA[<p>Do you use the header() function to redirect users?</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000066;">header</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Location: http://www.example.com&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</blockquote>
<p>Here&#8217;s a little tip: use the exit statement right after you redirect.</p>
<p>Why? Imagine this: You have some code that runs after the redirect (the user was redirected because he did not have the correct permissions to view the page), and that code updates the user table to change some sensitive data. Obviously, you wouldn&#8217;t want that code to run after the player is redirected, <em>but it could happen</em>.</p>
<p>By using exit immediately after the redirect, you can stop any other code from executing, and make sure that nothing goes wrong!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/02/13/tip-of-the-week/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Good Place to Start</title>
		<link>http://www.pbbgblog.com/2008/02/12/a-good-place-to-start/</link>
		<comments>http://www.pbbgblog.com/2008/02/12/a-good-place-to-start/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 18:36:12 +0000</pubDate>
		<dc:creator>mobeamer</dc:creator>
		
		<category><![CDATA[PBBG Coding]]></category>

		<category><![CDATA[Theory]]></category>

		<guid isPermaLink="false">http://www.pbbgblog.com/2008/02/12/a-good-place-to-start/</guid>
		<description><![CDATA[A lot of people ask how they can start/learn to develop browser based game, hopefully this article will help get them started. This article may be helpful to developers who are struggling to make changes / develop games without disturbing the production version.
The development environment comes into play for both these circumstances. There are a [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of people ask how they can start/learn to develop browser based game, hopefully this article will help get them started. This article may be helpful to developers who are struggling to make changes / develop games without disturbing the production version.</p>
<p>The development environment comes into play for both these circumstances. There are a number of ways to setup your development environment. The solution is both  short and sweet.</p>
<p>Please keep in mind this is only good for development teams of 1 or 2 individuals, you will need to do much more if your team consists of 3+ developers/coders.</p>
<p>I tend to use Uniform Server (http://www.uniformserver.com) as my environment. It&#8217;s a simple download you unzip and click a &#8220;start&#8221; executable. Yes, this is a Windows solution however, there are a number of alternative solutions, just search for LAMP on google.</p>
<p>It runs Apache, mySQL and PHP with a number of utilities. The great part is it&#8217;s less then 2GB so it fits on a flash drive, this means you can work on any windows,  anywhere.</p>
<p>I use that to develop on my local machine.  Once I am ready, I ftp my changed files to the site. (After making the database changes)</p>
<p>Every so often I will download the entire site from production and over write my development file. This helps keep my local version from getting to far from the production version.</p>
<p><em><strong> mobeamer</strong></em></p>
<p><img src="http://www.battleforcesonline.com/images/LongBanner.jpg" alt="Battle Forces Online" height="60" width="468" /><br />
<a href="http://www.BattleForcesOnline.com" title="Battle Forces Online">www.BattleForcesOnline.com</a><br />
<a href="http://mobeamer.blogspot.com/" title="Personal Blog">blogspot.mobeamer.com</a><br />
<em>I am no author but I do have somethings to share.  </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pbbgblog.com/2008/02/12/a-good-place-to-start/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
