I’m trying to implement a login system into my game that allows user to create a username and password and will be able to track various stats. I know a bit about MySQL and I think that this would likely be the best route to take, but before I start learning about MySQL and user systems in-depth, I just wanted to know if it’s a viable option in Unity.
I only ask this because I’ve googled it and the only answers that I could find were years old and didn’t explain very clearly. So, any help is greatly appreciated!
Usually when you have an online server you don’t just place your sql database open to the public on the internet.
Primarily because this creates a giant point of failure. If someone cracks your sql database username and password (which probably will be stored in your game source code somewhere so it can log into it), that means they can dump your entire sql database if you have it configured to read (which it probably will).
Furthermore, it hard codes all the configuration of your server into the distributed game. If you need to move stuff about, change out the database, upgrade the system… EVERY client will need to be updated.
Usually, you create a web service of some sort. This web service will take care of communicate with the database and resolve all the logic on the server where it is secure.
The web service will have a couple public methods that take generic data into them. For instance in your case you might have a method like the following:
location: mydomain.net/myservice/Login
shape: string Login(string username, string password)
takes in a username and password, returns a message of success or failure. On failure the message will include reason for failure.
Now all the database stuff is done on the server behind this function call. If you swapped from MySQL to MS/SQL, or even if you swapped to a none SQL solution, or you moved the service/database, anything like that. As long as the domain name points to the correct server, the shape of the Login method doesn’t change. Every client continues to work.
Furthermore all the security is on your server. The client has ZERO of the server information. It doesn’t know the name of the database, the username/pw of the database, or where the database is located. The only information passed between client and server is specific to the client.
You can write the service in a number of languages independent of Unity. May it be PHP, ASP.Net, Microsoft WCF, node.js, whatever.
Your Mono code just consumes the web service and interacts with the functions you define.
Thanks for the very informative answer, that clears up a lot!
I would probably be most interested in trying to create that service with PHP (as I am a already a little familiar with it). I found a ton of tutorials via a quick Google search, but do you have any specific tutorials that you would recommend? Thanks!
Nope, no tutorials.
I haven’t written PHP in several years. I hate the language. And I’ve never really used it in conjunction with Unity.
I also don’t really use tutorials… I’ve just written so many web services in node.js, Error: ASP.net | The ASP.NET Site, WCF, that it’s just kind of second nature to me now a days. With asp.net and wcf being at the top as I’ve mostly worked in .Net/C# for my jobs. And those are in .Net/C#.
Here’s a really simple article about Mono/.Net webserives:
http://www.mono-project.com/archived/writing_a_webservice/
At the end is a link to consuming a web service (the client side):
http://www.mono-project.com/archived/web_services/
Thanks for the links, I’ll go through them.