r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
Protocol.hpp File Reference

This file contains the network protocol. More...

#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <vector>
+ Include dependency graph for Protocol.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rnp::EventRecord
 Event record for ENTITY_EVENT packets (TLV format) More...
 
struct  rnp::PacketHeader
 Packet header according to RNP specification (Big Endian) Total size: 16 bytes. More...
 
struct  rnp::PacketConnect
 CONNECT packet payload. More...
 
struct  rnp::PacketConnectAccept
 CONNECT_ACCEPT packet payload. More...
 
struct  rnp::PacketDisconnect
 DISCONNECT packet payload. More...
 
struct  rnp::EntityState
 Entity state for WORLD_STATE packet. More...
 
struct  rnp::PacketWorldState
 WORLD_STATE packet payload. More...
 
struct  rnp::PacketPingPong
 PING/PONG packet payload. More...
 
struct  rnp::PacketAck
 ACK packet payload. More...
 
struct  rnp::PacketError
 ERROR packet payload. More...
 
struct  rnp::FragmentHeader
 Fragmentation header (when FRAG flag is set) More...
 

Namespaces

namespace  rnp
 

Enumerations

enum class  rnp::PacketType : std::uint8_t {
  rnp::CONNECT = 0x01 , rnp::DISCONNECT = 0x02 , rnp::WORLD_STATE = 0x03 , rnp::PING = 0x04 ,
  rnp::PONG = 0x05 , rnp::PACKET_ERROR = 0x06 , rnp::ACK = 0x07 , rnp::ENTITY_EVENT = 0x08 ,
  rnp::CONNECT_ACCEPT = 0x09 , rnp::PLAYER_INPUT = 0x03
}
 Packet types according to RNP specification. More...
 
enum class  rnp::PacketFlags : std::uint16_t {
  rnp::NONE = 0x0000 , rnp::ACK_REQ = 0x0001 , rnp::RELIABLE = 0x0002 , rnp::FRAG = 0x0004 ,
  rnp::COMPRESSED = 0x0008
}
 Packet flags for reliability and fragmentation. More...
 
enum class  rnp::DisconnectReason : std::uint16_t {
  rnp::UNSPECIFIED = 0 , rnp::CLIENT_REQUEST = 1 , rnp::TIMEOUT = 2 , rnp::PROTOCOL_ERROR = 3 ,
  rnp::SERVER_SHUTDOWN = 4 , rnp::SERVER_FULL = 5 , rnp::BANNED = 6
}
 Disconnect reason codes. More...
 
enum class  rnp::ErrorCode : std::uint16_t { rnp::INVALID_PAYLOAD = 1 , rnp::UNAUTHORIZED_SESSION = 2 , rnp::RATE_LIMITED = 3 , rnp::INTERNAL_ERROR = 4 }
 Error codes. More...
 
enum class  rnp::EventType : std::uint8_t {
  rnp::SPAWN = 0x01 , rnp::DESPAWN = 0x02 , rnp::DAMAGE = 0x03 , rnp::SCORE = 0x04 ,
  rnp::POWERUP = 0x05 , rnp::INPUT = 0x06 , rnp::CUSTOM = 0xFF
}
 Event types for ENTITY_EVENT packets. More...
 
enum class  rnp::EntityType : std::uint16_t {
  rnp::PLAYER = 0x01 , rnp::ENEMY = 0x02 , rnp::PROJECTILE = 0x03 , rnp::POWERUP = 0x04 ,
  rnp::OBSTACLE = 0x05
}
 Entity types for world state. More...
 

Functions

std::vector< std::uint8_t > rnp::serializeEvents (const std::vector< EventRecord > &events)
 Serialize events in ENTITY_EVENT format (TLV with entity_id) Format per event: type(1) | entity_id(4, BE) | data_len(1) | data(data_len)
 
std::vector< EventRecordrnp::deserializeEvents (const std::uint8_t *payload, const std::size_t length)
 Deserialize ENTITY_EVENT payload into event records Format per event: type(1) | entity_id(4, BE) | data_len(1) | data(data_len)
 
std::vector< uint8_t > rnp::serializeHeader (const PacketHeader &header)
 Serialize packet header (Big Endian as per RNP spec)
 
std::vector< uint8_t > rnp::serialize (const PacketHeader &header, const uint8_t *payload=nullptr)
 Serialize packet with header and optional payload (Big Endian)
 
PacketHeader rnp::deserializeHeader (const uint8_t *data, const std::size_t size)
 Deserialize packet header (Big Endian)
 

Variables

constexpr std::uint8_t rnp::PROTOCOL_VERSION = 1
 
constexpr std::size_t rnp::MAX_PAYLOAD = 512
 

Detailed Description

This file contains the network protocol.

Definition in file Protocol.hpp.