gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > How would I go about writing to a website?

#115418 - testforechozero - Mon Jan 15, 2007 11:54 pm

I'm developing a game where I'd like to upload stats to a website. I don't care how (it could be a text file with a user's name and score), I'm just wondering how I'd go about doing this.

#115420 - tepples - Tue Jan 16, 2007 12:08 am

On the client side, you generate an HTTP POST request with a body in URL form encoding. On the server side, you write a script to accept an HTTP POST and add it to the database. Plenty of games for Java and Flash players do this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#115437 - strager - Tue Jan 16, 2007 2:28 am

To further explain Tepple's solution...

If you're running a webserver, you could construct a packet to send to a script as such:
Code:
POST /path/to/record.php HTTP/1.1
Host: www.yoursite.net
User-Agent: Youragent/Version
Content-Length: [length]
Content-Type: application/x-www-form-urlencoded

username=blah&score=blah&whatever


Of course, you want to replace the obvious placeholders with something more meaningful. Also remember that you must URL-encode the data.

Your server script would look something like this:
Code:
<?PHP
$username = $_POST['username'];
$score = $_POST['score'];
// etc.

// record-to-database
?>


If you need help on the specifics of the code, find out what kind of stuff available on your web host (MySql, etc.) or give a template as to how the data is to be stored.

When testing your script, rather than testing the HTTP packet on the DS, try and use telnet. Just a hint. ;)

If a script is pre-written, it shouldn't be to hard to fit your HTTP packet to the form.

#115442 - testforechozero - Tue Jan 16, 2007 3:44 am

Oh, I could understand the server half of it, because i'm no novice to PHP and MySQL.

But what do you mean by URL encode?

#115464 - HyperHacker - Tue Jan 16, 2007 6:33 am

Write it as you would a URL: blah=foo&lol=bar&omgspace=lol,%20spaces

Of course if you just have it send name and score, anyone will be able to send the same from a web browser and fake scores.
_________________
I'm a PSP hacker now, but I still <3 DS.

#115465 - tepples - Tue Jan 16, 2007 6:38 am

Your code can sign and/or encrypt the message contents, but then anybody can ROM-hack your DS game to use its crypto subroutines.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#115467 - HyperHacker - Tue Jan 16, 2007 6:41 am

That's at least more difficult than making your own form in HTML or using a program like netcat.
_________________
I'm a PSP hacker now, but I still <3 DS.