I'd like to get into online games programming. I thought that as a start i'd be a good idea to implement an online database that would store the progress and score for a game i have made, i'll probably want to implement an account system too.
My issue is, i can't see to be able to ask google the right question. I don't know where to start. I've touched some on SQL and PHP, HTML and XSL, but, to me they're just languages, i can't see the big picture, how do these things connect to form a working service? I'm not looking for a solution, i just don't know what should i learn.
I'm not looking for knowledge on sockets, i'm familiar with network programming, i just don't understand the "modern" process of handling databases. I'd be very happy if somebody could lay out the structure of a database, how you put it out on the web, how you access the information and change it (not in a direct solution, just "this is done by programming a filter in SQL"), what languages are used for it, etc.
Answer
The database is the backend, your game is the client. Since you can't (well, technically you can but you really shouldn't) connect to the DB directly, you'll have to write some kind of middleware for that.
The middleware usually runs as a web-service or deamon on a server and exposes an interface for you to access/store game data. This stuff can be implemented in a lot of different languages.. basically any language that you can run on a server and access a database with.
For things like highscores, achievements etc. you can write a simple PHP (or Ruby, Java,..) script that you can access via HTTP. A common architecture for web APIs like this is REST. If you would implement a highscore system as RESTful service, you might have an URL like this:
http://my.server.com/highscores
Sending a GET
request to that URL would fetch the scores from the DB and return them (you could send them as XML, JSON or similar).
To add a new score-entry, you maybe have an URL like:
http://my.server.com/highscores/add
And you would send a new Highscore to that address using a HTTP POST
request. Then you read out the POST
data and insert it into the database.
Of course you don't have to conform to any architecture (such as REST), but I'd say it's good practice.
Here are some things you should be aware of when you do something like this for the first time:
Don't trust the client. If your game can send a highscore, anybody else can do so also... this question touches on that topic.
Always validate and sanitize incoming data (remember, don't trust the client). Being sloppy with these things will make your service susceptible to SQL injection attacks.
No comments:
Post a Comment