Online high scores
by Chris Labombard · in Torque Game Builder · 10/21/2005 (11:34 am) · 6 replies
Does this sound like a feasible idea?
I want to do high score recording, that grabs the current high scores from my web server, and (if you get a high score) spits them back out to the server.
I am pretty sure I could do high score sending (back to the server) by concatinating a string and using it in a goToWebpage statement, maybe encrytping the string so people cant send in false high scores. Will that work ?
Is there a way to grab the current high scores out of the server ?
I want to do high score recording, that grabs the current high scores from my web server, and (if you get a high score) spits them back out to the server.
I am pretty sure I could do high score sending (back to the server) by concatinating a string and using it in a goToWebpage statement, maybe encrytping the string so people cant send in false high scores. Will that work ?
Is there a way to grab the current high scores out of the server ?
About the author
I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.
#2
How do you do this?
I figured out what AES is, but what do you mean by that statement ? What is the post ?
Thank you for your response.
10/21/2005 (1:10 pm)
Quote:you can just fetch the list as a response to a web request
How do you do this?
Quote:The post that implements the AES encryption in the engine
I figured out what AES is, but what do you mean by that statement ? What is the post ?
Thank you for your response.
#3
which assumes you've got the mysql database 'dbName' with a table 'tblScores' that contains colums 'place', 'displayName' and 'score' in it, and that the webserver can access it at localhost by user 'someUser' with password 'somePassword'. (In other words, substitute your own proper info here for your setup).
I've not run that, and it is definitely example code; you'd want to put this in a function and put more checks, output it differently, etc. BUT barring stupid spur-of-the-moment coding errors on my behalf, that should actually function (or be close at least. ;-)
I was referring to this thread that talks about adding AES encryption facilities to the torque engine. I used that page to add console commands for encryption and decryption of strings pretty easily. The hardest part was figuring out and fixing the differences between this AES implementation and Java/PHP's implementation in order to make one capable of decoding the other's encryptions. One of the bigger things I recall running into was that the data block size was padded on one and not the other, so you had to artificially pad the block to an even block size (16 bytes) in order for it to work. There were a few other issues, but nothing too horrendous. Look into the mcrypt stuff in PHP (or the Cipher classes in java) for the server implementation.
10/21/2005 (2:33 pm)
Assuming you have a web server with PHP4 and a mysql database running, you'd create a php page, perhaps "scores.php" which would contain:<?php
$conn = mysql_connect("localhost", "someUsername", "somePassword");
mysql_select_db("dbName");
$query = "SELECT tblScores.place, tblScores.displayname, tblScores.score" .
"FROM tblScores " .
"ORDER BY tblScores.place ASC";
$result = mysql_query($query,$conn);
if (!$result)
{
echo ">NOSCORES";
}
else
{
$scoreList = "";
while (($row = mysql_fetch_assoc($result)))
{
if (!empty($scoreList))
{
$scoreList = $scoreList . "\t" . $row["place"] . "\t" . $row["displayname"] . "\t" . $row["score"];
}
else
{
$scoreList = $row["place"] . "\t" . $row["displayName"] . "\t" . $row["score"];
}
}
echo $scoreList . "\n";
}
?>which assumes you've got the mysql database 'dbName' with a table 'tblScores' that contains colums 'place', 'displayName' and 'score' in it, and that the webserver can access it at localhost by user 'someUser' with password 'somePassword'. (In other words, substitute your own proper info here for your setup).
I've not run that, and it is definitely example code; you'd want to put this in a function and put more checks, output it differently, etc. BUT barring stupid spur-of-the-moment coding errors on my behalf, that should actually function (or be close at least. ;-)
I was referring to this thread that talks about adding AES encryption facilities to the torque engine. I used that page to add console commands for encryption and decryption of strings pretty easily. The hardest part was figuring out and fixing the differences between this AES implementation and Java/PHP's implementation in order to make one capable of decoding the other's encryptions. One of the bigger things I recall running into was that the data block size was padded on one and not the other, so you had to artificially pad the block to an even block size (16 bytes) in order for it to work. There were a few other issues, but nothing too horrendous. Look into the mcrypt stuff in PHP (or the Cipher classes in java) for the server implementation.
#4
What I dont understand is how TGE grabs the data. That php script will send the data to the browser.
Luke, I really appreciate your help.
10/22/2005 (5:06 am)
Ok, I understand how to encrypt and send the data with a gotowebpage statement.What I dont understand is how TGE grabs the data. That php script will send the data to the browser.
Luke, I really appreciate your help.
#5
After you make sure this is running, I'd recommend that you modify it to have the php return some sort of string like "HEREARESCORES" at the start of the $scorelist and then check for that in the torque script. That way you can recognize whether you are getting real scores or a HTTP error message back from the web sitie
10/22/2005 (8:37 am)
Here is a snippet of script code that will request the best scores from the Lukes' php code above and then process it after it receives it. Pretty self explanatory.function dowloadHighScores()
{
// Make the HTTPObject if it doesn't already exist
if (!isObject(DownloadHighScoresObject))
new HTTPObject ( DownloadHighScoresObject );
// Ask web site for the scores
RUploadCourseObject.get("www.basicbob.com:80", "scores.php");
}
function DownloadHighScoreObject::onLine(%this, %line)
{
// For debugging echo out what we are getting back from the web site
echo(%line);
// Only need to do something if we are actually getting scores
if (%line $= ">NOSCORES")
{
// Do whatever you want if there are not scores
}
else
{
%index = 0;
%done = false;
while (!%done)
{
// Get the info for this
%place = getField(%line,%index);
%name = getField(%line,%index+1);
%score = getField(%line,%index+2);
if (%place $= "")
{
// We are done
%done = true;
}
else
{
// Do something with the info
// Step up the index to get the next score info
%index += 3;
}
}
}
}After you make sure this is running, I'd recommend that you modify it to have the php return some sort of string like "HEREARESCORES" at the start of the $scorelist and then check for that in the torque script. That way you can recognize whether you are getting real scores or a HTTP error message back from the web sitie
#6
This is going to be really cool. After I get it all working I'll be sure to try and seperate it and post a full example of working code.
10/22/2005 (9:05 am)
Wow, thanks guys.This is going to be really cool. After I get it all working I'll be sure to try and seperate it and post a full example of working code.
Torque 3D Owner Luke D
Default Studio Name
Server returns something like: 1\tLeetPlayer\t45982\t2\tAnotherLeetPlayer\t123\n function myHTTPObject::onLine(%this, %message) { for(%iii = 0; %iii < getFieldCount(%message); %iii++) { %place = getField(%message, %iii); %name = getField(%message, %iii++); %score = getField(%message, %iii++); // Do something with this score } }You could also do something more robust, where you get one score per line, and then you can enable the initial request to take a range (like start at score 1, end at 100) so you can deal with larger high score lists if you're so inclined.
Encryption is probably a must for submission. The post that implements the AES encryption in the engine is easily matchable by en/decoding on the server in either PHP or Java (just watch for block padding issues), give that a look. It's super-strong and not very processor intensive for short command strings like score-submission is likely to have.