Game Development Community

Connecting torque3D 3.0 MIT to a MySQL database

by Zeph · in Torque 3D Beginner · 08/20/2013 (10:46 pm) · 10 replies

Ive managed to get a working MySQL database connected to a website form for registration of account names, and other information with PHP5.

Note: The web registration information saves to the MYSQL web Database. The client, game server, and master server is on one computer temp until I get the funds to do otherwise.

Ive attempted to get Torque 3D 3.0 MIT to connect to this database for username, and password which is free hosted on a website, that offers MYSQL. Ive Used the Torque tutorials in resources. And Torque 3D cleint seems to be having issues communicating with the MYSQL Data base server with no replys back. In the command log console it shows that Torque 3D is attempting communication but hangs. Im not even sure if its leaving the client side or if it might be Database side.

Im not trying to point fingers, but... Maybe the tutorials are outdated, and usable for older versions of Torque 3d. Maybe theres a problem with the free website theres no support offered there. Maybe its Microsoft MSQL, or the New PHP5 code. Being new to this I have no real way of KNOWING what might be the issue unless someone with experience, and knowledge gives me some advice. Which I would greatly appreciate.

Im new to this, and this is my first attempt ever to get a game client to connect to database. Im really lost, and confused, and I would like to solve this, and learn.

Anyone with experience in this field who might be able to give me advice or point me into the right direction. Is there a work around, and or who actually KNOWS what the issues might be on getting the client to make a connection to the database?

Thanks everyone :P

#1
08/21/2013 (1:17 am)
What resource are you using to use T3D to connect to a database?

Do you have example code in TS (Torque Script) I assume?

Use
Quote:[code][/code]
tags to make the code show up correctly in your messsage.

What does the PHP look like? Show us some example code as well.

#2
08/21/2013 (4:03 am)
Well, of course the tutorials are outdated as they're made for earlier versions of the engine.

With that said however, nothing is stopping MySQL from working in T3D. If it doesn't work, then there's either:

1. Issues in the resource implementing the MySQL client.
2. Issues with firewalls.

You can fetch error messages from MySQL which describe (on the client side) what it thinks is going wrong. That will be extremly useful in tracking down the problem.
#3
08/21/2013 (5:51 am)
Most websites dont allow direct access to the databases and limits access to localhost and specific listed users.

I can only think of 2 solutions off the top of my head,

1) get torque to communicate with the PHP pages directly since they do have the database access and then get the info from the pages

2) Find a database that you can access directly, probably the easiest wa would be to set up some kind of VM and use that as the database server.
#4
08/22/2013 (8:19 am)
What Bloodknight said, any free webhost is not going to allow direct access to the database. You'll need to make a request to a php page and have it return the data.

I found a nice JSON library someone wrote for Torque Script, makes it easy to work with a php service that returns JSON data https://github.com/portify/jettison

Also the HTTPObject in T3D is broken and doesn't work right. Hopefully my pull request gets accepted soon.
#5
08/22/2013 (8:34 am)
The way I do this is by means of a TCPObject connection to a php script which can access the MySQL database.

As mentioned above, you will likely need a paid web host to be able to use this feature, unless you host your own server with PHP/MySQL since free hosts don't allow PHP/MySQL.

I have a resource somewhere in my old ones that provided a sample script to connect to a PHP script, you'd have to write the PHP yourself. Also, the TCPObject is prone to random access violation errors for some unknown reason so keep that in mind if you plan on using it.

Also, if you are doing an account system, and need to offer a level of security, I would recommend taking a look at my XXZ568 account system resource, or my Multiplayer Assembly Package, which provides this and a cURL implement to get around needing the TCPObject.

Either way, I'd get a web host situated first before tackling this issue.
#6
09/16/2013 (8:25 am)
Thanks for the input guys.. Yes the website I used was free. If its a firewall issue I prob wont know since they dont offer support, and I dont have access to their machines, nor have they ever replied back to me.

I read the article on the HTTP Object being broken. I just wasnt sure if it was fixed, and this might have been also part of the issue with T3D communicating with the web database. Might be both that and the free hosting really lol. Like I said it didnt seem like any of the tutorials worked, and it left me confused as to where the problem was. Would be nice to have a solid work around to the HTTP Object.

I also tried to use the same structure in the Web PHP script that was used to write to the database in reference to get torque to communicate with that, but didnt work. More then likely error on my part, and not making the code right Torque wise. I tried using different ways of structure code writing from different tutorials both on this forum and other PHP tutorial sites, and non of those worked also.


Robert I can try to do it on my system I just have to reset up a server on my computer again as I did previously. Theres one problem that might happen that comes to mind is getting the master server to work right with this if I do it this way since its all on one machine. Maybe I can use two diff DNS to do this.. I know one DNS worked fine with some tweaks to my system, and router and package handling routines.

I just figured before to switch from my computer server back to the web side cuz I was trying to get a web registration database going where I could expand on to separate web data, and have that same PHP script write selected user information to a second database which would be used by T3D giving more security to log in info for both game and web. This way the IP to the web server is not in T3D code. But I guess If I can get T3d to communicate with a database on My computer, then I would know it was just the Free web hosting which it sounds like that was the issue. If thats the case then I can continue on past this hump.

I will take a look into the JSON library.

The PHP script I used to write to the database for web registration pretty much did the work in reverse. As far as getting T3D to do communicate with PHP, not sure how to go about this since T3d is written in Torque code and C++. Im not too experience if any at all in trying to get different types of code to communicate with each other other then what Ive done so far in the PHP, and HTML. Most of My experience has been in solid C script or C++ individually. So this is new ground for me.

Ill also make another post today below with the PHP script as asked for. I have to dig in my muck of files to find it, and figure out which one it was I used since the website deleted all my info one day, and closed my account.

Just want to say thanks for all feedback. This kinda clears up in my mind that it was the free website hosting that was the issue, and not anything else.

#7
09/16/2013 (11:50 am)
Quote:This kinda clears up in my mind that it was the free website hosting that was the issue, and not anything else.
Unless you are talking to a local (on the same machine or within the same network) database it will be a big security issue to talk to a database directly. The client should not be talking to your database. The server is fine, but not the client.

You will find most web hosts paid or not make you go through extra hoops to talk to a database directly. This is because it is a security risk. Better to use PHP with some form of authentication to keep the database safe. Listen to Robert very closely. He is becoming our security expert here. He knows what he is talking about.

So this really is not about your web host. It is about your design.

To keep it simple:
- Server running on same host as database direct access okay (or in same protected network).
- Client should never connect to database. Have it go through server or a tech like php.
- For billing find a 3rd party service that is well known and provides secure transactions.

Edit:
If you are running Windows (I assume you are) look into a WAMP install. It will give you Apache, MySQL, and PHP in a server on your machine. Only allow server side code to communicate to the database of this setup. Have the client side talk to the server side using client to server commands. Or have the client talk to the PHP. This will give you a good setup for testing.
#8
09/16/2013 (12:27 pm)
Quote:Would be nice to have a solid work around to the HTTP Object.

Did you look into using the TCPObject? I've used that for connections before and it works wonderfully.
#9
09/16/2013 (1:51 pm)
@Jeff: I use the TCP objects for that as well, but a word of caution for the TCPObject. It's got a very nasty tendency to crash when dealing with larger data in the transmission.

@Demo: Good points there. You should only be using the PHP side to access the database, the client can communicate with your PHP code, but in the end, only the PHP will handle the SQL work.

For any information that is sent through the network line to the server, I highly recommend you encrypt it before sending it, that way you can avoid people hacking into your stream.

Also, as Demo has mentioned, you'll want to grab a third party service for anything payment related (IE: PayPal, E-Commerce), unless you're some god of security who has a super server that can handle like RSA-16384 on every transmission, you're going to want to have someone who can do that.. do it for you.

For the most part though, for basic things like kills/deaths per game a simple method like AES, or DES will work nicely. For things like news text or things that have no impact on gameplay, you can send that down as plaintext.
#10
09/16/2013 (9:21 pm)
I originally started using my computer as a web server for the masterserver with Windows Ultimate, Apache, and Wamp. Then after reading up on Roberts tutorials I switched over to a webserver which was a free host. I eventually got a working php script that would save/write/retrieve to that web database server with web form/mail to registration information. But I couldnt get T3D to work with that PHP code. I tried both Http Object, and TCP.

Note: The PHP code I used pretty much functions on its own, and communicates to the database. In design T3D wasnt communicating with the PHP for some reason, or vice versa. And I agree design is an issue. but Im not sure if it was host side, My PHP, or T3D. But then Robert stated it was the Free host, So Im going to try again using my computer as the host.

Right now Im not even thinking about making money or letting people play. Its just me, and only me while I learn. So Im not too concerned bout security atm. Im trying to get T3D to communicate with a database server, so I know it works, and I can expand and focus more on game design, world building. A simple handshake with any located database server weather its on a private host or my own system. Retrieve username, password, on client, and log into the game server world.

Is there a simple trouble shooting code example that works with currenr MIT T3D, that I can use to insert in T3D that would shake hands with database, and say Hello, pull out database stored (USER), and put out in text in the console "Hello connection made how are you (USER)"? If T3D wasnt able to make a handshake to return (If Statement) text error, unable to connect to database. But, this needs to work with a PHP script.

This would help in determining where an issue might lie, and keep it simple. Im pretty sure If I can get a basic handshake error, or connection, I can manage to figure out, and work out the rest, and add onto it. Im just sitting in the Dark here so to speak with a lack of knowledge in knowing where to pinpoint the problem.

As far as the PHP code. I used this one off github

https://github.com/simfatic/RegistrationForm