Chapter 1. Network

Network layer is chunk layer over SSL over TCP or UDP. Chunk consists of ID (4 bytes), body size (4 bytes) and body itself. ID and body size are in network byte order of course. In such system any data incosistence will lead to failure, so we need to use some integrity control library. SSL is the best for that. SSL also solves problems of data compression, security and user identification. Chunk IDs are divided into sections. Each section contains 256 ID's. So the 0-th section covers from 0x00000000 to 0x000000ff, 0x00f3ab-th section covers from 0x00f3ab00 to 0x00f3abff and so on. 0-th section is traveling section. It never changes from version to version. All other sections are version specific. They are described in "idefs.h". There are sections for lua environment, scenes, cameras, viewports, 3d models, lights, input, etc. Actually there are separate IDs for client to server and server to client chunks.

But when something so universal like that is developed there comes another question: how to tune network to descrease latency? Quake3 is good example of game with well tuned network. There's special algorithm based on UDP with wise control of undelivered packets. Still there's a way to make network pretty universal. There must be 4 combinations of network protocols: SSL over TCP, SSL over UDP, TCP only, UDP only. It's important to notice that combinations without SSL can't guarantee data security (remember inbetween connections) and will only allow anonymous connections. The first 3 are automated and 4th one will be similar to protocol of Quake3. And packet rythm will be led by server, which itself will be tuned for specialized needs.