Skip to content

Network Protocol Guide

Raphaël Chanliongco edited this page Dec 15, 2025 · 1 revision

This document defines the binary communication protocol used between the R-Type Client and Server. It is designed to be lightweight, low-latency, and suitable for real-time UDP communication.

1. Protocol Overview

  • Transport Layer: UDP (User Datagram Protocol).
  • Encoding: Strict Binary format (Little-Endian byte order).
  • Architecture: Client-Server (Authoritative Server).
  • Port: Default is 4242.

Note: Unlike text-based protocols (HTTP/JSON), this protocol sends raw bytes directly from memory structures to minimize bandwidth usage and parsing overhead.


2. Packet Structure

Every packet sent over the network shares a common Header, followed by a variable-length Body.

2.1. Header Layout (4 Bytes)

Offset Field Name Type Description
0x00 OpCode uint16_t Identifies the type of command (see Section 3).
0x02 Length uint16_t The size (in bytes) of the following Payload.

2.2. Visual Representation

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             OpCode            |             Length            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                       Variable Payload...                     |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

3. Command List (OpCodes)

The protocol distinguishes between commands sent by the Client (C->S) and updates sent by the Server (S->C).

OpCode Name Direction Payload Size Description
0x01 C_Login C -> S 0 bytes Request to join the game session.
0x02 S_LoginSuccess S -> C 4 bytes Acknowledge connection & assign Player ID.
0x03 C_Input C -> S 2 bytes Player movement/action inputs.
0x04 S_EntitySpawn S -> C 14 bytes Create a new entity (Player, Mob, Bullet).
0x05 S_EntityDestroy S -> C 4 bytes Remove an entity from the world.
0x06 S_EntityPosition S -> C 12 bytes Update position of a dynamic entity.
0x07 C_Shoot C -> S 0 bytes Player request to fire weapon.

4. Payload Specifications

This section details the byte layout for the body of each command type.

4.1. C_Input (0x03)

Sent by the client every tick to update input state.

Offset Type Name Description
0x00 int8_t DirX Horizontal axis (-1: Left, 1: Right, 0: None).
0x01 int8_t DirY Vertical axis (-1: Up, 1: Down, 0: None).

4.2. S_EntitySpawn (0x04)

Sent by the server when a new object enters the visual field.

Offset Type Name Description
0x00 uint32_t EntityID Unique Network ID.
0x04 uint8_t Type 0=Player, 1=Mob_Basic, 2=Bullet, 3=PowerUp.
0x05 float PosX Initial X Coordinate.
0x09 float PosY Initial Y Coordinate.
0x0D uint8_t Team 0=Ally, 1=Enemy (for collision logic).

4.3. S_EntityPosition (0x06)

High-frequency update to sync movements.

Offset Type Name Description
0x00 uint32_t EntityID Unique Network ID.
0x04 float X New X Coordinate.
0x08 float Y New Y Coordinate.

Authors

Epitech Paris

  • Raphaël Chanliongco
  • Hubert Touraine
  • Jean-Baptiste Boshra
  • Gabin Rudigoz
  • Ylan Cuvier
  • Swann Grandin


Epitech Logo