Offers a capability for multiple players to act within the same world at the same time.
A complex feature that has a significant impact on the game architecture, touching almost every fundamental structure.





Local multiplayer games

Networked multiplayer games

Local area network games

Online multiplayer games

Online-only games

MMO


Multiplayer in 1977

Multiplayer now
Methods
Topologies

Doom (1993)
Age of Empires (1997)
Command
NetChannel header
Using TCP is the worst possible mistake you can make when developing a multiplayer game.Glenn Fielder, 2008
Issues
Stream
Snapshot
Event
Action
Procedure Call
Connection messages
Beacon
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
Source engine's approach

Wrong

Correct

Time dilation
Deterministic prediction
Dead reckoning
Server-side rewind

Classic threats
Input validation
Software cheat detection
Torque Network Library (opentnl)
ReplicaNet
RakNet
NetStalker
Netcode


Now you see me, now you're dead.Duke Nukem