|
R-Type
Distributed multiplayer game engine in C++
|
Network protocol with unified message format. More...
Functions | |
| std::vector< uint8_t > | createMessage (MessageType type, const std::vector< uint8_t > &payload) |
| Create a message with type and payload. | |
| MessageType | getMessageType (const std::vector< uint8_t > &packet) |
| Get message type from packet. | |
| std::vector< uint8_t > | getPayload (const std::vector< uint8_t > &packet) |
| Get payload from packet (without header) | |
| std::vector< uint8_t > | serializeString (const std::string &str) |
| Serialize a string to bytes. | |
| std::string | deserializeString (const std::vector< uint8_t > &bytes, size_t &offset) |
| Deserialize bytes to string. | |
| std::vector< uint8_t > | createConnectRequest (const std::string &playerName, bool isSpectator=false) |
| Create HANDSHAKE_REQUEST message. | |
| std::string | parseConnectRequest (const std::vector< uint8_t > &packet, bool &isSpectator) |
| Parse HANDSHAKE_REQUEST message. | |
| std::string | parseConnectRequest (const std::vector< uint8_t > &packet) |
| Parse HANDSHAKE_REQUEST message (legacy - without spectator flag) | |
| std::vector< uint8_t > | createConnectResponse (const std::string &message) |
| Create HANDSHAKE_RESPONSE message. | |
| std::string | parseConnectResponse (const std::vector< uint8_t > &packet) |
| Parse HANDSHAKE_RESPONSE message. | |
Network protocol with unified message format.
Protocol format: [2 bytes: MessageType][4 bytes: payload_length][N bytes: payload]
This is modular, secure, and scalable:
Example: auto packet = createMessage(MessageType::CONNECT_REQUEST, playerName); auto type = getMessageType(packet); auto payload = getPayload(packet);
|
strong |
All message types in the R-Type protocol.
Add new types here as you need them. Each type is 2 bytes (uint16_t).
Message type mapping to Cap'n Proto wrappers:
Definition at line 52 of file NetworkMessages.hpp.
|
inline |
Create HANDSHAKE_REQUEST message.
| playerName | Player's name |
| isSpectator | Whether this is a spectator connection |
Definition at line 249 of file NetworkMessages.hpp.
References createMessage(), HANDSHAKE_REQUEST, and serializeString().

|
inline |
Create HANDSHAKE_RESPONSE message.
| message | Welcome message |
Definition at line 305 of file NetworkMessages.hpp.
References createMessage(), HANDSHAKE_RESPONSE, and serializeString().
Referenced by Server::_handleHandshakeRequest().

|
inline |
Create a message with type and payload.
| type | Message type identifier |
| payload | Message data |
Definition at line 111 of file NetworkMessages.hpp.
Referenced by Server::_broadcastGameState(), Server::_handleChatMessage(), Server::_handleHandshakeRequest(), Server::_processPendingDestructions(), Server::_sendPacket(), createConnectRequest(), createConnectResponse(), GameLoop::processInput(), Replicator::sendAutoMatchmaking(), Replicator::sendChatMessage(), Replicator::sendConnectRequest(), Replicator::sendCreateRoom(), server::GameruleBroadcaster::sendGamerulePacket(), Replicator::sendJoinRoom(), Replicator::sendLeaveRoom(), Replicator::sendListRooms(), Replicator::sendLoginAccount(), Replicator::sendRegisterAccount(), Replicator::sendStartGame(), and Replicator::updateAutoMatchmakingPreference().
|
inline |
Deserialize bytes to string.
Definition at line 205 of file NetworkMessages.hpp.
Referenced by parseConnectRequest(), and parseConnectResponse().
|
inline |
Get message type from packet.
| packet | Complete packet with header |
Definition at line 137 of file NetworkMessages.hpp.
References UNKNOWN.
Referenced by GameLoop::handleNetworkMessage(), Server::handlePacket(), Replicator::networkThreadLoop(), parseConnectRequest(), parseConnectResponse(), and Replicator::processMessages().
|
inline |
Get payload from packet (without header)
| packet | Complete packet with header |
Definition at line 152 of file NetworkMessages.hpp.
Referenced by Server::_handleAutoMatchmaking(), Server::_handleChatMessage(), Server::_handleCreateRoom(), Server::_handleHandshakeRequest(), Server::_handleJoinRoom(), Server::_handleLoginRequest(), Server::_handlePlayerInput(), Server::_handleRegisterRequest(), Server::_handleUpdateAutoMatchmakingPref(), GameLoop::handleNetworkMessage(), Replicator::networkThreadLoop(), parseConnectRequest(), parseConnectResponse(), and Replicator::processMessages().
|
inline |
Parse HANDSHAKE_REQUEST message (legacy - without spectator flag)
| packet | Complete packet |
Definition at line 294 of file NetworkMessages.hpp.
References parseConnectRequest().

|
inline |
Parse HANDSHAKE_REQUEST message.
| packet | Complete packet | |
| [out] | isSpectator | Set to true if this is a spectator connection |
Definition at line 267 of file NetworkMessages.hpp.
References deserializeString(), getMessageType(), getPayload(), and HANDSHAKE_REQUEST.
Referenced by parseConnectRequest().

|
inline |
Parse HANDSHAKE_RESPONSE message.
| packet | Complete packet |
Definition at line 317 of file NetworkMessages.hpp.
References deserializeString(), getMessageType(), getPayload(), and HANDSHAKE_RESPONSE.

|
inline |
Serialize a string to bytes.
Definition at line 186 of file NetworkMessages.hpp.
Referenced by createConnectRequest(), and createConnectResponse().