CodeBlanks Logo Icon CodeBlanks

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.

Practice Initialize authoritative server architecture

Define a Start method. Inside, print the text "Sunucu yetkili mimari aktif" using Debug.Log.

Starter code

Player.cs
using UnityEngine;

public class NetworkManagerSimple : MonoBehaviour
{
    // Start icinde sunucu yetkisi bildirimini yazdir
}

Sample solution

Player.cs
using UnityEngine;

public class NetworkManagerSimple : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Sunucu yetkili mimari aktif");
    }
}

Expected output

Sunucu yetkili mimari aktif

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 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 Correct answer
  • On the graphics card (GPU) of the player's local client
  • On a randomly chosen other player's computer

Explanation: The authoritative server centrally validates all game states, preventing clients from falsifying network data.

2 Server authority check

Question
if (____) { ProcessMovement(); }
Answer
if (isServer) { ProcessMovement(); }

Explanation: In authoritative server architecture, critical game logic is executed solely on the server using an 'isServer' check.

3 Multiplayer architecture concepts

Term Meaning
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

All lessons in Advanced