Game Development
Multiplayer architecture
Learn authoritative server and client-server architecture.
Multiplayer Architecture and Authoritative Server
The most crucial architectural decision in multiplayer games is authoritative networking. To prevent cheating and keep the game state synchronized, the Authoritative Server approach is standard practice.
// Clients only send inputs
// The server validates collisions, health, and broadcasts results
if (isServer) {
ApplyDamage(10);
}
In this model, clients only send raw inputs and keystrokes, while health points, hit validation, and scores are processed solely on the server.
Client-Server and the Netcode Layer
Netcode is the software layer responsible for transmitting data packets (TCP or UDP) over the network, compensating for packet loss, and synchronizing game objects.
// Netcode manages packet transmission between client and server
public void SendInputToServer(Vector2 moveInput) {
// Packet serialization and transmission
}
While Peer-to-Peer (P2P) links players directly to one another, the Client-Server model routes all communication through a central server.
Exercise Initialize authoritative server architecture
Define a Start method. Inside, print the text "Sunucu yetkili mimari aktif" using Debug.Log.
Show example solution
using UnityEngine;
public class NetworkManagerSimple : MonoBehaviour
{
void Start()
{
Debug.Log("Sunucu yetkili mimari aktif");
}
}
Test yourself
-
Where should game logic be executed in a multiplayer game to prevent players from cheating?
- Exclusively in the local hard drive cache
- On the Authoritative Server
- On the graphics card (GPU) of the player's local client
- On a randomly chosen other player's computer
Show answer
On the Authoritative Server — The authoritative server centrally validates all game states, preventing clients from falsifying network data.
-
Server authority check
if (____) { ProcessMovement(); }
Show answer
if (isServer) { ProcessMovement(); }
-
Multiplayer architecture concepts
- Authoritative Server
- Server deciding the game state
- Client
- Player side sending inputs and drawing
- Netcode
- Layer managing packets and sync
- Peer-to-Peer
- Serverless model with direct links
Next lesson: Photon Unity Networking