<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Building Browsergames</title>
	<atom:link href="http://buildingbrowsergames.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://buildingbrowsergames.com</link>
	<description>Ever wanted to build a browsergame?</description>
	<lastBuildDate>Mon, 29 Mar 2010 14:00:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>So long, and thanks for all the fish</title>
		<link>http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/</link>
		<comments>http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 14:00:39 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/</guid>
		<description><![CDATA[This post is very difficult to write.
When I started Building Browsergames back up again, I had big plans &#8211; a new design, a cleaner interface, more guest writers. Unfortunately, things didn&#8217;t go quite as I planned &#8211; and that&#8217;s why I&#8217;m writing this today.
Building Browsergames is shutting down. Forcing myself to find more writers and [...]]]></description>
			<content:encoded><![CDATA[<p>This post is very difficult to write.</p>
<p>When I started Building Browsergames back up again, I had big plans &#8211; a new design, a cleaner interface, more guest writers. Unfortunately, things didn&#8217;t go quite as I planned &#8211; and that&#8217;s why I&#8217;m writing this today.</p>
<p><strong>Building Browsergames is shutting down.</strong> Forcing myself to find more writers and games to review and tutorials has had a detrimental effect on quality of the content here &#8211; and when you&#8217;re teaching someone, you need to know what you&#8217;re teaching very well.</p>
<p>By continually trying to post tutorials and reviews under a time constraint, I&#8217;ve done a disservice both to myself, and to the browsergame community. Corners would get cut because the tutorial needed to be up in time, and questions would go unanswered.</p>
<p>I also have my own projects to consider. Faction Wars, while currently in the alpha stages, is doing very well &#8211; and there are a number of other projects that are getting close to that stage themselves. Writing something for Building Browsergames once or twice a week has proven to be too much of a distraction for me to be able to get as much done as I&#8217;d like to on my own projects.</p>
<p>What does this mean for you, the reader? Well, it means a few things:</p>
<ul>
<li>
<h3>Fewer Updates</h3>
<p>I won&#8217;t be writing much anymore. And while I&#8217;d like to publish guest posts from other developers and enthusiasts, no one actually seems interested &#8211; and anyone who does quickly changes their mind. With that in mind, it&#8217;s fairly safe to assume that Building Browsergames will not be updating very often in the near future.</p>
</li>
<li>
<h3>The tutorials stay</h3>
<p>I&#8217;m proud of what was built using the tutorials &#8211; and it even spawned <a href="http://icequest.sourceforge.net/portal/doku.php">an open-source project</a> based on the code. While the code might not be the best I&#8217;ve written, I&#8217;m glad that it&#8217;s helped visitors who wanted to learn to make their own games to get started.</p>
</li>
</ul>
<p>Essentially, Building Browsergames takes up too much of my time for me to be able to afford to keep it running at the level that I have without making some sort of income from it &#8211; and I don&#8217;t want to just plaster the site with ads and let the networks go to town. I don&#8217;t really want to do that to any of you &#8211; so for now, Building Browsergames has to go on a hiatus.</p>
<p>Thanks again to everyone who personally got in touch with me &#8211; there&#8217;s a good community here, and with a little bit of nurturing I think it can go on to achieve great things.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>BBGameZone Contest Winner: Wicked Dead</title>
		<link>http://buildingbrowsergames.com/2010/03/15/bbgamezone-contest-winner-wicked-dead/</link>
		<comments>http://buildingbrowsergames.com/2010/03/15/bbgamezone-contest-winner-wicked-dead/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 14:00:08 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[site-news]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[wicked-dead]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/03/15/bbgamezone-contest-winner-wicked-dead/</guid>
		<description><![CDATA[I managed to get in touch with Hypemaster
from the Browser-Based Game Zone forums to ask him a few questions about his entry in
the BBGZ 2010 PBBG competition. His entry,
Wicked Dead, was the winner of the contest with a 68 point lead over the
next entry. Here&#8217;s what he had to say:
Tell us a little about Wicked [...]]]></description>
			<content:encoded><![CDATA[<p>I managed to get in touch with <a href='http://community.bbgamezone.net/index.php?action=profile;u=2310'>Hypemaster</a><br />
from the <a href='http://bbgamezone.net'>Browser-Based Game Zone</a> forums to ask him a few questions about his entry in<br />
<a href='http://community.bbgamezone.net/index.php/topic,2716.0.html'>the BBGZ 2010 PBBG competition.</a> His entry,<br />
<a href='http://www.fusionbroz.com/wickeddead/'>Wicked Dead</a>, was the winner of the contest with a 68 point lead over the<br />
next entry. Here&#8217;s what he had to say:</p>
<h2>Tell us a little about Wicked Dead.</h2>
<p>Well, the game starts where life ends.</p>
<p>You are dead &#8211; and instead of going to heaven or hell, you&#8217;ve gone to a place called Wicked Dead. You are Wicked Dead! Here, you get a chance for a new life. You need to enter the gates and complete<br />
objectives and battles. For every level you complete, a new one will open &#8211; but if you fail a level,<br />
you&#8217;re bumped back 2 levels. The goal of the game is to complete level 100 &#8211; then you are given a new life!</p>
<p>In the levels you will need to do wicked stuff. If you die you die very painfully, but get reborn<br />
and can improve your stats. Yeah, you read that right &#8211; you can only improve your stats by dying! So<br />
deciding whether to complete a level or die is sometimes a hard decision.</p>
<p>Energy is your life-force &#8211; you need energy to enter a gate and complete the objective. No energy means no fun. You regain energy over time though, so don&#8217;t worry. You also have a stat called &#8216;pain&#8217; &#8211; when you die, your pain goes up. If you have a pain rate higher than 90 you will be unable to access a gate because you are so scared and have so much pain that you can&#8217;t do anything (so don&#8217;t die too much!). Pain goes away over time.</p>
<p>One thing to remember while playing Wicked Dead: not everything is what it seems! There are many tricks in place, and you will also meet other people in the gates.</p>
<h2>What gave you the initial idea for Wicked Dead?</h2>
<p>I was playing a game with some friends and we were losing badly. I was<br />
dying all the time and I thought, why don&#8217;t they make a game where death is<br />
rewarding? And then I started with an idea to make a game which rewards<br />
dying. My first idea was that you needed to try losing, the one who dies first<br />
wins. When I read about the competition I started working on that idea and<br />
then Wicked Dead was born. I changed it a bit, you get better when dying<br />
and you sometimes need to win and sometimes need to lose. Also, luck<br />
is something you will need. And lastly, I like to fool with people so thats also integrated into the game.</p>
<h2>What language did you write Wicked Dead in? What are you hosting it on?</h2>
<p>I used PHP, along with XHTML and MySQL for the database. I have a lot of experience with them,<br />
so it was a logical choice. I&#8217;m using the same shared hosting provider I use for all of my sites.</p>
<h2>What was something that went well during the contest? What was something<br />
that didn&#8217;t?</h2>
<p>Well the first 2 weeks went well, there is really nothing that went bad in<br />
terms of programming. Only thing that took some time was balancing out the<br />
stats and items. But thats something I always invest a lot of time in.</p>
<p>The thing that went bad was time! During the last two weeks of the contest, I almost<br />
didn&#8217;t get time to work on the game! I even forgot to upload my last changes<br />
before the competition ended. But it was no big deal &#8211; the basic idea was in place,<br />
and the update only added pvp and more levels.</p>
<h2>Do you have any plans for Wicked Dead, going into the future?</h2>
<p>At the moment I dont have much time to work on it, but I&#8217;m working on it.<br />
In the future more levels will be added and also a Minion minigame with<br />
aura stones. There are only a few and people will fight for it with their<br />
minions. Upgrading their base and creating minions or towers. The next gate<br />
levels will get more complex, more paths to follow, more choices and more<br />
tricks to fool people. I&#8217;m planning to make 100 levels, but at the moment there are only 18 ready to go &#8211; so there&#8217;s still a lot to do. I&#8217;m not planning to advertise it yet in<br />
the near future, maybe somewhere in the summer. I first want more levels<br />
ready. The problem is that I can&#8217;t make them as fast as people can play<br />
them. And after all, I&#8217;m making it for fun.</p>
<p>Have <strong>you</strong> played <a href='http://www.fusionbroz.com/wickeddead/'>Wicked Dead</a> yet? What did you think of it? Let us know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/03/15/bbgamezone-contest-winner-wicked-dead/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FactionWars is looking for alpha testers!</title>
		<link>http://buildingbrowsergames.com/2010/03/08/factionwars-is-looking-for-alpha-testers/</link>
		<comments>http://buildingbrowsergames.com/2010/03/08/factionwars-is-looking-for-alpha-testers/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:00:28 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[site-news]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/03/08/factionwars-is-looking-for-alpha-testers/</guid>
		<description><![CDATA[One of the games that I&#8217;ve been collaborating with someone on has finally hit the closed alpha stage &#8211; and now, we&#8217;re looking for alpha testers.
Here&#8217;s what we need alpha testers to do:

Play the game.
Diligently report any and all bugs/unexpected behavior using the built-in feedback form.

Interested? You can apply to join the closed alpha program [...]]]></description>
			<content:encoded><![CDATA[<p>One of the games that I&#8217;ve been collaborating with someone on has finally hit the closed alpha stage &#8211; and now, we&#8217;re looking for alpha testers.</p>
<p>Here&#8217;s what we need alpha testers to do:</p>
<ul>
<li>Play the game.</li>
<li>Diligently report any and all bugs/unexpected behavior using the built-in feedback form.</li>
</ul>
<p>Interested? You can apply to join the closed alpha program by submitting your information at <a href='http://bbrowsergames.wufoo.com/forms/faction-wars-closed-alpha/'>http://bbrowsergames.wufoo.com/forms/faction-wars-closed-alpha/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/03/08/factionwars-is-looking-for-alpha-testers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BBGameZone Contest Participant: Tennis Masters</title>
		<link>http://buildingbrowsergames.com/2010/03/01/bbgamezone-contest-participant-tennis-masters/</link>
		<comments>http://buildingbrowsergames.com/2010/03/01/bbgamezone-contest-participant-tennis-masters/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 14:00:17 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[contests]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[tennis-masters]]></category>
		<category><![CDATA[writeup]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/03/01/bbgamezone-contest-participant-tennis-masters/</guid>
		<description><![CDATA[This write-up comes from dbest
from the BBGameZone forums &#8211; he entered the contest with a game
called &#8220;Tennis Masters&#8221;:

Tennis Masters is planned to be an online tennis management game. The
game puts the players in charge of managing their own academy of
tennis players and making them stars. The idea of the game originated
in August 09 and active [...]]]></description>
			<content:encoded><![CDATA[<p>This write-up comes from <a href='http://community.bbgamezone.net/index.php?action=profile;u=5108'>dbest</a><br />
from the <a href='http://community.bbgamezone.net/'>BBGameZone forums</a> &#8211; he entered the contest with a game<br />
called &#8220;Tennis Masters&#8221;:</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/tennismasters/tennis-masters.png' width='450' /></p>
<p>Tennis Masters is planned to be an online tennis management game. The<br />
game puts the players in charge of managing their own academy of<br />
tennis players and making them stars. The idea of the game originated<br />
in August 09 and active development kick started in October 09. The<br />
game is currently being developed by a team of two, using PHP as the<br />
coding language.</p>
<h2>What went right?</h2>
<p>We decided to enter BBGameZone&#8217;s Competition 2010 to complete a<br />
Browser Based Game in a month. The competition deadline was an<br />
incentive for us to complete the game. Before the competition<br />
deadline, we had a rough base code that was ready. We attempted to<br />
leverage the existing code base to complete the game quickly. During<br />
the one month period, we put in a lot of effort in the Match Engine.<br />
The Match Engine of the game is the core of the game and would be<br />
responsible for simulating the matches. Since we realized that the<br />
game would be judged based on usability, we decided to work on the<br />
Help Manuals, so that the user would not be left clueless when<br />
visiting the site.</p>
<h2>What went wrong?</h2>
<p>As evident, since we did not complete the game in time, there was<br />
plenty that went wrong. As both of us happen to be new dads, we had to<br />
balance the time we spent on the game with the new responsibilities in<br />
our lives. There were times when communication was lacking between the<br />
two of us. As we were nearing the deadline of the competition, we<br />
realized that we would not be able to complete the game and decided to<br />
take it a bit easy.</p>
<p>In conclusion, although we did not complete our game in time, we<br />
really cherished being part of the game making competition. We plan to<br />
start our beta season in April and would be happy to see you join and<br />
help us build a better tennis management game. The demo website is at<br />
<a href='http://demo.tennismasters.org'>http://demo.tennismasters.org</a> and our game development forum is<br />
located at <a href='http://dt-games.net/gamesetmatch'>http://dt-games.net/gamesetmatch</a></p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/03/01/bbgamezone-contest-participant-tennis-masters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thursday Press Release: PHudBase, a real-time php game engine + client</title>
		<link>http://buildingbrowsergames.com/2010/02/25/thursday-press-release-phudbase-a-real-time-php-game-engine-client/</link>
		<comments>http://buildingbrowsergames.com/2010/02/25/thursday-press-release-phudbase-a-real-time-php-game-engine-client/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 14:00:07 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[site-news]]></category>
		<category><![CDATA[phudbase]]></category>
		<category><![CDATA[press-release]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/25/thursday-press-release-phudbase-a-real-time-php-game-engine-client/</guid>
		<description><![CDATA[This week&#8217;s release comes from PHudBase, which is an engine for building games using a client/server model in PHP.

PHudBase, a project built by John DeLancey for his upcoming PBBG, has
been released as open-source for the PBBG
community to try out, rip up, and improve upon.
PHudBase (or just PB) is a game engine written in PHP that&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>This week&#8217;s release comes from <a href='http://www.phudbase.com'>PHudBase</a>, which is an engine for building games using a client/server model in PHP.</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/phudbase/screenshot.png' alt="A screenshot of PhudBase" width='445px' /></p>
<p>PHudBase, a project built by John DeLancey for his upcoming PBBG, has<br />
been released as open-source for the PBBG<br />
community to try out, rip up, and improve upon.</p>
<p>PHudBase (or just PB) is a game engine written in PHP that&#8217;s broken up<br />
into two parts &#8212; the server (game engine itself) and<br />
a client that connects using HTML 5 WebSockets.  The engine also<br />
supports Telnet and Flash connections, but that&#8217;s not what it&#8217;s<br />
really about.</p>
<p>The server runs on your webserver using the PHP CLI (command line<br />
interface) module.  It sets up a server that is meant to<br />
run forever, listening for new connections, processing game actions,<br />
and talking to and hearing from your users.</p>
<p>The client is &#8212; really &#8212; just an example of what WebSockets and HTML<br />
5 are going to do for us (Google Chrome is the only<br />
browser that currently supports WebSockets).  It connects to the<br />
server as you&#8217;d expect, with just a few lines of javascript<br />
and no plugins at all.</p>
<p>The codebase &#8212; hosted at Google Code &#8212; contains a very, very basic<br />
game that you can build on top of or completely discard.<br />
You can use anything you want to store your data, and MySQL is<br />
certainly a great choice.  It also supports caching via APC or<br />
memcached (or anything else) with &#8220;hooks&#8221; that you can replace with<br />
the appropriate store/get/delete function calls (it currently stores<br />
every<br />
object in the game in an array in the Game object, itself).</p>
<p>The project&#8217;s homepage is <a href='http://www.phudbase.com'>http://www.phudbase.com</a>, where there&#8217;s a<br />
demo for you to try out and links to the Google Code and<br />
Google Groups pages for you to download and discuss the project.</p>
<p>Do <strong>you</strong> have a press release that you&#8217;d like us to publish? Get in touch by e-mailing <a href='mailto:buildingbrowsergames@gmail.com'>buildingbrowsergames@gmail.com</a>, leaving a comment below, or <a href='http://twitter.com/bbrowsergames/'>following us on Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/25/thursday-press-release-phudbase-a-real-time-php-game-engine-client/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BBGameZone Contest Results</title>
		<link>http://buildingbrowsergames.com/2010/02/22/bbgamezone-contest-results/</link>
		<comments>http://buildingbrowsergames.com/2010/02/22/bbgamezone-contest-results/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 14:00:02 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[site-news]]></category>
		<category><![CDATA[bbgamezone]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[results]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/22/bbgamezone-contest-results/</guid>
		<description><![CDATA[The BBGameZone Competition 2010 is now over &#8211; here are the games that managed to finish something in the month-long time frame:

Qorporate Quest
Wicked Dead
Demons
ModularGaming
Duel Arena

Due to unforeseen circumstances, all of the other entrants were forced to drop out (including yours truly). Better luck next time!

If you were interested in participating in the contest, there&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href='http://community.bbgamezone.net/index.php/topic,2612.0.html'>BBGameZone Competition 2010</a> is now over &#8211; here are the games that managed to finish something in the month-long time frame:</p>
<ul>
<li><a href='http://www.qorporatequest.com'>Qorporate Quest</a></li>
<li><a href='http://www.fusionbroz.com/wickeddead'>Wicked Dead</a></li>
<li><a href='http://demon.megabyet.net'>Demons</a></li>
<li><a href='http://copy112.com/modulargaming'>ModularGaming</a></li>
<li><a href='http://www.duelarena.com'>Duel Arena</a></li>
</ul>
<p>Due to unforeseen circumstances, all of the other entrants were forced to drop out (including yours truly). Better luck next time!</p>
<p></p>
<p>If you were interested in participating in the contest, there&#8217;s a new contest on to build a small game within 24 hours (spread over up to two weeks) &#8211; can view <a href='http://community.bbgamezone.net/index.php/topic,2705.0.html'>view the thread on bbgamezone</a> if you&#8217;re interested.</p>
<p>If you were one of the participants in the contest (whether you finished or not), <a href='mailto:buildingbrowsergames@gmail.com'>get in touch!</a> I&#8217;d like to talk to some of the other participants about their thoughts on the contest and their entries.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/22/bbgamezone-contest-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started With MongoDB (Python)</title>
		<link>http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/</link>
		<comments>http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 14:00:23 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/</guid>
		<description><![CDATA[Now that I&#8217;ve extolled the virtues of using a NoSQL database, it&#8217;s time to put my money where my mouth is and show you how to use one.
To start things off, we&#8217;re going to build a super-simple site using the excellent Bottle Python framework, which is built for building simple sites like this.
This tutorial assumes [...]]]></description>
			<content:encoded><![CDATA[<p>Now that I&#8217;ve <a href='http://buildingbrowsergames.com/2010/02/01/you-should-try-a-nosql-database-today/'>extolled the virtues</a> of using a NoSQL database, it&#8217;s time to put my money where my mouth is and show you how to <strong>use</strong> one.</p>
<p>To start things off, we&#8217;re going to build a super-simple site using the excellent <a href='http://bottle.paws.de/'>Bottle</a> Python framework, which is built for building simple sites like this.</p>
<p>This tutorial assumes that you already have a mongoDB instance up and running somewhere; if you haven&#8217;t done that already, take a look at <a href='http://www.mongodb.org/display/DOCS/Quickstart'>the quickstart on mongodb.org</a>.</p>
<p>First, <a href='http://bottle.paws.de/#download-install'>download and install Bottle</a> (it&#8217;s pretty easy). Once that&#8217;s done, we can start working on building our mini project.</p>
<p>Today we&#8217;re going to build a small &#8216;army manager&#8217; site; users will be able to add, edit, and delete members of their army, and everything we need to track for the user will be stored in our mongodb database.</p>
<p>To start off, we&#8217;ll just make the index page return a template:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> bottle, <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">from</span> bottle <span style="color: #ff7700;font-weight:bold;">import</span> route, jinja2_view <span style="color: #ff7700;font-weight:bold;">as</span> view, debug, run
&nbsp;
DATABASE_HOST = <span style="color: #483d8b;">'localhost'</span>
DATABASE_NAME = <span style="color: #483d8b;">'army'</span>
DATABASE_PORT = <span style="color: #ff4500;">27017</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> pymongo
<span style="color: #ff7700;font-weight:bold;">from</span> pymongo <span style="color: #ff7700;font-weight:bold;">import</span> Connection
connection = Connection<span style="color: black;">&#40;</span>DATABASE_HOST, DATABASE_PORT<span style="color: black;">&#41;</span>
db = connection<span style="color: black;">&#91;</span>DATABASE_NAME<span style="color: black;">&#93;</span>
users = db.<span style="color: black;">users</span>
&nbsp;
SOLDIER_NAMES = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Moe&quot;</span>, <span style="color: #483d8b;">&quot;Curly&quot;</span>, <span style="color: #483d8b;">&quot;Janne&quot;</span>, <span style="color: #483d8b;">&quot;Peter&quot;</span>, <span style="color: #483d8b;">&quot;Paul&quot;</span>, <span style="color: #483d8b;">&quot;Kyle&quot;</span>, <span style="color: #483d8b;">&quot;Chris&quot;</span>, <span style="color: #483d8b;">&quot;Jude&quot;</span>, <span style="color: #483d8b;">&quot;Larry&quot;</span>, <span style="color: #483d8b;">&quot;Gus&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span>
@view<span style="color: black;">&#40;</span><span style="color: #483d8b;">'templates/index.html'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> index<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'user'</span>: current_user,
    <span style="color: black;">&#125;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    ip = request.<span style="color: black;">environ</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'REMOTE_ADDR'</span><span style="color: black;">&#93;</span>
    current_user = users.<span style="color: black;">find_one</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: ip<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> current_user:
        users.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'ip'</span>: ip,
            <span style="color: #483d8b;">'army'</span>: <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>,
        <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
        current_user = users.<span style="color: black;">find_one</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: ip<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> current_user    
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    debug<span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    run<span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">'localhost'</span>, port=<span style="color: #ff4500;">8000</span>, reloader=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>You may have noticed that instead of using the default template renderer, I used the <a href='http://jinja.pocoo.org/2/'>Jinja</a> renderer instead &#8211; which templating engine you use is up to you, but I prefer Jinja.</p>
<p>There&#8217;s a lot going on here &#8211; and if you&#8217;re new to Python, this code probably looks pretty scary. However, it&#8217;s pretty simple once you get the hang of it &#8211; here&#8217;s what we&#8217;re doing:</p>
<ul>
<li>
<p>First, we&#8217;re importing all of the libraries we need, and setting up some of our configuration. This could be split out into another file easily enough &#8211; but for the sake of this tutorial, we&#8217;re going to keep everything self-contained for now. The libraries and helpers we&#8217;ve imported are <em>random</em>, <em>bottle.route</em>, <em>bottle.run</em>, <em>bottle.request</em>, <em>bottle.jinja2_view as view</em>, <em>bottle.response</em>, <em>bottle.debug</em>, <em>bottle.redirect</em>, <em>pymongo</em>, and <em>pymongo.Connection</em></p>
<p>Most of these come from the <a href='http://bottle.paws.de/'>Bottle</a> library, and are designed to help us get our app off the ground faster &#8211; we imported <em>random</em> to be able to choose names for our soldiers, and <em>pymongo</em> to help us work with our MongoDB database.</p>
</li>
<li>
<p>The next thing we did was create our index view &#8211; by saying that Bottle should route the url &#8216;/&#8217; to our &#8216;index&#8217; function. As you can see, all our index function does is retrieve the current user, and return it so that we can render it with our template &#8211; which we specified using our view() decorator.</p>
</li>
<li>
<p>The next thing we do is define a function to retrieve the current user, based on their IP address &#8211; this is our first dive into working with MongoDB. First, we retrieve the IP address of the computer that&#8217;s requesting the page, so that we can track the visitor&#8217;s information. Once we have that, we query our <em>users</em> database, to see if a user exists with our IP &#8211; if there is no user with the IP address we&#8217;re testing for, we create a new user with an empty army, and then return that one.</p>
</li>
<li>
<p>Finally, we have a little bit of utility code to let us test our Bottle app. This piece of code allows us to run our app by navigating to it in the terminal, and then just running &#8220;python app.py&#8221; &#8211; assuming your MongoDB instance is up and running and your dependencies are okay, you should be able to check out your app by navigating to <a href='http://localhost:8000/'>http://localhost:8000/</a>.</p>
</li>
</ul>
<p>If you navigate to your app right now though, you might notice that there&#8217;s a problem &#8211; we don&#8217;t have an index template! We&#8217;ll fix that by creating a template for our app, under templates/index.html:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;</span>
<span style="color: #00bbdd;">       &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Python MongoDB Tutorial<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        Your Army: {{ user.army }}
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">'/add-soldier/'</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">'post'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Add Soldier&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">'/remove-soldier/'</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">'post'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Remove Soldier&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">'/rename-army/'</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">'post'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Rename All Soldiers&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As you can see, we&#8217;re not shattering any barriers with this template &#8211; but it lets us test our app, so it will do for now. Navigate again to <a href='http://localhost:8000/'>http://localhost:8000/</a>, and you should see something like this:</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/mongodb-python/first.png' alt="Your Army: [], Add Soldier button, Remove Soldier button, Rename All Soldiers button" /></p>
<p>With our template all set up, it&#8217;s time to write our views &#8211; starting with the view that lets us add soldiers:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/add-soldier/'</span>, method=<span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> add_soldier<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    army = current_user.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'army'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    army.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>SOLDIER_NAMES<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    users.<span style="color: black;">update</span><span style="color: black;">&#40;</span>
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: current_user<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ip'</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span>,
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'$set'</span>: <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'army'</span>: army,
        <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>
    <span style="color: black;">&#41;</span>
    redirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>For the most part, this view&#8217;s pretty simple &#8211; we want it to be at the url &#8216;/add-soldier/&#8217;, and only responding when users POST to it (by clicking on the &#8216;add soldier&#8217; button in our template). When a user clicks on the button and POSTs to this view, we retrieve their current army (making sure to default to [] if it doesn&#8217;t exist &#8211; this is important!), add a new soldier to it (by appending a random name from our SOLDIER_NAMES variable), and then update the user&#8217;s information in our MongoDB database. Finally, we redirect back to the frontpage so that the user can see their new army.</p>
<p>It&#8217;s important to keep in mind that when you&#8217;re using a schema-less database like MongoDB, you may not actually <strong>have</strong> the properties you&#8217;re expecting to, especially if you haven&#8217;t set them. With that in mind, always be sure to write your code in such a way that it will still work if a an object doesn&#8217;t have the property that you were expecting it to.</p>
<p>If you visit your testing page at <a href='http://localhost:8000/'>http://localhost:8000/</a> now and click the &#8216;Add Soldier&#8217; button, you should notice that your army has increased &#8211; there&#8217;s a new name there!</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/mongodb-python/second.png' alt="Index page with a new army member" /></p>
<p>Now that we can <strong>add</strong> soldiers to our army, we need to be able to remove them as well. Let&#8217;s write a quick view to do that:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/remove-soldier/'</span>, method=<span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> remove_soldier<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    army = current_user.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'army'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>army<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:   <span style="color: #808080; font-style: italic;"># make sure we don't pop from an empty list</span>
        army.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    users.<span style="color: black;">update</span><span style="color: black;">&#40;</span>
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: current_user<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ip'</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span>,
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'$set'</span>: <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'army'</span>: army,
        <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>
    <span style="color: black;">&#41;</span>
    redirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This view is just about the same as our <em>add_soldier</em> view from earlier, except that we&#8217;re removing soldiers instead of adding them before we write the user&#8217;s army into our database. We make sure they actually have soldiers in their &#8216;army&#8217; array, and then we remove one if they do before writing their army back to the database, and redirecting back to the front page.</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/mongodb-python/first.png' alt="Index page, with an empty army" /></p>
<p>With that view written, there&#8217;s only one more to write &#8211; this one will live at &#8216;/rename-army/&#8217;, and update the names of all the soldiers in the user&#8217;s army:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/rename-army/'</span>, method=<span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> rename_army<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    army = current_user.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'army'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    army = <span style="color: black;">&#91;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>SOLDIER_NAMES<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> army<span style="color: black;">&#93;</span>
    users.<span style="color: black;">update</span><span style="color: black;">&#40;</span>
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: current_user<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ip'</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span>,
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'$set'</span>: <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'army'</span>: army,
        <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>
    <span style="color: black;">&#41;</span>
    redirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>As you can see, there isn&#8217;t much changed in this view either &#8211; we retrieve the user and their army, update the value of their &#8216;army&#8217; array, write it to the database, and then redirect them. We use a <a href='http://docs.python.org/tutorial/datastructures.html#list-comprehensions'>list comprehension</a> to update the name of every one of our army members, and that&#8217;s all that&#8217;s special here.</p>
<p>With that, we&#8217;re done! If you visit <a href="http://localhost:8000/">http://localhost:8000/</a>, you should be able to add soldiers, remove soldiers, and rename soldiers &#8211; with all the data being stored in your MongoDB database.</p>
<p>If you&#8217;re stuck, or can&#8217;t seem to get it going, you can download the code for this tutorial at <a href='http://buildingbrowsergames.com/blog/wp-content/downloads/mongodb-python-1.zip'>http://buildingbrowsergames.com/blog/wp-content/downloads/mongodb-python-1.zip</a>.</p>
<h2>Extra Homework</h2>
<ul>
<li>
<p>Our views involved writing a lot of boilerplate code, which can probably be refactored. Write a custom User object that handles storage and retrieval, along with making it easier to interact with the user&#8217;s army.</p>
</li>
</li>
<p>Modify the &#8216;army&#8217; array to store custom Soldier objects, which have a name <strong>and</strong> an attack value &#8211; when a user adds a soldier to their army, randomize both values (some of the work for this has been done for you &#8211; see the download above).</p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Thursday Press Release: Fanta Trade</title>
		<link>http://buildingbrowsergames.com/2010/02/04/thursday-press-release-fanta-trade/</link>
		<comments>http://buildingbrowsergames.com/2010/02/04/thursday-press-release-fanta-trade/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:00:43 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[fanta-trade]]></category>
		<category><![CDATA[press-release]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/05/thursday-press-release-fanta-trade/</guid>
		<description><![CDATA[Hey, game creators &#8211; Building Browsergames is starting a new initiative called &#8220;Press Release Thursdays&#8221; &#8211; if you&#8217;ve got a new game that&#8217;s just getting out there, send us your press release and we&#8217;ll publish it!
To start things off, I have a release from Fanta-Trade, a stock market simulation game:


Fanta Trade is a browsergame where [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, game creators &#8211; Building Browsergames is starting a new initiative called &#8220;Press Release Thursdays&#8221; &#8211; if you&#8217;ve got a new game that&#8217;s just getting out there, send us your press release and we&#8217;ll publish it!</p>
<p>To start things off, I have a release from <a href='http://fanta-trade.eu/index.php'>Fanta-Trade</a>, a stock market simulation game:</p>
<p></p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/fanta-trade/image001.jpg' width='445px' /></p>
<p>Fanta Trade is a browsergame where users are given <strong>100,000 (fanta) euros to invest</strong> when they sign up &#8211; in stocks, commodities, currencies, warrants &#8211; almost everything you can imagine. One of the nice things about Fanta Trade is that stock names and prices are <strong>real</strong> &#8211; so you can become a successful stock trader (or lose it all) without taking any risks in real life. You can also find some elements typical to most browsergames within Fanta Trade: teams, rankings, and a forum in which the best players can be found providing their own take on the market.</p>
<p>Fanta-Trade is a good game for anyone who has an interest in learning how the world of finance works &#8211; or for anyone who wants to face a different kind of competition than &#8220;send your soldiers to the enemy&#8217;s village&#8221;.</p>
<p>Fanta-Trade&#8217;s sophisticated simulation engine works well, and has succeeded in transforming something as complicated as investing in the stock market into something easy and enjoyable for all &#8211; especially those who don&#8217;t know how the market works. And if you get stuck, the vibrant community is always providing tips for the game &#8211; all users can open their own financial blog and start writing their own market analyses, so you can even start dispensing your own advice if you so choose.</p>
<p>Fanta-Trade was created in Italy, so most of the players are Italian &#8211; but it has also been translated into English. You can check it out at <a href='http://fanta-trade.eu'>http://fanta-trade.eu</a>.</p>
<p></p>
<p>Do <strong>you</strong> have a press release that you&#8217;d like us to publish? Get in touch by e-mailing <a href='mailto:buildingbrowsergames@gmail.com'>buildingbrowsergames@gmail.com</a>, leaving a comment below, or <a href='http://twitter.com/bbrowsergames/'>following us on Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/04/thursday-press-release-fanta-trade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You should try a NoSQL database today.</title>
		<link>http://buildingbrowsergames.com/2010/02/01/you-should-try-a-nosql-database-today/</link>
		<comments>http://buildingbrowsergames.com/2010/02/01/you-should-try-a-nosql-database-today/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 14:00:08 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[site-news]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[nosql]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/01/you-should-try-a-nosql-database-today/</guid>
		<description><![CDATA[One of the hottest new web technologies being discussed right now on the web is NoSQL Databases &#8211; with the two I hear about most being CouchDB and MongoDB.
NoSQL databases provide a different approach than traditional relational databases by being &#8217;schema-less&#8217; &#8211; allowing you to quickly and easily add arbitrary data to whatever you need [...]]]></description>
			<content:encoded><![CDATA[<p>One of the hottest new web technologies being discussed right now on the web is <a href='http://nosql-database.org/'>NoSQL Databases</a> &#8211; with the two I hear about most being <a href='http://couchdb.apache.org/'>CouchDB</a> and <a href='http://www.mongodb.org/display/DOCS/Home'>MongoDB</a>.</p>
<p>NoSQL databases provide a different approach than traditional relational databases by being &#8217;schema-less&#8217; &#8211; allowing you to quickly and easily add arbitrary data to whatever you need to. This is a feature that&#8217;s <strong>extremely</strong> well-suited to browsergames &#8211; if you need a certain item to have a specific attribute that no other item has, it&#8217;s easy: you just add it, and move on. In a traditional SQL-based database setup, you&#8217;d need to add a column and make sure it was null or defaulted for all of your other items &#8211; which would be a major hassle if you had a large number of items.</p>
<p>Both the <a href='http://couchdb.apache.org'>CouchDB</a> and <a href='http://mongodb.org/display/DOCS/Home'>MongoDB</a> sites have quickstart guides &#8211; if you haven&#8217;t tried one of the two out already, I highly encourage you to do so.</p>
<ul>
<li><a href='http://wiki.apache.org/couchdb/Basics'>CouchDB Quickstart</a></li>
<li><a href='http://www.mongodb.org/display/DOCS/Quickstart'>MongoDB Quickstart</a></li>
</ul>
<p>If you still need some convincing, here are a few areas in a game where a NoSQL database like Couch or Mongo will be better-suited than a traditional database like MySQL or PostgreSQL:</p>
<ul>
<li>
<h2>Items</h2>
<p>So you have a potion, and potions usually heal people. But for this one super-rare potion, you want to heal the player <strong>and</strong> teleport them to a secret location. How?</p>
<p>In a traditional SQL-based system, you&#8217;d add a column to your <em>items</em> table to track what the potion did, and then add the extra code and handlers so that when a potion of the one super-rare type was used, the player was both healed and teleported. This works, but it&#8217;s a bit of a pain &#8211; you need to create/track a new item type, along with writing the code to handle it.</p>
<p>In a schema-less situation (when you&#8217;re using something like Couch or Mongo), all you have to do is add an attribute &#8216;teleports_player_to&#8217; to your item &#8211; and then in your code, check if the item has a &#8216;teleports_player_to&#8217; attribute. If it does, teleport the player there after running your item handling code. All done!</p>
</li>
<li>
<h2>Quests</h2>
<p>Quests are one area where schema-less storage really shines. You want to keep track of quests a player is on &#8211; but each quest is different! One quest involves killing a certain number of enemies, while another requires you to talk to two different NPC&#8217;s, while yet another needs you to move Important Package A to Secret Location B. How do you track all of that data?</p>
<p>In a relational database, you do it by keeping track of what &#8216;type&#8217; each quest is, along with a small amount of arbitrary information related to that quest. For a &#8220;kill 10 ogres&#8221; quest, you need to track that it&#8217;s a killing quest, you need 10 things killed, and those &#8216;things&#8217; are, in this case, ogres. For a &#8220;delivery&#8221; quest, you need to track which item the player has to have, and which location they need to take it to.</p>
<p>In situations like this, using a relational database to track information for your quests starts to break down very rapidly. What if you wanted to have a quest that required a player to kill 10 ogres, and <strong>then</strong> deliver a package to the town mayor? How would you do that?</p>
<p>With a schema-less database, this is easy. All you have to do is check which attributes you quest has, and write your code to work around them &#8211; so if you wanted to have a quest where users had to kill 28 goblins, talk to the goblin herder and the shepherd, and then deliver the goblin herder&#8217;s letter of surrender to the shepherd, you could &#8211; all you&#8217;d have to do is check the quest attributes.</p>
</li>
</ul>
<p>What other situations can you come up with when a NoSQL database might be superior to using a relational database to track data in your game, or when a relational database is a better option? Let us know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/01/you-should-try-a-nosql-database-today/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Adding a Reward System to your Game</title>
		<link>http://buildingbrowsergames.com/2010/01/25/adding-a-reward-system-to-your-game/</link>
		<comments>http://buildingbrowsergames.com/2010/01/25/adding-a-reward-system-to-your-game/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 14:00:06 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[rewards]]></category>
		<category><![CDATA[topsite]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/01/25/adding-a-reward-system-to-your-game/</guid>
		<description><![CDATA[I was recently contacted by Sunchaser from the BBGameZone forums about membership within the PBBG network for his topsite, top-pbbg.com. As you can see, his membership was accepted &#8211; and I also managed to get him to write a quick tutorial about how to integrate his site into your PBBG &#8211; so that you can [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently contacted by <strong>Sunchaser</strong> from <a href='http://bbgamezone.net'>the BBGameZone forums</a> about membership within <a href='http://pbbgnetwork.com'>the PBBG network</a> for his topsite, <a href='http://top-pbbg.com'>top-pbbg.com</a>. As you can see, his membership was accepted &#8211; and I also managed to get him to write a quick tutorial about how to integrate <strong>his</strong> site into <strong>your</strong> PBBG &#8211; so that you can drive traffic to your game by providing incentives for your players, using a reward system. Here&#8217;s the tutorial in full:</p>
<p><p>It&#8217;s possible to find on the internet a large number of sites that shows a list of browser-based games (these are normally called Topsites, or Toplists). A game owner can register their game into these sites &#8211; and by inserting a voting link in their game, their players can cast their vote for the game. With enough votes, your game can be pushed into the top positions on the topsite &#8211; increasing visibility, <strong>and</strong> driving more traffic to your game.</p>
<p>Some of these sites allow you, the game owner, to configure a <strong>reward system</strong> for your game, so that you can give your players an incentive to vote for your game.</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/pic_1.png' style='width:600px;' /></p>
<p>Once you have configured the reward URL, an example of a voting link would be <strong>http://exampletoplist.com/in.php?u=789&#038;key=12345667</strong>.</p>
<p>The parameter &#8216;u&#8217; will contain the ID of the player that is voting, and the key is a random number. After the topsite has verified the vote, it will call back your configured link (for example, <strong>http://yourgame.com/reward.php?u=789&#038;key=12345667&#038;listname=top_pbbg</strong>). The reward script should check for a corresponding couple (userid + key), and then give the player the reward.</p>
<p>This tutorial will walk you through setting up a system that:</p>
<ul>
<li>Sends a player vote to a toplist, recording the vote</li>
<li>Processes a callback from the toplist</li>
</ul>
<h2>Sending a player vote to a toplist</h2>
<p>In order to trace the votes and prevent cheating, the votes sent to the toplist will need to be recorded within a database table. The first thing we&#8217;ll do is create a database table where we store different toplist sites, along with a table for recording user votes:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`cfg_ranking_sites`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span> <span style="color: #808080; font-style: italic;">--primary key</span>
  <span style="color: #ff0000;">`username`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>      <span style="color: #808080; font-style: italic;">--the username you registered with in the toplist</span>
  <span style="color: #ff0000;">`name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>          <span style="color: #808080; font-style: italic;">--the toplist name</span>
  <span style="color: #ff0000;">`url`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>          <span style="color: #808080; font-style: italic;">--the toplist url (voting links of the toplist)</span>
  <span style="color: #ff0000;">`refererurl`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>   <span style="color: #808080; font-style: italic;">--the toplist root url</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`voting_log`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`user_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`list_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`vkey`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`status`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`ip`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`urlcalled`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`timestamp`</span> timestamp <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CURRENT_TIMESTAMP <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> CURRENT_TIMESTAMP<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM;</pre></div></div>

<p>Next, we&#8217;ll add any topsites we wanted to track into our <em>cf_ranking_sites</em> table (in this case, <a href='http://top-pbbg.com'>top-pbbg.com</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`cfg_ranking_sites`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`username`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`voting_link`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`refererurl`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'vlad'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'top_pbbg'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://www.top-pbbg.com/index.php?a=in&amp;u=vlad&amp;k=KEY'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://www.top-pbbg.com'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Next, we create a file called <em>vote.php</em>, which loads the topsite urls, generates a random key for users, tracks the vote, <strong>and</strong> sends the vote to the topsite. Here&#8217;s the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/****************************************************************************
File:   vote.php
Desc:   traces a vote creating a random key, and sends the vote.
****************************************************************************/</span>
<span style="color: #000088;">$listname</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'listname'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// load data of rating site</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> 
	<span style="color: #0000ff;">&quot;select id, voting_link 
  from cfg_ranking_sites
  where name = '<span style="color: #006699; font-weight: bold;">{$listname}</span>' &quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$list_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$voting_link</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// generate a rnd string</span>
<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">md5</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10000000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the user id from session</span>
<span style="color: #666666; font-style: italic;">// (substitute your method for finding the user id)</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> User<span style="color: #339933;">::</span><span style="color: #004000;">get_char_info</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// place the generated random key and trace the vote</span>
<span style="color: #000088;">$urlcalled</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;KEY&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$k</span><span style="color: #339933;">,</span> <span style="color: #000088;">$voting_link</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;insert into 
	voting_log
  ( user_id, vkey, list_id, ip, status, urlcalled ) 
  values
  ( '<span style="color: #006699; font-weight: bold;">{$u}</span>', '<span style="color: #006699; font-weight: bold;">{$k}</span>', <span style="color: #006699; font-weight: bold;">$list_id</span>, '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 'new', '<span style="color: #006699; font-weight: bold;">{$urlcalled}</span>' ) &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// send the vote</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;location: <span style="color: #006699; font-weight: bold;">$urlcalled</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Next, put your voting link inside a page that&#8217;s visible to your players, so that they can start clicking on it. Make sure the link points to your <em>vote.php</em> file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">'vote.php?listname=top_pbbg'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Vote for us at Top PBBG!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now, your players should be able to vote, and you should be able to record their votes in the table <em>voting_log</em>.</p>
<h2>Processing a callback from the toplist</h2>
<p>Let&#8217;s assume you have configured your reward URL on <a href='http://top-pbbg.com'>top-pbbg.com</a> to be the following reward URL:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">'http://yourgame.com/reward.php?listname=top_pbbg'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Vote for us at Top PBBG!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>To process the toplist callback and give rewards to your player(s), first create a file called <em>reward.php</em> and insert the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Set content type</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Check input, if keys are not present return error.</span>
<span style="color: #666666; font-style: italic;">// This check and the fields needs to be changed for each toplist</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>
	<span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> or 
	<span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'success'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> or
	<span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'listname'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> or
	<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;response rewarded=&quot;0&quot; message=&quot;Invalid input.&quot; /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get data</span>
<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$success</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'success'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$referer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select v.id, v.user_id, r.name
from voting_log v, cfg_ranking_sites r
where vkey = '<span style="color: #006699; font-weight: bold;">{$key}</span>' and v.list_id = r.id
and   refererurl = '<span style="color: #006699; font-weight: bold;">{$referer}</span>'
and   status = 'new'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sql</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// insert your debug message, return error</span>
<span style="color: #666666; font-style: italic;">// mydebug( true, &quot;match not found. ip: &quot; . $_SERVER['REMOTE_ADDR'] . &quot; key: &quot; . $key . &quot; referer: &quot; . $referer);</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;response rewarded=&quot;0&quot; message=&quot;match not found.&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$list_name</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// give rewards to user, only if the vote was unique ($success==1)</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$success</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$r</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//example: give reward and send information to user</span>
		<span style="color: #666666; font-style: italic;">//mysql_query( &quot;update user set char_adamantium = char_adamantium + 2 where user_id = &quot; . $user_id );</span>
		<span style="color: #666666; font-style: italic;">//User::send_news( 'char', $user_id, &quot;You got 2 adamantium for your vote at &quot; . $list_name );</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//example: give reward and send information to user</span>
		<span style="color: #666666; font-style: italic;">//mysql_query( &quot;update user set char_mythril = char_mythril + 2 where user_id = &quot; . $user_id );</span>
		<span style="color: #666666; font-style: italic;">//User::send_news( 'char', $user_id, &quot;You got 2 mythril for your vote at &quot; . $list_name );</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;update voting_log set status = 'rewardgiven' where id = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;response rewarded=&quot;1&quot; message=&quot;Reward given.&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;update voting_log set status = 'rewardnotgiven' where id = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;response rewarded=&quot;0&quot; message=&quot;Reward not given (not unique vote).&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, by changing the code within the if statements above, you should be able to give rewards to your players for voting for your game on different topsites.</p>
<h2>Note</h2>
<p>The script <em>reward.php</em> has been written to process rewards for one toplist &#8211; if you want it to process results from multiple toplists, you will want to have it handle the <em>listname</em> parameter, using that to decide which piece of code to run for which topsite.</p>
<p>And that&#8217;s all there is to setting up your game with a rewards URL! If you&#8217;re interested in doing this for your game, sign up at <a href='http://top-pbbg'>top-pbbg.com</a> and get started &#8211; and then post a link to your game in the comments when you&#8217;re finished.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/01/25/adding-a-reward-system-to-your-game/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
