FIT CTU
Adam Vesecký
vesecky.adam@gmail.com
Lecture 11
Multiplayer




Local multiplayer games

Networked multiplayer games

Local area network games

Online games

MMO

Torque Network Library (opentnl)
ReplicaNet
RakNet
NetStalker
Methods
Topologies
Single master
Partial authority
Full replication
Doom (1993)
Age of Empires (1997)
Command
NetChannel header


Data categories
TPC header
UDP header
Ports
TCP
UDP
Using TCP is the worst possible mistake you can make when developing a multiplayer game.Glenn Fielder, 2008
Issues
Connection
Reliability
Flow control
Stream
Snapshot
Command
Action
Procedure Call
Connection messages
Beacon

Server-Client messages
Client-server messages
Example with no optimization
struct Mage {
int health;
int mana;
}
void Serialize(const Mage* mage) {
SendMessage(reinterpret_cast<const char*>(mage), sizeof(Mage));
}
void Deserialize(const Mage* output) {
ReceiveMessage(reinterpret_cast<char*>(output), sizeof(Mage));
}
Health = 10, Mana = 14; Little Endian

struct Mage : public Streamable {
vector<Item*> items;
int health;
int mana;
void SaveToStream(NetWriter* writer) {
writer->WriteDWord(health);
writer->WriteDWord(mana);
writer->WriteDWord(items.size());
for(auto item : items) item->SaveToStream(writer);
}
void LoadFromStream(NetReader* reader) {
health = reader->ReadDWord();
mana = reader->ReadDWord();
int itemsCount = reader->ReadDWord();
for(int i=0; i<itemsCount; i++) {
items.push_back(new Item(reader));
}
}
}

Compression of bits
Entropy Encoding
Compression of attributes
Compression of the payload
Delta messages
switch(actionType) {
case OBJECT_CREATED:
int objectType = reader->ReadDWord();
auto factory = creatorManager->FindObjectFactory(objectType);
auto newInstance = factory->CreateInstance(reader); // parse parameters
objects.push_back(newInstance);
break;
case OBJECT_DELETED:
int objectId = reader->ReadDWord();
sceneManager->removeObjectById(objectId);
...
}
Latency
Suitable latencies
Non-network latency
Network latency
Prediction
Server simulation
Client misprediction
Dealing with correction
Source engine's solution

Wrong

Correct

Time dilation
Deterministic prediction
Dead reckoning
Server-side rewind


Swifty Invasion in WoW
Static zones
Server partitioning
Instancing

3 data types



Classic threats
Input validation
Software cheat detection

A hero needs not speak. When he is gone, the world will speak for him.Halo 3