Game Development Community

Databases and Torque 3d

by MarkusDavey · in Torque 3D Beginner · 11/29/2011 (1:52 am) · 16 replies

Hello everyone,

I'm after a database solution for Torque 3d. I've looked at a few database systems, and found that postgreSQL is probably the best to go with licensing wise, but I'm unsure on how to implement it into the engine.

If anyone knows a solution to implementing postgreSQL, or has a suggestion of another database software to use, please leave me a reply.

Thanks.

#1
11/29/2011 (2:11 am)
Forget this, I've found a lovely resource in regards to Torque 3D and postgreSQL integration here:

www.garagegames.com/community/blogs/view/20969

a cached version (for supporting the future!)
Hello future!
#2
11/29/2011 (7:55 am)
We tryed all the Database solutions for our project. While at first we did like the postgreSQL, we had to ditch it after about a week, due to limits in the T3D routines (not T3D itself, but the resource). We ultimately settled on an ODBC connection to a MYSQL database.
I can't remember exactly what resource we used (I think we used several and pieced it together), but here are some great resources for it:
www.garagegames.com/community/resources/view/9656
and the original I think...
www.garagegames.com/community/blogs/view/1921

They are quite old resources, however they still work today. This is one of T3D greatest secrets, so many of the ancient resources still do apply. It pretty cool.
#3
11/29/2011 (7:58 am)
^ I used to like mySQL until the limitations of their new license threw me into hating it. The license basically states that mySQL can only be used if the project it's self is entirely open source.

infact, from what I see here, is that the cheapest commercial implementation of mySQL is 2,000 dollars for a license.

So, postgreSQL it is. I'm sure I can bridge any issues I have with that resouce, but, I just have to get it working first. I have a #include not working for some reason.
#4
11/29/2011 (1:46 pm)
If you like, I still have our working files for postgreSQL on beta 3 should be good on 1.1 or 1.2. Can upload them when I get to the studio if you let me know you need or would like them.
#5
11/29/2011 (11:45 pm)
^ that would be kind if you could. Still having issues compiling.
#6
11/30/2011 (7:09 am)
What are you using the database for? Honestly, connecting directly to a DB from T3D is not secure, because if the T3D server is compromised, then there's a good chance your DB is laying out in the open (the password is usually stored in script or memory).

If you use TCPObject or HTTPObject, then you can put your DB behind a web server (easier to secure against attacks than T3D, and not user-facing since it only connects to the server), and then make requests to the web server for information. As long as your server isn't doing double-duty as a web-site or something, it should work fine.

For some functions, you can offload the work to be done directly from client to web-server, like chat. Hope that helps.
#7
11/30/2011 (7:13 am)
www.atroxnoctis.com/files/pgSQLTorque.zip

And yes there are some security concerns with DB connections, however we run two differnt versions of our title, a client and a server. The server code is locked down, and client code has nothing harmful in it.

I don't think you need anything else to get this to run, if I'm wrong just let me know.
#8
11/30/2011 (7:15 pm)
@Ted

How would you do that may I ask?

@Sven, cheers.
#9
12/06/2011 (1:44 pm)
Do a search there is some info on using the HTTPObject..
heres some partial examples:

function makeDisposition(%name, %content, %isEnd)
{
   if (%isEnd)
      %dispo = %name@"="@%content@"\r\n";
   else
      %dispo = %name@"="@%content@"&";
   return %dispo;
}

function [somefunction]() 
{
   %EWG = (yourfunction)();
   %host =  (address:port);
   %callType = *****
   %reqHead = ****
...
   %dispo = makeDisposition( ****** );
   %dispo = %dispo @ makeDisposition( ***** );
...
   %EWG.request = %dispo;
   %EWG.response = "";
   %EWG.onFinish = "(function to handle response)";
   %EWG.PerformConnect(%host);
}
....
....
function (yourfunction)() 
{
   if (!isObject(EWGConnection)) 
      new HTTPObject("EWGConnection");
   return EWGConnection;
}
function EWGConnection::PerformConnect(%this, %host) 
{
   %this.get(%host, (your php file root), %this.request);
}
function EWGConnection::onConnected(%this) 
{
   //echo("--- HTTP onConnected --");
}
function EWGConnection::onConnectFailed( %this ) 
{
   %this.response = "CERROR_CONNECTFAILED";
   (some function to handle errors);
}
function EWGConnection::onDNSFailed( %this ) 
{
   %this.response = "CERROR_DNSFAIL";
   (some function to handle errors);
}
function EWGConnection::onLine(%this, %line) 
{
   %this.response = %this.response NL %line;
}
function EWGConnection::onDisconnect(%this) 
{
   %this.call(%this.onFinish, %this.response);
}

#10
12/06/2011 (5:46 pm)
Sorry, didn't see the thread 'til now, but John is right- you can look at his example, or do a search for both HTTPObject and TCPObject. You can also check for resources on integrating encryption if you're going to have clients log in through the client software, and have the client pass the hashed password to a simple webpage to verify it on the server-side without T3D even doing the look-up itself (it simply asks an internal web server, and if it's turned down, it just drops the player).
#11
12/09/2011 (6:07 am)
I'm looking into HTTPObjects, I just need to work out how to make the webserver respond to the things that are being passed to it.
#12
12/09/2011 (6:44 am)
Quote: I just need to work out how to make the webserver respond to the things that are being passed to it.

If you're using PHP, then use print() or echo (you can also use die() because you can print messages in it). That's what I do.
#13
12/09/2011 (6:51 am)
Could you give a basic "Helloworld"esque example of this?
#14
12/09/2011 (8:48 am)
I found a few things to do with HTTPObject, some by you oddly Ted. But I've ran into an odd result and I'm not sure if it's by design or not, but whenever my script returns a value, it dumps out the entire header along with it.

eg.

in my browser, the script outputs
1,2,3

but my error outs in torsion say
HTTP/1.1 200 OKDate: Fri, 09 Dec 2011 16:47:35 GMTServer: Apache/2.2.14 (Ubuntu)X-Powered-By: PHP/5.3.2-1ubuntu4.10Vary: Accept-EncodingContent-Length: 7Content-Type: text/html1,2,3\n

^ is there a way to make that just output "1,2,3" like the webpage does?

Cheers.
#15
12/09/2011 (11:11 am)
@Markus: "oddly"? LOL... :p

What I do is have the relevant lines tagged with a code I can read, and then in the onLine() callback, I just filter out all of the other crap. Also helps if you're getting similar values back for different queries, you can sort out the query responses that way.

echo 'RET '.$returnVal;

When that line is echoed in PHP, then the onLine() callback will see "RET" followed by whatever else you put into $returnVal. You can use the getWord() functions on the line returned to the callback to parse it and get whatever information you need out of it.

function HTTPObject::onLine(%obj, %line)
{
   switch$(getWord(%line, 0))
   {
      case "RET": //we got a line we want to look at
         $val = getWord(%line, 1);
         if(!$val) echo("failed");
   }
}

So that above is the callback doing a quick parse on the %line variable and outputting some information to the T3D console if the $returnVal was 0.
#16
12/24/2011 (8:03 am)
@Markus,
I went and looked at the license and don't see anything about being charged to use MySQL. Everything is available under the GPL. Unless you are compiling against the actual MySQL software then there are no licensing issues. Putting it on a machine and using it falls under the GPL. Every database connector I have used contains none of the MySQL codebase or is GPL themselves: PHP, Python, etc. I am sure you could find software to connect to a MySQL database that you can use in a closed source project very easily. I don't see where you think you have to pay to use it. If the software is available as GPL then it is available for non-commercial as well as commercial. If they delineated that point I believe they would be in violation of the GPL itself.