a few questions about server design

Started by
13 comments, last by hplus0603 11 years, 7 months ago
Hi,
I'm creating action 2d game using UDP and I've heard that it's best to implement whole gameplay on the server and client should send as low data as possible (in order to prevent user from cheating, hacking etc). Therefore I've got some questions, which hopefully someone could answer:
1. My game is going to have a lobby and players will be able to create a match, wait for others to join and start it. In such case what should be done on the server and client separately to ensure best performance for both server and clients? There is pixel perfect collision in my game (a bit laborious becouse every pixel is being checked on 2 colliding sprites). I thought that checking if collision occurs will be done on the client but collision execution on the server. So client will be sending players' indexs which collide, server will execute the collision and send the result back to client. Is that a good approach or whole collision operations should be done on client? (I would like to disable any easy to do hacks in my game but keep good performance and design).
2. Where camera moving should be handled? I guess that on the client becouse it's individual for each client, right?

I would be very grateful for answers!
Advertisement
Also if I have a lobby and I have a chat there as well so how to ensure that all text messages sent by users arrive to server and vice versa? How is it done in other games created on top of UDP? I guess that loosing text messages shouldn't be allowed even in UDP game?
Games on top of UDP usually classify messages into "reliable" and "unreliable." "Reliable" messages, when sent, are put into a queue of some sort, and only removed from that queue when the remote end acknowledges the packet that they were put into. If an acknowledge doesn't come in quickly enough, the messages are re-transmitted, until acknowledge is received. This also needs some form of de-duplication on the receiving end (typically implemented using a serial number for reliable messages.)
enum Bool { True, False, FileNotFound };
thanks for answer. I'm wondering also if I should have a separate server for lobby and separate servers for matches? How is it actually done? 1 server per one match? or 1 server handling all matches? or maybe one player should be the server and host game to others in given match, but is that secure enough? Though I have no idea how to implement that. I would be very grateful for any clues!
All the variants you're talking about have been impemented, and work.

The problem with having players hosting matches is that you have to implement NAT punch-through, and only allow players with working punch-through (or port forwarding) to host matches. The benefit is that you don't need to run the game servers yourself.

The benefit of having lobby and game all in one is that the hand-off and management of "who's online" is simple. The draw-back is that there is an upper limit to the number of games you can run at one time, because the server machine may run out of capacity.

The "best practice" for large-scale systems is to run multiple lobbying processes, and also run multiple game processes (perhaps one game per process, if processes are cheap.) When a player logs in, you'd try to assign him/her to a lobby server where other players on the friend list already are. Or you'd assign be geographic location, or something. The point being that you want players to be on lobby servers where they will find friends to play with, and you also want to scale the number of players beyond what a single server can do for lobbying. Xbox Live actually dynamically splits the lobbying -- for most games, it'll be on a single process, but when enough players are online (for the really big games,) it will split; I believe it will split geographically.
enum Bool { True, False, FileNotFound };
thanks a lot for answer!
I think I like the idea about players hosting matches the most as I probably won't have enough budget to buy servers myself. 1 thing is concerning me still. I have very little idea about hacking online games but if one player is being a server, isn't he allowed to easily hack? Both his client and server would be ran on 1 machine so he might be able to corrupt data on the server, or? If you knew any good tutorials I would be really very grateful for your help and I appreciate your time you've spent here already!

PS: How is this method exacly called that one player hosts game for others? It's not peer to peer I guess and not simply client/server?
As soon as you give a user full administrative rights over the game (being the server), it will get hacked. There's just no two ways around it. Diablo III is went with proprietary dedicated servers for a good reason.

Everything is better with Metal.


PS: How is this method exacly called that one player hosts game for others? It's not peer to peer I guess and not simply client/server?


It's just client / server. If you want secure games, you will have to host on machines you trust. Either because you own them, or you can validate and authenticate the server content. Usually 'pure' game servers are called dedicated servers. There is no client-side, no rendering or sound, and the game is controlled via a console (entering commands, either locally, or by a games administrator remotely, rcon_password and all that). It's a lot lighter on resources, and you can run several servers on one machine, your bandwidth becoming your bottleneck.

Internet security is a big deal, especially when money is involved (auction houses). Then you run into legal matters. Simply put, a client / server would be the most secure you can hope for, and from where you can build on, and if someone wants to run a moded server and you do not run an authentication service, then there is nothing you can do, apart from accepting it.

If you run a lobby service, then you can run an authentication service. You will need to authenticate users, client and server content, client and server binaries, transactions, communications, ect... SteamWorks, XBox Live or Games For Windows Live are examples of such systems, and as you can tell, it's not an easy thing to do.

Everything is better with Metal.

if one player is being a server, isn't he allowed to easily hack?[/quote]

Yes.
Many, many games have been quite successful with this model, though. Until just a few years ago, that was the only way that network-hosted games were written.
You still need a server for matching up the hosters with the players, but that's an easier thing to operate.

If you think your game will be popular, and there will be incentive to cheat, then you may need to change to run the servers on your own. The good news, though, is that, because players go to your matchmaking service to find servers, you can make that change later, without breaking anything that already exists.

So, I would recommend this sequence of implementation:
1) Build the game, with manual hosting, and the player having to enter a target address for the game server.
2) Make the game super fun!
3) Build a matchmaker, where hosted games register, and client players can find and join games.
4) Make this matchmaker, and the NAT punch-through, robust!
5) Now if the game is fun and robust, you may start seeing cheaters as a problem. Move servers into your own hosting, and advertise them in the matchmaking as "secure" or "premium" or whatever.

If you complete 1) and 2), you're better off than 99% of all other game projects on the planet :-)
enum Bool { True, False, FileNotFound };
papalazaru,
thanks for answer! I would like to use some authetification system but I need to know how hacks work. How someone can change my server's content if server is ran on his own machine? Does he somehow stick another program to my server? Or he's just sending false values to / from server via for example windows command line?

edit:
hplus0603,
thanks a lot for your tips! I feel that network is the hardest challenge that I have faced so far. Though I think that most of the game engine is already done and if I managed to succeed with network coding, the game could be quite fun :). NAT punch-through is a thing that scares me the most... It seems there are almost no any example codes of doing that ;/

This topic is closed to new replies.

Advertisement