
Originally Posted by
NessDan
I remember learning that TCP carries a sequence number to make sure packets are coming in order. I never really thought about that issue but I can see how that could be a massive issue - totally didn't cross my mind. And I'll keep in mind that the OS overrides the source IP. (Couldn't an application catch all out-going packets and change the data in them? I remember reading an article saying that some hackers use "hack proxies" that modify packets without the client being modified.)
Yes they can. If you sign them with a time-stamp it makes it a lot more difficult to do though. Also, one cannot use this method to identify themselves as another person for reasons already stated.
You won't need anything that complex for your game, though I suppose you could do something similar but in a smaller scale. Assuming you're going for a central server design, this is how I would do it:
I would have the server:
*I would have the client update the user position based off of what the server tells it and not what the client tells the server. So when you press the up key, change the Vy velocity to like 10m/s by sending a message to the server. Don't move the player on the client - just wait for a response from the server telling you & all the other players where you character has moved & move the player on the client according to the response. This will help you keep in sync with other clients.
*Instead of having players submit their exact location every time they move, have them submit their location and their velocity when they change velocity. To give an example:
Code:
(Initially player is traveling at 0m/s)
(Player then begins traveling 10ms East and 3 m/s North)
Send to server: set Vx 10m/s ; set Vy 3m/s location(location prior to applying velocity)
Client response to the message broadcasted via server: Change player 'x' location to initial location and apply velocity.
(Player stops after traveling for 10s.)
Send to server: set Vx 0m/s Vy 0m/s new location (Whatever the final location is)
Client response to the message broadcasted via server: Stop moving player - set final location accordingly.
*Resync player positions and other critical properties every couple of seconds\fractions of a second - play around with the resync frequency.
*Have players tell the server when they've shot a bullet - network the bullets similar to how you networked play movement(as described above.)
This will cause a little bit of jittering due to the constant resyncing and minor losses of accuracies so you may want to implement a method to "tween" the world objects\players to their new locations upon resyncing (so that such resyncing isn't noticeable) -
only do this step if you have to - you might be able to skip it.
NPCs are a bit more difficult only because, I assume you implemented simple following code and not path-finding code using nodes etc. This means your NPCs constantly have a changing velocity so they are constant traveling in the direction of the player. So I would recode your NPC logic so that it travels to a player via particular nodes - take a look at A* path finding (there is a game-dev article on it.) When you have NPCs traveling to nodes to other nodes to players its easier to network (as their velocities aren't constantly changing.)
I can't link you to any external resources(its against the rules) but gamedev forums can help you quite a lot. My networking design is based off of researching like you had + some of my own ideas. Anyways, good luck.
Sorry it too so long to respond, I'm working on something w\ someone else and I lost track of the article.
Also, this is a flash game so I _assume_ you're using sockets or FMS - if I were you I would use FMS (or something similar but free) if I could. Also, it looks like you are sending raw data back and forth from the server - use serialization its much neater.