Network gaming for the first time

Hello

I’m writing a course work and I’ve just finished on physics. Now I want to implement networking on my project, but I have no experience on it.



Game can have maximum 8 players. At the beginning server starts his game, then clients join him (like quake 3). On each onAnalog() method call player responds with “command”. This “command” executes on player side, players sends it to server, server executes and sends it to other players and players executes it ( [player, execute] → [server, execute] → [other players, execute] ). Server every dt time sends to players information about map and players(players coordinates, terrain change and etc).



I think this should work in the middle of the game, but I don’t know what to do when player joins the game. I thought that it will be enough to send information about map, but I’m not confident about it, because at the moment of sending players maybe executing some “command”.



Could you give me some advices and hints, please.

Typically at the start of a game, you send some kind of start message, indicating all the information the player needs to get started. When that’s over with, you just start your normal routine of messages. The client should not be able to execute a command when it is not completely joined yet, or when the start message has not been received yet. You could say the client is in a pending state.



On a side note, please note that executing command client side could be prone to hacking. The best thing to do is make the client as ‘dumb’ as possible, by checking everything on the server for sanity. Say if you have a player that suddenly moved 1000 feet instead of a few feet, you’d correct that to just a few feet (you may even choose to kick him out). Same goes for other events. Let’s say in a RPG you’re at a trader and you want to sell something. You don’t let the client do the money calculating, you just have the client send the items it wants to sell, where the server will calculate how much money you’ll get for it. You have the server in control at all times, that is not the case with clients :slight_smile:

Thank you for reply.

You mean something like “Press fire to start.”?



One more question, is it good to send command by TCP every time player’s onAnalog(…) method is called (around every 10 milliseconds)? I’m afraid for server that will receive a command and will have to send it to other players. What should I do if it is not?

Nah I meant ‘Let the client start automatically when it has received the start message’.



As for your second question; it’s better to use UDP in those situations (less overhead). If you use SpiderMonkey, you can do message.setReliable(false) to send it over UDP.

As for your second question; it’s better to use UDP in those situations (less overhead). If you use SpiderMonkey, you can do message.setReliable(false) to send it over UDP.

If i have 8 player in local network I should do the same thing?

Well if that’s the only case in which you’d be using it, it doesn’t really matter anymore. Might as well use TCP then (overhead is no problem since there’s a fast reliable connection).

:smiley:

Thank you. You’ve build my confidence. :wink: