views:

178

answers:

4

I would like to design a PvP game uses flash in client and java socket server, but I do need server validates trajectory and if bullets hit target from cheating.

Is there any tutorial or paper provides how to do this ?

+4  A: 

To do it you need to have a server-side logic.

Mainly you will use clients just to show gamestates that are sent by server (if you want you can also let your clients show whatever they think is right until a new gamestate is received and synch to it) and to send to the servers just actions that are done (clicks or key presses) while your server should take care of everything else..

clients should be mainly frontends for the world representation..

Jack
@Jack: +1 but see my comment to M28's answer. Server-side logic doesn't mean you're sending the whole game state: it depends on the game. Games which seems 'close' to the what the OP is describing, like Warcraft III or Starcraft 2 (anywhere from 2 to 8 players, so *not* massively mutliplayer, where hundreds of units with lots of properties are part of the game state) still only send the user's mouse/keyboard (timed) inputs (the input and the time at which it happened). Think of the server as a user-input-validation relay.
Webinator
Actually these games are P2P.. not server based
Jack
By the way it depends massively on the game: for fps you usually just send back deltas from server to clients, while clients send just inputs. For RTS it's really more complex, that's why using a decentralized approach usually works better..
Jack
Thank you all,for me what diffcult is that should I implement physical engine at server side ?I don't know how instances at WOW works? but all the units moving, hit-testing, trajectory logic handled by server seems impossible?Now my logic like this :Tank move(c)->validated(s)->Tank fire(c)->validated(s)->when will bullet hit target ?(I don't know which side should judge this??) ->hit-test validated by server->finished.
Konami.Koumura
it shouldn't be "tank moves" but __player is pressing forward button__ -> __server receives this info and moves tank accordingly__.. or __player presses fire__ -> __server shoots a projectile__ -> __server warns clients to show a projectile shooted from that tank__ later when projectile on gameworld (so on server) reaches something it will modify game state (like health of target) and when new game states reaches clients they will have information implicitly about where it arrives..
Jack
Thanks Jack, so I should let projectile physical exercises run at server side or running at client side and just validates by server?If I have 3 game rooms and each room has 100 projectiles working, Server has to handle all of their behaviors?
Konami.Koumura
@Jack: When the player shoot, he already know there will be a shot, just start the animation and fix it if the server says that you did it wrong.
M28
If the server is nothing more than an user-input-validation relay, then how can the game state be synchronized when a client first connects? seems like the server would need to ask a client to replicate it for the new guy.
Nathan
+2  A: 

Since you asked for patterns, I am assuming you understand the kind of logic you want to write on server side, but not sure about how to organize your code. You should look at strategy pattern (http://en.wikipedia.org/wiki/Strategy_pattern) once. Since in this problem based on various locations on the screen, you need to change the way server validates the data, strategy pattern is a good fit for the problem.

Fazal
Thank you, strategy design pattern is fitting my server-client relationship.
Konami.Koumura
+2  A: 

The general idea for a uncheatable multiplayer game is:

You should only send the keys the user is pressing, the server stores it and after some intervals, it processes the informations and send a snapshot of the current position of all objects in the game.

Maybe if you don't want to waste too much network traffic:

You could save everything's position for 2 seconds, record the last user input (with the input, he may also send his last snapshot id), then send only what differs from the position now and what the user have.

M28
@M28: +1 but you're not sending a snapshot of the current world state from the server, the server acts just as a (validating) relay for user inputs actually. The server reproduce the entire game state and can trivially detect a cheating client going "out of synch". Sending the whole game state would be way too wasteful. Thing "Warcraft III" or "Starcraft 2": you can have hundreds of units with properties in the game state, these are definitely not sent down the wire. You only send each player's input and the server (Battle.net) act as a (validating) input relay.
Webinator
+1  A: 

@Jack: +1, and you should not actually do physical exercises at server,server just check start point, end point, range and time ect... if they are reasonable!

Ryan