Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm writing an HTML5 game that takes place in a single screen and does not have any data that would need to be saved (except for a score). I am writing all of my canvas logic on the front end. because it seemed like the easiest way to program interactions. However Ive been reading on r/gamedev that the best way to organize games is to sent client input to the server and have the server render the results on the client. I have a couple questions about this:

1.) If my game takes place on a single screen (meaning no changes in background, enemies, etc. Think Space Invaders), is it worth putting my game logic on the server?

2.)If I do put my logic on the server, how can i facilitate clean communication with the client? Web sockets? or plain HTTP? Using a WebSocket seems straightforward for this kind of task, but they are not supported by all browsers. On the flip side I'm kind of hazy on how HTTP could be used to send and receive data from the client.

Any advice would be great.

share|improve this question
1  
Usually when people are talking about client/server they are talking about multiplayer games. I don't generally think of space invaders as multiplayer, however. Is this just a single player game? –  Cameron Fredman Feb 26 '13 at 18:55
add comment

3 Answers 3

up vote 6 down vote accepted

Generally, this advice is given not because of abstraction or code cleanliness but rather because gameplay logic that is sensitive must be simulated by an authorative server to prevent cheating and hacking. Long story short: If you don't particularly care about players hacking their score - don't bother.

If your game is multiplayer, then you should looking into making the client nothing but a "dumb terminal" and display for the game. Generally, this involves the client only sending inputs and actions to the server, and the server sends the results back to the entities that may be interested in his result. You can look at this article for getting started with socket.io.

It's a broad topic and tough to cover in this answer but the gist of the idea is that. For example, instead of just moving and telling every other player "I got 100 points"... you instead send "I shot", and the server simulates your shot. Then, when the server sees someone was "shot" then it sends a result back to all other players who may be interested that this object was shot, so something can explode, the killer can get points etc.

share|improve this answer
    
So basically, the client should be treated as a dumb terminal that accepts server input? Any advice on how to accomplish this using http requests? –  codeninja Feb 26 '13 at 18:32
    
This is only the case if your game is going to be multiplayer - is your game singleplayer? If not, then just leave it as is. If it's supposed to be multiplayer, there's a lot of reading you're going to want to do. –  Vaughan Hilts Feb 26 '13 at 18:38
    
if you could forward me to some resources it would be awesome =D –  codeninja Feb 26 '13 at 18:47
    
Added more information. –  Vaughan Hilts Feb 26 '13 at 19:02
1  
You could maybe use ajax, but straight HTTP requests would not work. –  aglassman Feb 26 '13 at 22:10
show 2 more comments

it depends on what game you're trying to make and do you care about cheating in your game.

if you don't care about cheating, it will be much more easier to just do everything on client and simply relay the actions/results via the server to other clients.

if you do care about anti-cheating, and depending on game type, you might want to make some predictions on client side so that your game dont suffer from round-tip delay. in short, your client need to have the logic and also send the actions to the server to be simulated, but your client will only trust the results from the server.

share|improve this answer
add comment

BrowswerQuest is a great example of a secure way to protect your HTML5 data from being hacked. It is a massively multiplayer game that has a server built with Node.js and a library called socket.io which handles the websockets. And like they said the client is like a dummy client. The server is the authority.

share|improve this answer
1  
It might be a great example, but this doesn't really answer the question. –  Anko Apr 27 at 18:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.