T3D HTTPObject

C++, C#, Java, PHP, ect...
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

T3D HTTPObject

Post by hallsofvallhalla »

Posting this here for those that can't read the T3D forums, this is a exact copy of my post...

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);
    

}
i could not find a way to add a & in the url passing without modding source so I used explode in the php script to separate the username and password after the ===.

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...";    
   }
  
}
my only problem now is the accessing database...., i had to put that in there because there is a delay of about 3 - 5 seconds on the information to be retrieved..anyone know why? its localhost..or does anyone know a better way of doing this, like freezing everything until the answer comes back?


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";
	}
?>

just change the values to match your database and fields.
Post Reply

Return to “Coding”