<?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 &#187; rewards</title>
	<atom:link href="http://buildingbrowsergames.com/tag/rewards/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>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>

