QtCraft API C++ classes QML types Handbook

QcProtocol Namespace

Binary wire format: every frame is [quint16 type tag][payload] in QDataStream big-endian encoding. More...

Header: #include <common/protocol/QcProtocol.h>

Types

enum class Peer { Client, Server }

Variables

const quint32 firstVersionWithClientText
const int maxFrameBytes
const quint32 version

Functions

QcResult<QcMessage> decode(const QByteArray &frame, QcProtocol::Peer sender)
QByteArray encode(const QcMessage &message)
bool isSentBy(std::size_t messageIndex, QcProtocol::Peer sender)
quint32 predictionSequence(const QcMessage &message)
QcResult<std::shared_ptr<QcChunk>> readChunk(QDataStream &stream)
void writeChunk(QDataStream &stream, const QcChunk &chunk)

Detailed Description

Transports deliver whole frames; framing on byte streams is the transport's job.

Type Documentation

enum class QcProtocol::Peer

The two ends of a connection.

ConstantValueDescription
QcProtocol::Peer::Client0The client.
QcProtocol::Peer::Server1The server.

Variable Documentation

const quint32 QcProtocol::firstVersionWithClientText

From this version on Hello starts with version, player name and client text, so a server of another version still reads who knocked (decision E-834).

const int QcProtocol::maxFrameBytes

The largest frame decode() accepts.

const quint32 QcProtocol::version

Bumped whenever a message layout changes (history: decision E-368): 66 sends the threads of families with the content (decision E-839), 67 brings the admin channel (decision E-848), 68 sends the speed of status effects with the content (decision E-838), 69 numbers the predicted block actions and acknowledges them (decision E-853), 70 brings the enchanting table and enchantments on stacks (decision E-864), 71 the anvil and the prior work on stacks (decision E-866), 72 the names of chests and machines (OpenMachine), content keys of chat lines (ChatMessage) and items that store their enchantments in the content (decision E-873), 73 the building part of a block (partOf) in the content (decision E-874), 74 the pause of the server (PauseRequest, ServerPause; decision E-877), 75 runs every network connection over TLS (decision E-872; the messages are unchanged), 76 the band-pass, volume variation and drive of sounds in the content (decision E-879), 77 map centres and debug goals over the whole technical bound of the world (decision E-883), 78 the rune seed of the enchanting screen (EnchantingState::runeSeed, decision E-884), 79 whether a block is a bed in the content (decision E-885), 80 the latency probes (LatencyProbe, LatencyEcho) and the round trip of each player in the PlayerList (decision E-886), 81 the group and the names of each command in the AdminCatalogue (decision E-911), 82 boats: the entity kind Boat, the boat item's boatBlock in the content and the driven boat's state in PlayerState, the Rowing bit of a boat whose driver paddles (decision E-920), 83 the advancements: their definitions in the content and the player's progress (AdvancementProgress, decision E-923), 84 the player's air under water (PlayerAir, decision E-955), 85 a fresh hit and its direction in PlayerHealth (decision E-971), 86 the pulse, ink and tentacles of creatures that swim in pulses in the content (decision E-974), 87 the drawn placement of held launchers in the content (QcHoldDisplay::drawn and thirdPersonDrawn, decision E-984), 88 usingItem in PlayerInput and PlayerState (decision E-986).

Function Documentation

QcResult<QcMessage> QcProtocol::decode(const QByteArray &frame, QcProtocol::Peer sender)

Returns the message of frame received from sender, or why it is invalid: too large, empty, of an unknown type or one that peer must not send (rejected before its payload is read), undecodable, truncated or with trailing bytes.

QByteArray QcProtocol::encode(const QcMessage &message)

Returns the frame of message: its type tag and payload.

bool QcProtocol::isSentBy(std::size_t messageIndex, QcProtocol::Peer sender)

Returns whether sender may send the message with the variant index messageIndex; decode() rejects the rest.

quint32 QcProtocol::predictionSequence(const QcMessage &message)

Returns the number of the client's block prediction message carries if it is a FinishMining or UseItem (decision E-853); 0 for other messages and for actions the client predicted nothing for.

QcResult<std::shared_ptr<QcChunk>> QcProtocol::readChunk(QDataStream &stream)

Returns the chunk read from stream in the encoding of writeChunk(), or why its data is corrupt.

void QcProtocol::writeChunk(QDataStream &stream, const QcChunk &chunk)

Writes chunk to stream: its position, then per section a palette plus run-length encoded indices; shared with persistence.