User Account System
by Skylar Kelty · 11/13/2006 (4:37 pm) · 170 comments
---------------------------------------------------------------------------------------------------
Version 3
---------------------------------------------------------------------------------------------------
Version 3.3 - Updated!
download v3.3
Version 3.3 uses Web-Server Interaction and features awards, stats and member panel.
This version requires PHP, MYSQL and TorqueScript Knowledge.
If you have downloaded this before, make sure you clear your browser's cache!
Version 3.2
download v3.2
Version 3.2 uses SQLLite and features awards, stats and member panel.
Version 3.1 - Untested!
download v3.1
Version 3.1 uses xml and features awards, stats and member panel.
---------------------------------------------------------------------------------------------------
Old Versions
---------------------------------------------------------------------------------------------------
Version 2 - No longer supported!
download v2
Version 2 uses SQLite, which is more secure. Some of you may not want to use SQLite, if you dont, use v1.2
Version 1.2 - No longer supported!
download v1.2
Version 1.2 uses the fileobject
---------------------------------------------------------------------------------------------------
ChangeLog
---------------------------------------------------------------------------------------------------
UPDATES:
v1.1 - bug fixes
v1.2 - now uses c++
v2 - now uses SQLite
v3 - Fixes, Updates and 3.3 uses web-server interaction
v3.3 - Updated to.. actually work.. see comments
Version 3
---------------------------------------------------------------------------------------------------
Version 3.3 - Updated!
download v3.3
Version 3.3 uses Web-Server Interaction and features awards, stats and member panel.
This version requires PHP, MYSQL and TorqueScript Knowledge.
If you have downloaded this before, make sure you clear your browser's cache!
Version 3.2
download v3.2
Version 3.2 uses SQLLite and features awards, stats and member panel.
Version 3.1 - Untested!
download v3.1
Version 3.1 uses xml and features awards, stats and member panel.
---------------------------------------------------------------------------------------------------
Old Versions
---------------------------------------------------------------------------------------------------
Version 2 - No longer supported!
download v2
Version 2 uses SQLite, which is more secure. Some of you may not want to use SQLite, if you dont, use v1.2
Version 1.2 - No longer supported!
download v1.2
Version 1.2 uses the fileobject
---------------------------------------------------------------------------------------------------
ChangeLog
---------------------------------------------------------------------------------------------------
UPDATES:
v1.1 - bug fixes
v1.2 - now uses c++
v2 - now uses SQLite
v3 - Fixes, Updates and 3.3 uses web-server interaction
v3.3 - Updated to.. actually work.. see comments
About the author
Recent Blogs
• AFXSpellCooldowns• TGEA material.cs Generator
• Check for update
• Save/Load game system
• DOM, SG and future resources
#142
<?
include("database.php");
$avatarname = mysql_real_escape_string($_GET['ravatarname']);
$q = mysql_query("SELECT * FROM character WHERE charname='$avatarname'");
if(mysql_num_rows($q) > 0)
die("UserTakenn<!--end-->");
if(!mysql_query("INSERT INTO character VALUES ('0', '$avatarname', 'GreenHorn', '1', '1', '1', '1', '1', '1', '')"))
die("MYSQLErrorn<!--end-->");
print "SUCCESSn<!--end-->";
?>
EDIT:
I am still trying to understand all this so bare with me :)
02/06/2010 (11:38 am)
Here is my register avatar page.<?
include("database.php");
$avatarname = mysql_real_escape_string($_GET['ravatarname']);
$q = mysql_query("SELECT * FROM character WHERE charname='$avatarname'");
if(mysql_num_rows($q) > 0)
die("UserTakenn<!--end-->");
if(!mysql_query("INSERT INTO character VALUES ('0', '$avatarname', 'GreenHorn', '1', '1', '1', '1', '1', '1', '')"))
die("MYSQLErrorn<!--end-->");
print "SUCCESSn<!--end-->";
?>
EDIT:
I am still trying to understand all this so bare with me :)
#144
02/06/2010 (2:25 pm)
Well, I got that working but now after creating avatar name I get the unknown error occured, please be scared blah blah lol. I can even close all that out and login and its correct with correct name. Heres the function.function UACOnline::onLine(%this, %line)
{
echo(%line); // spam, use for debugging
if(%line $= "<!--end-->")
{
$uac::result = $web::HTTPTextLines;
$web::HTTPTextLines = "";
if($uac::curfunction $= "register")
{
switch$($uac::lastmessage) // Error handling
{
case "MYSQLError":
MessageBoxOK("Error", "The web server did not send a valid response, please try again later. " @ %result);
case "UserTaken":
MessageBoxOK("Error", "That username is already taken");
case "SUCCESS":
//MessageBoxOK("Sucess!", "Thankyou for registering.");
canvas.popdialog(registerdlg);
canvas.pushdialog(registeravatardlg);
default:
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
}
}
if($uac::curfunction $= "registeravatar")
{
switch$($uac::lastmessage) // Error handling
{
case "MYSQLError":
MessageBoxOK("Error", "The web server did not send a valid response, please try again later. " @ %result);
case "AvatarTaken":
MessageBoxOK("Error", "That username is already taken");
case "SUCCESS":
//MessageBoxOK("Sucess!", "Thankyou for registering.");
//canvas.popdialog(registerdlg);
canvas.pushdialog(registeravatardlg);
//canvas.pushdialog(registeravatardlg);
default:
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
}
}
#145
Also might want to change
To a pop ;p
02/06/2010 (3:07 pm)
Which line specificly does it occur on (just add something to each instance of "An unknown...")Also might want to change
# case "SUCCESS":
# //MessageBoxOK("Sucess!", "Thankyou for registering.");
# //canvas.popdialog(registerdlg);
# canvas.pushdialog(registeravatardlg);
# //canvas.pushdialog(registeravatardlg);To a pop ;p
#146
Thanks
02/06/2010 (3:30 pm)
It accurs in the createavatar function. For some reasion it allways goes to the default msg even tho it creates the avatar and its info.Thanks
#147
add console prints to see what message, if any, is being sent
02/06/2010 (5:05 pm)
Well are you giving it a new message?add console prints to see what message, if any, is being sent
#148
TestGuyAVATARSUCCESS
<!--end-->
TestGuy is the avatars name.
Its working the same as the normal register account except insted of going
somewhere else after success it reads the next line down with is the default message.
default:
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
Here is the msg.
Also , it does not close the register avatar name ui.
02/06/2010 (5:59 pm)
Yes. I changed it to AVATARSUCCESS and I get this as return in console.TestGuyAVATARSUCCESS
<!--end-->
TestGuy is the avatars name.
Its working the same as the normal register account except insted of going
somewhere else after success it reads the next line down with is the default message.
default:
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
Here is the msg.
case "AVATARSUCCESS":
//MessageBoxOK("Sucess!", "Thankyou for registering.");
//canvas.popdialog(registerdlg);
canvas.popdialog(registeravatardlg);
//canvas.pushdialog(registeravatardlg);Also , it does not close the register avatar name ui.
#149
02/06/2010 (6:36 pm)
Here is the uac.cs from client/scripts that I am using.// vote: is dso good enough security for you?
%uac = new GameBaseData(UAC);
$uac::HTTPHost = "localhost:80";
$uac::Location = "/torque/";
$uac::registerPage = "register.php";
$uac::registeravatarPage = "registeravatar.php";
$uac::loginPage = "login.php";
$uac::scorePage = "stats.php";
$uac::awardsPage = "awards.php";
$uac::avatarinfoPage = "avatarinfo.php";
$uac::result = "";
$uac::curfunction = "";
$uac::lastmessage = "";
function UACOnline::onLine(%this, %line)
{
echo(%line); // spam, use for debugging
if(%line $= "<!--end-->")
{
$uac::result = $web::HTTPTextLines;
$web::HTTPTextLines = "";
if($uac::curfunction $= "register")
{
switch$($uac::lastmessage) // Error handling
{
case "MYSQLError":
MessageBoxOK("Error", "The web server did not send a valid response, please try again later. " @ %result);
case "UserTaken":
MessageBoxOK("Error", "That username is already taken");
case "SUCCESS":
//MessageBoxOK("Sucess!", "Thankyou for registering.");
canvas.popdialog(registerdlg);
canvas.pushdialog(registeravatardlg);
default:
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
}
}
if($uac::curfunction $= "registeravatar")
{
switch$($uac::lastmessage) // Error handling
{
case "MYSQLError":
MessageBoxOK("Error", "The web server did not send a valid response, please try again later. " @ %result);
case "AvatarTaken":
MessageBoxOK("Error", "That username is already taken");
case "AVATARSUCCESS":
MessageBoxOK("Sucess!", "Your Avatar is created.");
canvas.popdialog(registeravatardlg);
default:
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
}
}
if($uac::curfunction $= "login")
{
switch$($uac::lastmessage) // Error handling
{
case "MYSQLError":
MessageBoxOK("Error", "The web server did not send a valid response, please try again later. " @ %result);
%this.logout();
case "BADUSER":
MessageBoxOK("Error", "Incorrect username/password");
%this.logout();
default:
if(strpos($uac::lastmessage, "~") > 0)
{
echo($uac::lastmessage);
%array = strSplit($uac::lastmessage, "~");
UAC.Loggedin = true;
UAC.ID = %array.getValue(0);
//UAC.email = %array.getValue(5);
canvas.popdialog(logindlg);
Canvas.setContent(MainLobbyGui);
}
else
{
MessageBoxOK("Error", "An unknown error has occured, please be scared and hide under your desk.");
logout();
}
}
}
$uac::curfunction = "";
}
else
{
$web::HTTPTextLines = $web::HTTPTextLines @ "\n" @ %line;
}
$uac::lastmessage = %line;
}
function UACOnline::onConnectFailed()
{
MessageBoxOK("Error", "Couldnt Connect to web server!");
}
function UACOnline::onConnected()
{
//echo("Connected to page");
}
function UACOnline::onDisconnect()
{
// could put the stuff here instead of using <!--end-->
//echo("Disconnected from page");
}
#150
02/06/2010 (6:38 pm)
/*
* You could use a serial number like thing, where users have to register using their serial number
*/
function UAC::register(%this, %username, %password, %first_name, %last_name, %email)
{
if(strlen($uac::curfunction) > 0)
{
MessageBoxOK("Error", "Please wait for another function to complete");
return;
}
$uac::curfunction = "register";
%querystring = "username=" @%username
@"tpassword=" @%password
@"tfirst_name=" @%First_name
@"tlast_name=" @%Last_name
@"temail=" @%Email;
echo(%querystring);
new HTTPObject(UACOnline);
UACOnline.get($uac::HTTPHost, $uac::Location @ $uac::registerPage, %querystring);
}
function UAC::registeravatar(%this, %avatarname)
{
if(strlen($uac::curfunction) > 0)
{
MessageBoxOK("Error", "Please wait for another function to complete");
return;
}
$uac::curfunction = "registeravatar";
%querystring = "avatarname=" @%avatarname;
//@"tpassword=" @%password
//@"tfirst_name=" @%First_name
//@"tlast_name=" @%Last_name
//@"temail=" @%Email;
echo(%querystring);
new HTTPObject(UACOnline);
UACOnline.get($uac::HTTPHost, $uac::Location @ $uac::registeravatarPage, %querystring);
}
/*
* Something to think about: someone with very little knowledge of TS could easily adapt this
* and produce a bruteforce login system, scary eh?
* It would be wise to port this over to protected c++
*/
function UAC::login(%this, %username, %password)
{
if(strlen($uac::curfunction) > 0)
{
MessageBoxOK("Error", "Please wait for another function to complete");
return;
}
UAC.Username = %username;
//UAC.Password = %password; // Do we really want to store this?
$lpassword = "Password"; // Reset, for security
$uac::curfunction = "login";
%querystring = "username="@%username
@"tpassword="@%password;
new HTTPObject(UACOnline);
UACOnline.get($uac::HTTPHost, $uac::Location @ $uac::loginPage, %querystring);
}
function logout(%this)
{
if(UAC.Loggedin == true)
{
UAC.ID = 0;
UAC.Loggedin = false;
UAC.Username = "";
UAC.Password = "";
UAC.First_Name = "";
UAC.Last_Name = "";
UAC.Email = "";
} else {
//MessageBoxOk("Error!", "Your not logged in!"); // Then it doesnt matter, no need to spam end-users
}
}
function UAC::isloggedin(%this)
{
if(UAC.Loggedin == true)
return true;
else
return false;
}
#151
02/06/2010 (6:39 pm)
function UAC::getcurrentuserdata(%this, %info)
{
switch$(%info){
case "ID":
return UAC.ID;
case "username":
return UAC.Username;
case "password":
return "yehornot";//UAC.Password;
case "first_name":
return UAC.First_Name;
case "last_name":
return UAC.Last_Name;
case "email":
return UAC.Email;
default:
return UAC.Loggedin;
}
}
function UAC::getavatardata(%this, %avatarinfo)
{
switch$(%avatarinfo){
case "ID":
return UAC.ID;
case "avatarname":
return UAC.avatarname;
case "title":
return UAC.title;
case "rank":
return UAC.rank;
case "kills":
return UAC.kills;
case "deaths":
return UAC.deaths;
case "exp":
return UAC.exp;
case "gold":
return UAC.gold;
case "rm":
return UAC.rm;
default:
return UAC.Loggedin;
}
}
#152
02/06/2010 (6:40 pm)
The rest.function UAC::checkloggedin()
{
if(!UAC.isloggedin()){
//MessageBoxOK("Warning", "You are not logged in!"); // Then it doesnt matter, no need to spam end-users
return false;
}
else
{
return true;
}
}
#153
Send me an email @ profile address with zipped code, script and php.
02/06/2010 (10:23 pm)
Could be a php issue, make sure your new liningSend me an email @ profile address with zipped code, script and php.
#154
Now to get the avatar info to show up in a gui for the lobby :)
Thanks again and very sorry for the head ache.
02/06/2010 (10:46 pm)
Well, kinda some good news lol. I did manage to figure that one out. For some odd reason I had to put the registeravatar if function before the create account function now all things are good so far.Now to get the avatar info to show up in a gui for the lobby :)
Thanks again and very sorry for the head ache.
#155
02/07/2010 (8:51 am)
Thats okay :) Glad to hear you got it working!
#156
What I am trying to do now is use the create avatar to update the avatarname field in users table.
Thanks
Edit. Added code tags.
Also, in current state. This code does not seem to pass the correct info to the php file. Even tho I get avatarsuccess when I look at the database table on from phpmyadmin the avatarname field is blank.
02/25/2010 (3:50 pm)
Hi, I am having to start over due to massive laptop melt down and I thought I take a different rout. I have everything compiling and register account working but this time I added AvatarName to the users table.What I am trying to do now is use the create avatar to update the avatarname field in users table.
function UAC::registeravatar(%this, %avatarname)
{
%userID = UAC.getcurrentuserdata("ID");
if(strlen($uac::curfunction) > 0)
{
MessageBoxOK("Error", "Please wait for another function to complete");
return;
}
$uac::curfunction = "registeravatar";
%querystring = "ID="@%userID
@"tAvatarName="@%avatarname;
//@"tname="@%name;
new HTTPObject(UACOnline);
UACOnline.get($uac::HTTPHost, $uac::Location @ $uac::registeravatarPage, %querystring);
}The problem is that my registeravatar.php file works if you pass the info to it. So my big question is how do I change this to get the user ID and insert the %avatarname value and pass it to the php?Thanks
Edit. Added code tags.
Also, in current state. This code does not seem to pass the correct info to the php file. Even tho I get avatarsuccess when I look at the database table on from phpmyadmin the avatarname field is blank.
#157
Hope that helps!
02/25/2010 (5:42 pm)
You use the '&' operator to pass multiple get variables as such:$uac::curfunction = "registeravatar"; %querystring = "ID="@%userID @"&AvatarName="@%avatarname @"&name="@%name;
Hope that helps!
#158
Ill get right to work on it.
Thank you very much.
02/25/2010 (5:49 pm)
O ok , I think I understand. The & symble is to match the string that would be set in the php file like registeravatar.php?username=test&avatarname=testguy.Ill get right to work on it.
Thank you very much.
#159
02/25/2010 (5:58 pm)
I think I see my major problem. Its sending a blank ID so for some reasion its not getting the info. humm..
#160
Did you find a different way of doing things or just quit the project all together?
Thanks
02/26/2010 (12:35 pm)
You mind if I ask what was the reason you stopped working on this?Did you find a different way of doing things or just quit the project all together?
Thanks

Torque Owner Wayne Eversole
Default Studio Name
Got the gui popup working and click type in a name and hit register avatar and I get this.
*** Load Main Menu
username=test password=test first_name=test last_name=test email=test
HTTP/1.1 200 OK
Date: Sat, 06 Feb 2010 15:38:06 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
X-Powered-By: PHP/5.2.9
Content-Length: 18
Content-Type: text/html
SUCCESS
<!--end-->
charname=
Warning! You have a duplicate datablock name of UACOnline. This can cause problems. You should rename one of them.
HTTP/1.1 200 OK
Date: Sat, 06 Feb 2010 15:38:17 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
X-Powered-By: PHP/5.2.9
Content-Length: 193
Content-Type: text/html
<br />
<b>Warning</b>: mysql_num_rows(): supplied argument is not a valid MySQL result resource in <b>C:\xampp\htdocs\torque\registeravatar.php</b> on line <b>8</b><br />
MYSQLError
Window focus status changed: focus: 0
Using background sleep time: 25
<!--end-->