Archive for August, 2007

Game Design: Where to put Saved Game Files

Wednesday, August 22nd, 2007

Here is a little rant, about a pet-peeve of mine. Those of the readers here who own windows boxen and indulge in the habit of PC gaming will probably be able to relate.

By convention most software on windows gets installed into the Program Files folder. There is nothing that enforces this but this is usually how it’s done. So most applications end up having a path that looks something like this:

C:\Program Files\Company Name\Application Name\

There is nothing wrong with that - in fact it keeps things organized and I approve of this convention. It is worth mentioning that non-administrator users do not have write access to the Program Files which is a very good security decision. This precaution means that some random mallware distributing website can’t just cleverly overwrite your applications with it’s own executables.

Of course this also means that an application run by a non-admin user can’t write to it’s own installation folder. This is why Windows provides a seldom mentioned, and often ignored Application Data folder for each user. It is usually located in:

C:\Documents and Settings\Your Username\Application Data\

The sole reason for existence of that folder is to give different applications a user-writable space where they could save their configuration files, temp data and etc. Most of the time however, game designers choose to ignore that folder completely.

When you get home today, do this little experiment - try to figure out where your favorite games keep their saved game files. You should know that anyway for the purpose of backing up, but that’s a whole other story. The games these days usually don’t tell you where thy put your saved data - and rightfully so. It is a low level technical detail that most people (except for us, backup freaks) don’t really care about. Chances are that most of the games you own, save in their installation directory - for example:

C:\Program Files\Company Name\Game Title\Saved Games\

What are the implications of this design choice? Let’s count them together:

  1. You can’t save game as non-admin
  2. Any other user on the system can overwrite your saves
  3. Most games now try to implement some sort of “profile” functionality to allow two or more people to play the same game without mixing their saves and settings - this could be avoided
  4. If you reinstall the game your saves might get deleted
  5. Program Files folder will often not be included in backups (why back up tons of binaries?), but your user profile (including the Application Data folder) usually will be

Why not just put the saved games where they should be in the first place - in Application Data? I understand that they often want to keep everything in one place, but this is not the best idea. And it could save them time and money on creating those in-game profile management systems. Let windows deal with user management stuff.

And no, creating a junction that points a given Saved Games folder to some place in my own Application Data is not a viable solution. Or, rather it will work for me as I am the sole user of my machine. But if you share your gaming rig with room-mates or siblings that will just lock them out of the game. Unless of course you all share the same login, which is just plain stupid.

Sending Emails With Attachments via PHP

Tuesday, August 21st, 2007

If you ever played around with the native PHP mail function, you will probably know that it’s functionality is very basic. Plain text emails work great, but if you want to do HTML email, you need to figure out what mail headers to send with your message. And if you want to send an attachment you need to base64 encode it yourself.

Good news is that you only need to implement it once. Even better news is, that almost every PHP developer out there already implemented their own email class at one point or another. Therefore, you should not be wasting time on this - just go out there and steal some code.

If you are shopping around for a good PHP email functionality I recommend PHPMailer. Why do I like it? Let me count the ways:

  1. Easy to use
  2. No Setup involved - just drop the class files in your include path
  3. Let’s you sen attachments, html emails and etc without any thinking
  4. Works with PHP4
  5. Widely used (included in projects like Mambo, Moodle, PostNuke, Xoops and etc..
  6. Well documented
  7. Distributed under GPL

How easy to use is it? Let me show you. Here is a simple script that will send an email with an attachment:

<?php
require("class.phpmailer.php");
 
$mail = new PHPMailer();
$mail->From     = "you@example.com";
$mail->FromName = "Your Full Name";
$mail->Host     = "smtp.example.com";
$mail->Mailer   = "smtp";
 
$mail->AddAddress("someone@example.com");
$mail->AddCC("supervisor@example.com");
$mail->AddBCC("secret@example.com");
$mail->Subject = "This is Your Subject";
$mail->Body    = "This is your message";
$mail->AddAttachment("~/files/something.zip", "new_name.zip");  // optional name
 
if(!$mail->Send())
{
     echo "There was an error sending the message";
     exit;
}
 
echo "<p>Message was sent successfully</p>";
?>

How is that for simple? It’s a piece of cake! I have been using it for a while now, and I haven’t had any problems with it. So go and steal it today.

River is a Terminator

Tuesday, August 21st, 2007

Jesus, I’m really out of the loop. You guys probably knew about this for at least a 100 years now, but it’s new to me. Apparently the lovely River from Firefly is the new Terminator girl in the upcoming Fox series.

The series is supposed to air in January but the full pilot is out there. Apparently it’s been circulating on various p2p networks for months now. There is also a high quality copy uploaded on the DivX Stage 6. I’m not going to link to it, but it’s not hard to find.

The premiere didn’t really blow me away or anything. But then again it was not horrible either. The acting was decent, the production values and special effects were pretty good. The story… Well, I didn’t really cringe that much or anything. I LOL’d a little bit when it turned out that River is a termie in a most predictable way ever. Oh, look, a hot girl befriends John Connor. Oh look, she just got shot! Oh hey, she is back! Dum dum dum!

The only way they could have made it more obvious is to make her speak with an Austrian accent, and keep telling people she will be back at every possible occasion.

Also, I didn’t know they made the T-800 skeletons in size small. I’m not sure if this is Glau’s acting, or the writing/direction but she kinda fails to sell the emotionless robot look the way Arnold, Robert Patrick and Kristanna Loken did. Or maybe it’s because she has actual lines, while other terminators mostly didn’t (with exception of Arnold who naturally speaks like a robot).

The story seems to take place between Terminator 2 and Terminator 3… But at the end of the pilot, Sarah, John and Termi-River are transported from 1999 to 2007. WTF? I don’t know how is that supposed to work with the movie storyline. I have no clue where are they going with this, and it seems stupid, but perhaps there is a method to their madness.

Anyway, go watch the pilot, and let me know what you think.

Saving Bandwidth and Preventing Hotlinking With Coral Cache

Monday, August 20th, 2007

A while ago Jeff Artwood wrote about “outsourcing” hosting your images to a 3rd party service as a method for minimizing bandwidth costs. This a very practical advice not just for high traffic sites but for just about anyone. You never know when you might get on digg or slashdot and get a significant traffic spike. Jeff outlined various image hosting services in his post, and all of them have certain flaws:

  1. Image Shack and Photo Bucket have prohibitive storage and bandwidth caps
  2. Flickr has an upload cap and a restrictive TOS
  3. S3 is cheep but not free

There is an alternative to offsite image hosting though: Coral Cache.

Coral Cache Logo

The image above is a good example of Coral Cache-ing your images. It is both hosted on my server, and distributed by the Coral Cache service. How is it done? Click on that image and check out the URL. Every time you want to Coral Cache something simply add .nyud.net to the domain name. That’s all there is to it.

If you do it manually for all your larger images you get a fine grained control on which sections of your website are cached and which are not. On the other hand, this approach can become difficult to maintain. If one day you decided you no longer want to use Coral Cache you will have to search and change the URL for each image.

What you really want is to have normal URL’s for all the locally stored files, and then use mod_rewrite to automagically alter all of them to use Coral Cache. For example, if you are like me and you usually upload image files via the browser using Wordpress’ default upload dialog you can use the script below:

RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$
RewriteRule wp-content/uploads/(.*)$ http://www.yoursite.com.nyud.net/blog/wp-content/uploads/$1 [R,NC]

The first two lines are recommended on the Coral Cache wiki. The last line does the actual rewriting.

Put this in a .htaccess file in the root directory of your blog and observe the magic. The first time you load a page it might take a bit longer than usual, but with high traffic, this trick should quickly pay off. I’m not sure how often Coral flushes their cache, but if you have a low traffic site, this might actually slow down the loading a bit if the time between visits is larger than the lifetime of a file in the cache.

Of course the best part about using url rewriting is that you can easily switch it off at any time. When the digg effect subsides, or traffic goes down significantly, and you no longer need the cache you can simply comment out these 3 lines from your .htaccess file. In fact, you can just commend out the last line, as the two conditions can’t really do any damage by themselves.

Note that side effect of this trick is that you no longer need to worry about the hotlinking issue. Since all images will be redirected to the Coral Cache the lazy assholes can hotlink to you all they want. In fact you might as well stick the following two lines right after the Coral Cache conditionals:

RewriteCond %{HTTP_REFERER}!^$ 
RewriteCond %{HTTP_REFERER}!^http://(www\.)?yoursite\.com.*$ [NC]

First line excludes requests without a referrer, while the second one excludes the local requests. You may also want to add few lines here that will exclude Googlebot and other similar services which you may or may not want to index your images. But proper hotlinking prevention strategies are a a topic for a whole new discussion.

Then, when your server gets dugg comment out all the hotlinking related lines, and you go back into ultra-bandwidth saving mode.

Also, please feel free to correct or improve my mod_rewrite code. It is definitely not perfect, but it is functional. I would greatly appreciate any input or constructive criticism here. mrgreen

Update 08/17/2007 06:24:31 PM

Damn it! Phil Haack beat me to it. I wrote this post on the 14th and 15th completely independently from Phil. I was also inspired by the Yslow plugin to do some research on this topic.

Of course I decided to queue this post to appear on Monday the 20th (because I had some other stuff in the pipe) while Phil posted it right away. Oh well…

Update 08/20/2007 11:40:34 AM

Oops. It seems that Coral Cahce wiki got vandalized. Too bad. Let’s hope they get it fixed soon. I tried to restore it back to normal, but it seems that it has been edited by spammers so many times their wiki software “forgot” the good article already. (

Also it’s probably worth mentioning that this caching method should mostly be used for heavy lifting during immense traffic spikes. Using it to cache your images on every-day basis is probably not the best idea as it might and will slow down your page - see Phill Haacks post.

Also, imagered.com is another valid alternative here. You could use the same techniques outlined here to cache your images with their site.

Two Disturbing Sounds

Sunday, August 19th, 2007

Here are some disturbing sounds that will haunt your dreams, give you nightmares and generally creep you out. What you do with them is up to you. You can use these in constructive ways - for example, I know that some game masters like to use music as mood building tools. Putting the Shepard’s Tone track onto your gaming playlist could create hell of a creepy mood for those Call of Cuthullu sessions. Or you can use it for some disturbing pranks - like smuggling the backwards musing onto someones ipod’s easy listening mp3 playlist. )

Anyway here they are:

First up is the Sheppard’s Tone - it is a sound that seems to be continously rising or falling, but really doesn’t. Best description of it I heard was that it is the audio equivalent of a barbers pole - it seems to be moving, but it doesn’t. The sample I have here is really ominous and creepy:

[Sheppard’s Tone OGG Sample]

Second is actually a shortwave radio recording from a Numbers Station. I wrote about these mysterious spy stations in the past. The interesting thing about this stations is that they don’t always use a voice reading off words or numbers. Some use odd music like recordings. I previously linked to the creepy russian polytone sound [direct mp3 link]. This recording is even creepier - it is some music recording played backwards:

[Backwards Music MP3 Sample]

This one literally makes my skin crawl for some reason. Please feel free to link to your picks for ultra creepy and disturbing sounds in the comments. )