Game Development Community

AccUpdate Problem

by Christian Weber · in Torque Game Engine · 08/30/2003 (9:13 am) · 20 replies

Hi,

I tried to get the "persistant character script" to update the game score. The php script works just fine. There are 3 variables, 2 are old (user,passcrc and score).

I have the following problem, when I call the function i get the error "Invalid Account Name"(So the script doesnt send the information correct to the php file). Here are the scripts.

The functions:

Quote:
function UpdateGameScore(%client, %name, %passcrc, %score)
{
%client = %this.clientid;
//Store the clients passcrc
%client.passcrc = %passcrc;
updateaccount(%client, %name, %passcrc, %score);
//give 30 seconds for response or boot him!
%client.loginLoop = schedule(30000, 0, "clientLoginFailed", %client);
}


function UpdateAccount(%client, %username, %passcrc, %accscore)
{
%client.authReturned = false;
%accquery = "user="@%username@"\t"@
"passcrc="@%passcrc@"\t"@
"score="@%score@"\r";
%accserver = $AuthServer;
%accpath = $AuthServerPath;
%accscript = %accpath @ "score.php";
%accupd = new HTTPObject(AccUpdate);
%client.sendObject = %accupd; //store object details just in case
%accupd.clientid = %client;
%accupd.get(%accserver, %accscript, %accquery);
}

function AccUpdate::onLine( %this, %line )
{
%client = %this.clientid;
//Check if webpage returns the word Updated on the frst line
if(StrStr(%line, "Updated") != -1)
{
messageClient(%client,
'MsgClient', '\c3Account Updated.',
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled,
%client.isAdmin,
%client.isSuperAdmin);
cancel(%client.loginLoop);
return;
}

//otherwise, update failed!
error("- ",%line);
clientLoginFailed(%client);
}

function AccUpdate::onConnectionDied( %this )
{
%client = %this.clientid;
%accerror= "Connection Died";
AccountUpdateFailed(%client, %accerror);
}

function AccUpdate::onDNSFailed( %this )
{
%client = %this.clientid;
%accerror= "Connection Failed";
AccountUpdateFailed(%client, %accerror);
}

function AccUpdate::onConnectFailed( %this )
{
%client = %this.clientid;
%accerror= "Connection Failed";
AccountUpdateFailed(%client, %accerror);
}

function AccountUpdateFailed(%client, %accerror)
{
error("Error: " @ %accerror);
}

The php file:

Quote:
//Check username is valid else error and exit
if(is_null($user) || $user == "" || $user == " ")
{
echo "Auth Server - Invalid Account Name ";
exit();
}

//Check password is valid else error and exit
if(is_null($passcrc) || $passcrc == "" || $passcrc == " ")
{
echo "Auth Server - Invalid Password";
exit();
}

//Check Score is valid else error and exit
if(is_null($score) || $score == "" || $score == " ")
{
echo "Auth Server - No Score to add.";
exit();
}

//Check password and username match
$home = mysql_connect($auth_host, $auth_user, $auth_pass);
mysql_select_db($auth_dbase);
$query = "select * from account where username='$user'";
$result = mysql_query($query,$home);
$row = mysql_fetch_assoc($result);
$temppass = $row['password'];
$username = $row['username'];
$crcpass = crc32($temppass);
$accscore = $row['Kills'];
$allscore = $accscore+$score;

if($user != $username)
{
echo "Auth Server - Incorrect Username ";
exit();
}


if($user == $username && $crcpass != $passcrc)
{
echo "Auth Server - Incorrect Password ";
exit();
}

if($user == $username && $crcpass == $passcrc)
{
//Update score
$home1 = mysql_connect($auth_host, $auth_user, $auth_pass);
$query1 = "UPDATE account SET kills = '$allscore' WHERE username='$user'";
$result1 = mysql_query($query1,$home1);
//Advise Server of updated data
echo "Auth Server - Account updated!";
}


?>

Thx,
Chris

#1
08/31/2003 (2:59 am)
*push* no ideas?
#2
09/05/2003 (10:30 am)
*last push* i dont find the mistake... :-(
#3
09/05/2003 (12:56 pm)
If you're running a recent version of PHP, you need to use $_REQUEST to get to your variables.... They won't be set right.

Also, are you sure you're forming a valid GET request?
#4
09/05/2003 (1:52 pm)
I'm thinking you've got a global register issue. In your /etc/php.ini file, there is a register_globals entry. Set that to On and see if it starts to work.

Gotta warn you though, turning that on can open up some nasty things if you don't filter bad stuff out.
#5
09/05/2003 (9:03 pm)
The better solution is to use $_REQUEST or $_GET or whatever is most appropriate; see us4.php.net/manual/en/reserved.variables.php#reserved.variables.request.
#6
09/08/2003 (8:23 am)
Mhm I still get "Incorrect Password" but it seems like he verifies the accountname.

Quote:

//Call your variables file which should contain the $auth_host, etc variables
//These variables are your sql server variables
require_once("variables.php");

$auth_host = $GLOBALS['auth_host'];
$auth_user = $GLOBALS['auth_user'];
$auth_pass = $GLOBALS['auth_pass'];
$auth_dbase = $GLOBALS['auth_dbase'];

$_GET['user'];
$_GET['passcrc'];
$_GET['score'];

//Check username is valid else error and exit
if(is_null($user) || $user == "" || $user == " ")
{
echo "Auth Server - Invalid Account Name ";
exit();
}

//Check password is valid else error and exit
if(is_null($passcrc) || $passcrc == "" || $passcrc == " ")
{
echo "Auth Server - Invalid Password";
exit();
}

//Check Score is valid else error and exit
if(is_null($score) || $score == "" || $score == " ")
{
echo "Auth Server - No Score to add.";
exit();
}

//Check password and username match
$home = mysql_connect($auth_host, $auth_user, $auth_pass);
mysql_select_db($auth_dbase);
$query = "select * from account where username='$user'";
$result = mysql_query($query,$home);
$row = mysql_fetch_assoc($result);
$temppass = $row['password'];
$userid = $row['userid'];
$username = $row['username'];
$crcpass = crc32($temppass);
$sessions = $row['sessions'];
$accscore = $row['Kills'];
$allscore = $accscore+$score;

if($user != $username)
{
echo "Auth Server - Incorrect Username ";
exit();
}


if($user == $username && $crcpass != $passcrc)
{
echo "Auth Server - Incorrect Password ";
exit();
}

if($user == $username && $crcpass == $passcrc)
{
//Update score
$home1 = mysql_connect($auth_host, $auth_user, $auth_pass);
$query1 = "UPDATE account SET kills = '$allscore' WHERE username='$user'";
$result1 = mysql_query($query1,$home1);
//Advise Server of updated data
echo "Auth Server - Account updated!";
}


?>

Thanks for your help pals.

Chris
#7
09/08/2003 (10:46 am)
$_GET[] is a variable. You need to assign it to a variable, ie:

$user = $_GET['user'];
#8
09/10/2003 (4:25 am)
K, the php file works just fine but the script doesnt send any information to the php file, so i always get the error "Invalid Username".
#9
09/10/2003 (5:55 am)
Did you fix it from what you list above? Cuz what you have above will always give you an invalid username.
#10
09/10/2003 (5:57 am)
Yes, works perfect, the database gets updated but the cs file doesnt work, dont know why.
#11
09/10/2003 (8:58 am)
Maybe your response parsing code is broken?b
#12
09/10/2003 (9:08 am)
I have almost the same script to verify the account, this script works fine, but only if you join a server or start a server, if you call it again later its the same problem. i have no idea why.
#13
09/10/2003 (12:15 pm)
Run a network sniffer and see what data is actually going across the wire. That way you can see if it's a client or server side problem.
#14
09/10/2003 (12:31 pm)
Ok the problem is definantly a client side problem. the doesnt transfer the username, score and the password. this is behind the file "user=&passcrc=&score=" everything important is missing. dont know why, he transfers the data when someone joins, but only one time, it just wont work again.
#16
09/17/2003 (9:49 am)
*last push*
#17
09/24/2003 (1:55 pm)
Could it be that he doesnt know what the variable is?
#18
09/24/2003 (2:45 pm)
Christian Weber: It's because the & characters are converted to %26. To fix that you need to go thru the engine's source code and disable the convertion process. Here is a comment I posted on my News GUI control for receiving news content from a web server
resource

Quote:
To make it possible to do multiple query variables you have to comment out one line of code in the httpObject.cc source code of Torque of void HTTPObject::expandPath.

Just comment out this line:
asciiEscapeTable['&'] = true;
to
//asciiEscapeTable['&'] = true;

Since that is now commented out you can use & to define another query variable infront of another, but there is a bad thing about this. Torque will not beable to convert & to the HTTP standard ASCii code which web server require in order to have a & character in a variable's value field. Same goes for using =, you have to convert it yourself in order to use
it in a variable's value field. I do not know what the code string is for & and =. I'll figure it out here in a few minutes and then I will let you know.

then of course

Quote:
Alright I have the results of the tests I've preformed to get the answers:
%26 is &
%3D is =


Tada, there ya go and enjoy!
:)
#19
09/25/2003 (4:55 am)
Still invalid account name, i'm sure that it is some stupid mistake. well, ok. he doesnt transfer the username or anything for the account update. but he verifies the account well on the start, but when i start the function manually, the same happens "invalid accountname".
#20
10/20/2003 (5:10 pm)
function UpdateGameScore(%client, %name, %passcrc, %score)
{

// undefined var: %this
%client = %this.clientid;
//Store the clients passcrc
%client.passcrc = %passcrc;
updateaccount(%client, %name, %passcrc, %score);
//give 30 seconds for response or boot him!
%client.loginLoop = schedule(30000, 0, "clientLoginFailed", %client);
}