<?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; setup</title>
	<atom:link href="http://buildingbrowsergames.com/category/setup/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>Save bandwidth while improving performance!</title>
		<link>http://buildingbrowsergames.com/2009/02/13/save-bandwidth-while-improving-performance/</link>
		<comments>http://buildingbrowsergames.com/2009/02/13/save-bandwidth-while-improving-performance/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 14:00:32 +0000</pubDate>
		<dc:creator>donbonifacio</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=737</guid>
		<description><![CDATA[Bandwidth can be very troublesome, especially if you&#8217;re at a limited hosting solution, with only a small amount of gigabytes to serve per month. If your site uses a substantial quantity of images and scripts, you may find yourself having a big problem.
Lets imagine that a new user goes to your site and he/she will [...]]]></description>
			<content:encoded><![CDATA[<p>Bandwidth can be very troublesome, especially if you&#8217;re at a limited hosting solution, with only a small amount of gigabytes to serve per month. If your site uses a substantial quantity of images and scripts, you may find yourself having a big problem.</p>
<p>Lets imagine that a new user goes to your site and he/she will need to download 100kb of scripts and images, plus the XHTML page. If you have 50.000 requests, you&#8217;ll serve a significant quantity of bandwidth. And you may even serve static content to old users if you don&#8217;t configure correctly your static content headers.</p>
<h3>Step 1 &#8211; Decouple the static content from the dynamic content</h3>
<p>First you need to prepare your game to be able to get your images/scripts from anywhere. Instead of linking like:</p>
<pre>&lt;img src="/Images/Sample.png" /&gt;</pre>
<p>You need to code your application to link like:</p>
<pre>&lt;img src="http://some_host/Images/Sample.png" /&gt;</pre>
<p>And have the <strong>http://some_host</strong> easily configurable somewhere. That way you&#8217;ll be able to change the location of your static content and make use of <em>content distribution networks</em>. This can be a complex task if you leave it to the end, so you should start as soon as possible using this strategy. Note that this way you may still use your main server URL for static content.</p>
<h3>Step 2 &#8211; Use a Content Distribution Network</h3>
<p>Now that you have a configurable static content location, you have several options to consider. For example, if your game is open source, you may create an account at <a href="http://sf.net">SourceForge.net</a> and then you&#8217;ll have your own web space to use. You could then configure your game to use as a location for static content something like:</p>
<pre>http://your_game_name.sourceforge.net</pre>
<p>And that&#8217;s it! You&#8217;d save a lot of bandwidth and server load just by changing some configuration. But having an open source game isn&#8217;t always an option. Fortunately, there&#8217;s a free content distribution network named <a href="http://www.coralcdn.org/">Coral CDN</a> that is very easy to use. Imagine that your game is at the <em>http://your_game_name.com</em> url and that you configured your static content location to <strong>http://your_game_name.com</strong>. To use Coral CDN you&#8217;d have just to change the static location to:</p>
<pre>http://your_game_name.com.nyud.net</pre>
<p>Appending the <em>&#8220;.nyud.net&#8221;</em> will make Coral to automatically act as a proxy to your content and cache it. For example, you can try it at this site: <a href="http://buildingbrowsergames.com.nyud.net/">buildingbrowsergames.com.nyud.net</a>.</p>
<p>There are other CDN solutions out there, some will cost more money and will be better. A great advantage of CDNs is that they have servers all over the world and will sync your data all over them. So, if your server is in England but you have a user from Japan, the CDN will serve the static content from the nearest server, and your user won&#8217;t need to fetch content from the other part of the world.</p>
<h3>Step 3 &#8211; Configure Static Content Headers</h3>
<p>So, by now you don&#8217;t have to worry about bandwidth, because you&#8217;ll have a third party serving it for you. But there&#8217;s something more you can do to improve user experience. When a browser requests content it may cache it according to the server configuration. But if you don&#8217;t configure the server properly, the browser may ask for the same static file over and over again.</p>
<p>This won&#8217;t be costly for you, but for the user experience. If a user makes a request to your game and the browser has everything cached, the request will be almost instantaneous! However, if the browser needs to refresh data, it may ask for the static content again, and that may implicate that your user will have to wait a second and see loading images.</p>
<h3>Resources</h3>
<p>This article is just an introduction to make you aware of static content problems and how to solve them. To learn more about client side performance, you can study the <a href="http://developer.yahoo.com/performance/rules.html">Yahoo&#8217;s Best Practices for Speeding Up Your Web Site</a>. They have a lot of useful tips, and if you use Firefox, you may install <a href="http://developer.yahoo.com/yslow/">YSlow</a>, an extension that will rate your site in terms of client side performance.</p>
<p>Another great tool to use is something like <a href="http://www.fiddlertool.com/fiddler/">Fiddler</a>, that allows you to see all requests made by the browser, headers, and so on. By using it you&#8217;ll see where you can improve.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/02/13/save-bandwidth-while-improving-performance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hosting Review: Slicehost</title>
		<link>http://buildingbrowsergames.com/2008/07/30/hosting-review-slicehost/</link>
		<comments>http://buildingbrowsergames.com/2008/07/30/hosting-review-slicehost/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 14:00:39 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[hosting]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=120</guid>
		<description><![CDATA[As you may or may not know, Building Browsergames was offline for a short while this weekend. I was transferring Building Browsergames from running off of my own, dedicated server to a Virtual Private Server from Slicehost.
Now, you may be wondering exactly why I made the switch &#8211; and it&#8217;s a fair question to ask. [...]]]></description>
			<content:encoded><![CDATA[<p>As you may or may not know, Building Browsergames was <a href='http://buildingbrowsergames.com/2008/07/24/offline-for-a-while/'>offline for a short while</a> this weekend. I was transferring Building Browsergames from running off of my own, dedicated server to a Virtual Private Server from <a href='http://slicehost.com'>Slicehost</a>.</p>
<p>Now, you may be wondering exactly <strong>why</strong> I made the switch &#8211; and it&#8217;s a fair question to ask. Previously, I was running Building Browsergames off of a single Linux server, affectionately referred to as &#8220;Max&#8221;.</p>
<p>While dedicated hosting allows you to find <a href='http://buildingbrowsergames.com/2008/04/16/what-you-need-to-look-for-in-a-web-host/'>everything you need in a webhost</a>, it also introduces a few things that you need to worry about &#8211; namely, supporting your hardware. If a hard-drive fails, or a system goes down and won&#8217;t come back up, or your website gets slashdotted/dugg and your server starts to melt, that&#8217;s your webhost&#8217;s problem &#8211; <strong>except</strong> for when you&#8217;re running your own dedicated server. In that situation, anything that goes wrong with your system is your responsibility.</p>
<p>I&#8217;m not ready for that responsibility. I have better things to do with my time than work out optimal RAID configurations to make sure there is 0 downtime in the event of a drive failure. But at the same time, I like the flexibility that&#8217;s afforded to me by running a dedicated server &#8211; if I ever need something non-standard, or I want to install a piece of software, I don&#8217;t need to ask anyone &#8211; I simply log in to my server, and install the software. Piece of cake.</p>
<p><a href='http://slicehost.com'>Slicehost</a> provides the best of both worlds; I get the reliability of having a company managing my server so that I don&#8217;t need to worry about drive failures or server meltdowns or anything, but I also get the freedom of having a dedicated system &#8211; only virtualized.</p>
<p>The &#8216;virtualized&#8217; part is a pretty big deal. It means that from Slicehost&#8217;s handy web interface, I can do a lot of mundane(but still useful) things &#8211; things like backing up my slice(their word for &#8217;server&#8217;), rebooting it, <strong>dynamically scaling it up or down</strong>, and even giving it a handy name to remember it by(my slice is named &#8216;Max&#8217;, just like the server it&#8217;s replacing).</p>
<p>There are lots of neat (and handy) things that you can do with Slicehost &#8211; but one of the biggest ones is that you can <strong>dynamically scale your slices</strong>.</p>
<p>What does that mean? For a developer who&#8217;s building a game on the cheap, it means Great Things. You can start your game with their basic slice, for $20/month &#8211; and run as many websites as you want to off of that single slice. You can even have a single slice for a single website, if you want to. At least to begin with, the starter slice will probably be more than enough for a fledgling browsergame &#8211; and with the ability to size it up as you need to, it&#8217;s the perfect way to expand without any of the hassle of re-configuring servers.</p>
<p>Want to know about some other cool features? With all but Slicehost&#8217;s biggest slice size, you can get a backups plan &#8211; for a little bit extra every month, you can keep 3 exact images of your slice. You get one daily backup, one weekly backup, <strong>and</strong> the ability to create &#8217;snapshots&#8217; of your slice &#8211; essentially allowing you to roll-back to any time that you want to(I took one just after I finished the server migration, as an insurance policy in case anything went wrong afterwards).</p>
<p>You can also dynamically add slices to your slicehost account &#8211; although each slice does have a monthly cost associated with it. And if you&#8217;ve also purchased the backups option, you can create slices based off of your other slices &#8211; which means that should I ever want a slice with the exact same configuration as my &#8220;Max&#8221; slice has, all I need to do is go to &#8220;Add a Slice&#8221;, and select a snapshot of Max to use as the system Image(If you don&#8217;t have a snapshot or want a fresh system, you can choose from a few Linux distributions &#8211; Ubuntu 6/7/8, Arch 2007.08, CentOS, Debian, Fedora, and Gentoo).</p>
<p>I had Slicehost recommended to me by someone I respect very much, who justified his choice by saying &#8220;if your core competency isn&#8217;t hosting, why are you focusing on it?&#8221; &#8211; and he&#8217;s right. And if your core competency is building browsergames, you should be focusing on that &#8211; not on getting niggling hardware details in place for your servers. I will warn you that you need at least some experience with the command line in Linux to get started &#8211; but if you&#8217;re really stuck, there are some great tutorials on <a href='http://howtoforge.org'>HowToForge</a> that will get you up and running in no time.</p>
<p>If you&#8217;re thinking about signing up for Slicehost, consider using <a href='https://manage.slicehost.com/customers/new?referrer=3006273395'>my referrer link</a> &#8211; while it (unfortunately) won&#8217;t result in any discounts for you, it will get me a slight reduction in the costs for my slice. If you&#8217;d rather register without giving me anything, you can use <a href='https://manage.slicehost.com/customers/new'>this non-referral link</a> &#8211; or just visit <a href='http://slicehost.com'>their website</a> to learn more.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/07/30/hosting-review-slicehost/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Building Browsergames: Getting started with a templating system (Perl)</title>
		<link>http://buildingbrowsergames.com/2008/05/18/building-browsergames-setting-up-a-templating-system-perl/</link>
		<comments>http://buildingbrowsergames.com/2008/05/18/building-browsergames-setting-up-a-templating-system-perl/#comments</comments>
		<pubDate>Mon, 19 May 2008 03:00:47 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[buildingbrowsergames]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=36</guid>
		<description><![CDATA[So far we&#8217;ve built a registration page and a login page for our game, but not much else. That&#8217;s because we&#8217;re hitting a bit of an important milestone for our game: what templating system will we use?
It&#8217;s important to choose a templating system before you start building any functionality more complex than your registration and [...]]]></description>
			<content:encoded><![CDATA[<p>So far we&#8217;ve built a <a href='http://buildingbrowsergames.com/2008/04/18/building-browsergames-the-registration-page-perl/'>registration page</a> and a <a href='http://buildingbrowsergames.com/2008/04/25/building-browsergames-the-login-page-perl/'>login page</a> for our game, but not much else. That&#8217;s because we&#8217;re hitting a bit of an important milestone for our game: what templating system will we use?</p>
<p>It&#8217;s important to choose a templating system before you start building any functionality more complex than your registration and login system &#8211; it will help you speed up your development time, and keep your code and your design separate. If you&#8217;re like me, that means that you can safely pass your template off to someone who actually <strong>can</strong> design, and get them to work their magic on your template &#8211; without having to worry about your code breaking.</p>
<p>To that end, what Perl templating systems are there out there?</p>
<p>There are a lot of Perl templating systems available. There&#8217;s <a href='http://search.cpan.org/~abw/Template-Toolkit-2.19/lib/Template/Toolkit.pod'>Template::Toolkit</a>, and <a href='http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm'>HTML::Template</a>, and scores of others. For the sake of this quick guide, I&#8217;ve chosen to use HTML::Template &#8211; although really, you can use whatever templating system you want to(although my examples will all use HTML::Template).</p>
<p>To begin with, we need to install HTML::Template. There are a number of ways to go about this, and if you&#8217;ve never installed a Perl module before I recommend that you read <a href='http://www.cpan.org/modules/INSTALL.html'>this guide to installing CPAN modules</a>, and then install HTML::Template on your system. Alternately, a lot of systems with Perl on them come with the cpan shell &#8211; at which point all you need to do to install the module is run this command:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="shell" style="font-family:monospace;">cpan install HTML::Template</pre></td></tr></table></div>

<p>At this point, HTML::Template is installed &#8211; so let&#8217;s build a quick tester script to take advantage of that. First off, we&#8217;ll set up the template for the index page that <a href='http://buildingbrowsergames.com/2008/04/25/building-browsergames-the-login-page-perl/'>our login page from earlier</a> sends non-administrator users to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;My Index Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;p&gt;Hello, &lt;!--tmpl_var name='username'--&gt;!&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>It looks like a regular HTML file, doesn&#8217;t it? And that&#8217;s the great thing about templating systems. With a templating system, <strong>you can write regular HTML and just intersperse markers for whatever content you&#8217;re going to dynamically add</strong>, instead of hard-coding your content into your template.</p>
<p>We&#8217;ll call that template file <strong>index.tmpl</strong> &#8211; our index page will load it in when it outputs the user&#8217;s information. Really, you can use whatever extension you like &#8211; I just like .tmpl.</p>
<p>The next thing we need to do is write the code for the page that actually loads in and outputs the template. Here&#8217;s what that looks like:</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
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>cgi<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> HTML<span style="color: #339933;">::</span><span style="color: #006600;">Template</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cookie</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'username+password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\+/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$template</span> <span style="color: #339933;">=</span> HTML<span style="color: #339933;">::</span><span style="color: #006600;">Template</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span>
		filename	<span style="color: #339933;">=&gt;</span>	<span style="color: #ff0000;">'index.tmpl'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span>username	<span style="color: #339933;">=&gt;</span>	<span style="color: #0000ff;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">output</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>All we do in this code is load in the value of the cookie that we set in our login page &#8211; named &#8216;username+password&#8217;. Then, we split it based on &#8216;+&#8217;, to return our username and password &#8211; because we only need the username, we discard the password:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>10
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\+/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This obviously shows us that there&#8217;s a bit of a problem with our cookie &#8211; if a user signs up with a &#8216;+&#8217; in their username, our split will no longer work! One good way to work around this is to use something a little more complex to divide our username and password, or modify our code slightly to use a regular expression capture instead of split:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>10
11
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$cookie</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(.+)\+/</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This way, we&#8217;ll retrieve all information that comes before the last &#8216;+&#8217; sign &#8211; because <a href='http://perldoc.perl.org/5.8.8/functions/crypt.html'>crypt</a> returns characters in the set [./0-9A-Za-z], we don&#8217;t need to worry about a &#8216;+&#8217; sign cropping up and wrecking our regular expression.</p>
<p>Once that&#8217;s done, all we do is create a new template object, tell it where to load our template from, and then populate the paramater &#8216;username&#8217; with the value we pulled out of our cookie. And then we&#8217;re finished!</p>
<p>As you can see, working with a templating system isn&#8217;t that hard &#8211; and the gains you make by being able to instantly use the same template accross many pages are huge. There&#8217;s really no reason <strong>not</strong> to be using some sort of templating system &#8211; whether you roll your own, or use a pre-existing system.</p>
<p>If you want to see the example code in action, <a href='http://buildingbrowsergames.com/sandbox/register.cgi'>register</a>, and then <a href='http://buildingbrowsergames.com/sandbox/login.cgi'>login</a>, and you&#8217;ll be redirected to the index page &#8211; which will display the value out of our cookie.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/05/18/building-browsergames-setting-up-a-templating-system-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building Browsergames: Getting started with a templating system (PHP)</title>
		<link>http://buildingbrowsergames.com/2008/05/16/building-browsergames-setting-up-a-templating-system-php/</link>
		<comments>http://buildingbrowsergames.com/2008/05/16/building-browsergames-setting-up-a-templating-system-php/#comments</comments>
		<pubDate>Fri, 16 May 2008 14:00:16 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[buildingbrowsergames]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=35</guid>
		<description><![CDATA[When you start building significant pieces of your game beyond the basic login and registration systems, you start to realize that you&#8217;re copying and pasting the basic layout of your pages a lot. Wouldn&#8217;t it be nice to have a template that you can drop all of the unique content into, and re-use on every [...]]]></description>
			<content:encoded><![CDATA[<p>When you start building significant pieces of your game beyond the basic login and registration systems, you start to realize that you&#8217;re copying and pasting the basic layout of your pages a lot. Wouldn&#8217;t it be nice to have a template that you can drop all of the unique content into, and re-use on every page?</p>
<p>The answer is that you can &#8211; and should. It will help you separate your design from your code, which(if you&#8217;re anything like me) means that you can have someone with actual designing skills come through and fix up your template before you push your site out to the rest of the world.</p>
<p>This will be a brief rundown on how to get up and running with a templating engine, which is what we will be using to build all of the other parts of our browsergame in progress. For a PHP templating engine, I&#8217;ve chosen Smarty. I did this by taking a look at <a href='http://www.smarty.net/rightforme.php'>Smarty&#8217;s list of features</a>, and deciding whether I liked them or not &#8211; when you choose a templating engine, that&#8217;s really all the forethought you need to put into it &#8211; will it work for you, and are you okay with working with it? As an aside, if you don&#8217;t like your templating system you can always switch systems for your next project.</p>
<p>A lot of developers are fans of &#8220;rolling their own&#8221; templating system. While this can definitely work, you&#8217;re probably going to make larger gains by simply using an existing one &#8211; if you need anyone to help you with your game later(or it really takes off and you hire someone), it will be a benefit to be using a system that they might already know as opposed to a proprietary system. Also, why do all that work when it&#8217;s already been done for you?</p>
<p>The Smarty website has a <a href='http://www.smarty.net/quick_start.php'>smarty quick start tutorial</a>, which you can use to get yourself up and running with Smarty.</p>
<p>Once you&#8217;ve gotten Smarty set up on your system, we&#8217;ll be building the index page that <a href='http://buildingbrowsergames.com/2008/04/24/building-browsergames-the-login-page-php/'>our login page from earlier</a> redirects to for non-administrator users. To start off with, we&#8217;ll just use the testing <strong>index.tpl</strong> file from the Smarty quick start:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;My Index Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;p&gt;Hello, {$name}!&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Next, we&#8217;ll use the <strong>index.php</strong> file from the Smarty quick start, and modify it so that it displays the currently authenticated user&#8217;s username:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// put full path to Smarty.class.php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/usr/local/lib/php/Smarty/Smarty.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Smarty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/web/www.domain.com/smarty/templates'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compile_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/web/www.domain.com/smarty/templates_c'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cache_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/web/www.domain.com/smarty/cache'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/web/www.domain.com/smarty/configs'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>As you can see, there isn&#8217;t that much of a change made &#8211; we add a call to <a href='http://ca3.php.net/manual/en/function.session-start.php'>session_start()</a> to load up our previously stored session values, and then we use one of them to display the user&#8217;s username. If you visit your testing page, you should see the username that you logged in with &#8211; which means that Smarty is working! With Smarty we&#8217;ll be able to make sure that our code and designs no longer have to be intermingled &#8211; meaning that there&#8217;s less chance of accidentally screwing up one while working on the other.</p>
<p>If you want to see it in action, you can first <a href='http://buildingbrowsergames.com/sandbox/register.php'>register</a>, then <a href='http://buildingbrowsergames.com/sandbox/login.php'>login</a> to get redirected to the index page &#8211; which will show you the username you&#8217;re currently logged in with.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/05/16/building-browsergames-setting-up-a-templating-system-php/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>What you need to look for in a web host</title>
		<link>http://buildingbrowsergames.com/2008/04/16/what-you-need-to-look-for-in-a-web-host/</link>
		<comments>http://buildingbrowsergames.com/2008/04/16/what-you-need-to-look-for-in-a-web-host/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 14:00:51 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[hosting]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=8</guid>
		<description><![CDATA[There are a lot of web hosting companies out there, and all of them offer different things. It&#8217;s hard to decide which one to use, and which features you actually need when you&#8217;re choosing a web host for your browsergame.
To begin with, you don&#8217;t need dedicated hosting. Shared hosting will work just fine for both [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of web hosting companies out there, and all of them offer different things. It&#8217;s hard to decide which one to use, and which features you actually need when you&#8217;re choosing a web host for your browsergame.</p>
<p>To begin with, you don&#8217;t need dedicated hosting. Shared hosting will work just fine for both testing and the initial game &#8211; it&#8217;s only once you hit massive numbers of users that you will need dedicated hosting.</p>
<p>One thing you need to make <strong>absolutely sure of</strong> is that your host has some sort of database, and supports your choice of server-side language. Make sure to confirm that the version of the language that they have is the one you need &#8211; I know people who have needed PHP 5 but accidentally started a web hosting contract with a company that only had PHP 4 &#8211; it caused them a lot of headaches before they finally switched.</p>
<p>Filespace and bandwidth are something people will always argue about. At the core of it, as long as you have enough filespace for your files, and enough bandwidth to get them out to your audience, you&#8217;re fine. What does that mean? If your browsergame is purely code and your browsergame is the only thing on that hosting plan, you&#8217;re probably safe with 50MB. If you have a lot of images in your game or your game is <strong>absolutely massive</strong>(Wordpress is under 2MB of PHP), then you might need more &#8211; but for most cases, 50MB will be fine.</p>
<p>When it comes to bandwidth, go with something that seems &#8216;big enough&#8217;. To begin with, you&#8217;ll never get close to using as much bandwidth as you have available. When you do start coming close or hitting your cap, it&#8217;s a sign that you should upgrade.</p>
<p>Another important thing to consider is stats packages. You should check to see what sort of stats package your web host makes available &#8211; this will be important after you launch your game, so that you can keep track of how many visitors you have, what time of the day most people play your game, and other neat statistics.</p>
<p>One last consideration is databases. Some hosts will give you an unlimited number of databases, and some will cap you at a number like 5. If your browsergame is the only thing on that hosting plan, you&#8217;d be fine with one &#8211; the general consensus is one database per project, unless you don&#8217;t have enough available. So as long as your host provides one or more databases, you should be fine in this regard.</p>
<p>There are a few other options that web hosts will offer you &#8211; things like Fantastico(which is an automated installer for a bunch of popular website tools), POP Accounts, FTP Accounts, and a whole bunch of other things. As long as your host gives you at least one FTP account, you&#8217;ll be fine.</p>
<p>With all that being said, it sounds like choosing a web host is a difficult task. But it&#8217;s actually very easy. Here&#8217;s the condensed list of what you need:</p>
<ul>
<li>Support for your server-side language(the language <strong>and</strong> the version you will be using)</li>
<li>Databases(at least one)</li>
<li>Enough filespace to host your project &#8211; anything at or over 50MB should be fine to start with</li>
<li>At least one FTP account, so you can upload your files</li>
<li>Some sort of stats package(although if they don&#8217;t provide one, you could use <a href='http://www.google.com/analytics/'>Google Analytics</a>)</li>
</ul>
<p>One last thing that I haven&#8217;t mentioned here is price. That&#8217;s because it&#8217;s entirely up to you what you pay for hosting. I would recommend something cheaper to begin with, because even if your game has a business model behind it, you probably won&#8217;t be making any income from it for at least the first few months &#8211; so you should choose a web hosting plan you can afford to pay out of your own pocket.</p>
<p>And that&#8217;s all there is to it. If you&#8217;re still not sure which host to use, I recommend <a href='http://atomhost.com/'>Atomhost</a> &#8211; before I started hosting my own websites, they were the host I used and their support team is top-notch &#8211; they have a good understanding of any technical problem you may have. Also, if you keep a close eye on their homepage you can sometimes find promo codes that will knock down the price of whatever plan you are considering.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/04/16/what-you-need-to-look-for-in-a-web-host/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

