I am new to Torque(purchased a couple days ago) and spent quite a bit of time trying to get my Gui login to work through my mysql database. I searched the forums and found little info on how to get it working and found others wondering the same thing. I am a binary owner only so without source it really made this harder.
I finally got it working so I thought I would post how I got it working. I took from several sources already here. Like I said I am new to Torque so if this is a bad way of doing it or there is a resolve that i missed then I apologize. if someone sees a way for me to make this better please post it. I am still learning how the GUI works with variables and such.
Firstly I build the GUI with username and password fields. Not going to explain that just make sure to name your text fields to username and password.
I then added these functions to the bottom of my login.gui
Code: Select all
function netlogin()
{
%username = $playername;
%password = $password;
%server = "localhost:80";
%path = "/torque/";
%script = "login.php";
%query = "username="@%username@"==="@%password;
%hto = new HTTPObject(CharLogin);
%hto.get(%server,%path @ %script,%query);
}
Code: Select all
function CharLogin::onLine(%this,%line)
{
if (StrStr(%line, "success") != -1)
{
resultguitext.text = "Log in Successful";
return;
}
if (StrStr(%line, "failure") != -1)
{
resultguitext.text = "Username or Password is incorrect";
return;
}
else
{
resultguitext.text = "Accessing Database...";
}
}
here is the php script
Code: Select all
<?php
$username = $_GET['username'];
$exploded_username = explode('===',$username);
$newusername = $exploded_username[0];
$password = $exploded_username[1];
include "connect.php";
$query="SELECT * from torque where username='$newusername' AND password = '$password'";
$query2=mysql_query($query) or die("Could not query players table");
$query3=mysql_fetch_array($query2);
if (isset($query3['username']))
{
echo "success";
}
else
{
echo "failure";
}
?>