Game network library mmo
Ok, someone asked questions regarding to server side game play programming on Reddit.
- Best way to handle enemies on server?
- Transferring map data between client and server?
Fortunately, I have worked a lot about these issues so I can explain where we should start and finish doing them.
Best way to handle enemies on server?
13 years ago when I was developing an MMO tank battle game ‘Blitz 1941’, I was afraid of taking a lot of CPU time at server for calculating flying projectiles which curves then collide to terrain or combination of cubical objects. At that time, I developed it like this.
- Each client simulates a projectile then sends the movement message to server.
- The server receives it, stores the projectile data to itself, then multicast the movement message to nearby players.
It worked fine, but the development was not so easy and it was prone to be exploited as the gameplay was decided by clients.
So I added another feature:
- All clients simulate the projectile then send the movement message to server.
- The server picks up the most accurate
This worked fine too, but I thought it might cause needless overhead on server.
Years after when I was working for another game developing project, I checked how much time is consumed while a network message is sent to be received.
Finally, in my opinion, I would suggest you to HANDLE ENEMIES ON SERVER ANYWAY.
The reason is simple: Handling the network messages is also heavy.
Yes, we also use I/O Completion Port or epoll for massive multiplayer and fast running game server. We make it very quickly with many optimizations. But, we cannot optimize the OS kernel. Of course, there is a way of optimizing them too, but it is out of the topic here. If you want to check them out, look for articles about user level network stack development.
In short, it takes thousands or tens of thousands of CPU clock cycles for sending or receiving a network message inside OS kernel. During that time, you can sufficiently calculate one or many enemy objects at server.
It is just simple. Import enemy handling code to your server and run it. Then multicast the movement message or action message to nearby clients. 10~20 per second is enough, depending on what game you develop. Of course, your game server should load map data on server, too. In Blitz 1941, my game server loaded map data including Line of Sight data map, navigation path map, etc. Just simple do as the clients do, except multimedia data such as texture, sound, animation, skeleton and mesh.
Please note that doing so much work such as mesh collision check is costly at server. The server does not do rendering for each scene, but it must handle thousands of scenes in it. Most of the time is done on CPU. For collision detection and reaction, use sphere or cylinder if you can.
Transferring map data between client and server?
Unless you are developing Minecraft thing, you might need to transfer map data. It is easy to develop and saves your server management cost if you just copy the map data to the client folder and the server folder.
What if the map is updated? Just simple. Upload the patch and let the clients download them, and copy the map to your servers and just reload them. Some bloating people say to upload them to SQL database, but remember to keep in mind KISS: keep it simple, stupid.