r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
rnp Namespace Reference

Classes

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

Enumerations

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

Functions

std::vector< std::uint8_t > 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< EventRecorddeserializeEvents (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 > serializeHeader (const PacketHeader &header)
 Serialize packet header (Big Endian as per RNP spec)
 
std::vector< uint8_t > serialize (const PacketHeader &header, const uint8_t *payload=nullptr)
 Serialize packet with header and optional payload (Big Endian)
 
PacketHeader deserializeHeader (const uint8_t *data, const std::size_t size)
 Deserialize packet header (Big Endian)
 

Variables

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

Enumeration Type Documentation

◆ DisconnectReason

enum class rnp::DisconnectReason : std::uint16_t
strong

Disconnect reason codes.

Enumerator
UNSPECIFIED 
CLIENT_REQUEST 
TIMEOUT 
PROTOCOL_ERROR 
SERVER_SHUTDOWN 
SERVER_FULL 
BANNED 

Definition at line 52 of file Protocol.hpp.

◆ EntityType

enum class rnp::EntityType : std::uint16_t
strong

Entity types for world state.

Enumerator
PLAYER 
ENEMY 
PROJECTILE 
POWERUP 
OBSTACLE 

Definition at line 91 of file Protocol.hpp.

◆ ErrorCode

enum class rnp::ErrorCode : std::uint16_t
strong

Error codes.

Enumerator
INVALID_PAYLOAD 
UNAUTHORIZED_SESSION 
RATE_LIMITED 
INTERNAL_ERROR 

Definition at line 66 of file Protocol.hpp.

◆ EventType

enum class rnp::EventType : std::uint8_t
strong

Event types for ENTITY_EVENT packets.

Enumerator
SPAWN 
DESPAWN 
DAMAGE 
SCORE 
POWERUP 
INPUT 
CUSTOM 

Definition at line 77 of file Protocol.hpp.

◆ PacketFlags

enum class rnp::PacketFlags : std::uint16_t
strong

Packet flags for reliability and fragmentation.

Enumerator
NONE 
ACK_REQ 
RELIABLE 
FRAG 
COMPRESSED 

Definition at line 40 of file Protocol.hpp.

◆ PacketType

enum class rnp::PacketType : std::uint8_t
strong

Packet types according to RNP specification.

Enumerator
CONNECT 
DISCONNECT 
WORLD_STATE 
PING 
PONG 
PACKET_ERROR 
ACK 
ENTITY_EVENT 
CONNECT_ACCEPT 
PLAYER_INPUT 

Definition at line 23 of file Protocol.hpp.

Function Documentation

◆ deserializeEvents()

std::vector< EventRecord > rnp::deserializeEvents ( const std::uint8_t * payload,
const std::size_t length )
inline

Deserialize ENTITY_EVENT payload into event records Format per event: type(1) | entity_id(4, BE) | data_len(1) | data(data_len)

Definition at line 253 of file Protocol.hpp.

References rnp::EventRecord::data.

Referenced by eng::AsioClient::processEntityEvent(), and srv::AsioServer::processPacket().

+ Here is the caller graph for this function:

◆ deserializeHeader()

PacketHeader rnp::deserializeHeader ( const uint8_t * data,
const std::size_t size )
inline

Deserialize packet header (Big Endian)

Definition at line 345 of file Protocol.hpp.

References rnp::PacketHeader::flags, rnp::PacketHeader::length, rnp::PacketHeader::reserved, rnp::PacketHeader::sequence, rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.

Referenced by eng::AsioClient::processPacket(), and srv::AsioServer::processPacket().

+ Here is the caller graph for this function:

◆ serialize()

◆ serializeEvents()

std::vector< std::uint8_t > rnp::serializeEvents ( const std::vector< EventRecord > & events)
inline

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)

Definition at line 217 of file Protocol.hpp.

References MAX_PAYLOAD.

Referenced by srv::AsioServer::broadcastEntityEvents(), srv::AsioServer::broadcastEvents(), srv::AsioServer::sendEntityEvent(), srv::AsioServer::sendEvents(), and eng::AsioClient::sendPlayerInputAsEvent().

+ Here is the caller graph for this function:

◆ serializeHeader()

std::vector< uint8_t > rnp::serializeHeader ( const PacketHeader & header)
inline

Serialize packet header (Big Endian as per RNP spec)

Definition at line 292 of file Protocol.hpp.

References rnp::PacketHeader::flags, rnp::PacketHeader::length, rnp::PacketHeader::reserved, rnp::PacketHeader::sequence, rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.

Referenced by serialize().

+ Here is the caller graph for this function:

Variable Documentation

◆ MAX_PAYLOAD

std::size_t rnp::MAX_PAYLOAD = 512
inlineconstexpr

Definition at line 18 of file Protocol.hpp.

Referenced by serializeEvents().

◆ PROTOCOL_VERSION

std::uint8_t rnp::PROTOCOL_VERSION = 1
inlineconstexpr

Definition at line 17 of file Protocol.hpp.