MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / PrepareToRead

Method PrepareToRead

src/network/core/packet.cpp:278–291  ·  view source on GitHub ↗

* Prepares the packet so it can be read * @return True when the packet was valid, otherwise false. */

Source from the content-addressed store, hash-verified

276 * @return True when the packet was valid, otherwise false.
277 */
278bool Packet::PrepareToRead()
279{
280 /* Put the position on the right place */
281 this->pos = static_cast<PacketSize>(EncodedLengthOfPacketSize());
282
283 if (cs == nullptr || cs->receive_encryption_handler == nullptr) return true;
284
285 size_t mac_size = cs->receive_encryption_handler->MACSize();
286 if (this->buffer.size() <= pos + mac_size) return false;
287
288 bool valid = cs->receive_encryption_handler->Decrypt(std::span(&this->buffer[pos], mac_size), std::span(&this->buffer[pos + mac_size], this->buffer.size() - pos - mac_size));
289 this->pos += static_cast<PacketSize>(mac_size);
290 return valid;
291}
292
293/**
294 * Get the \c PacketType from this packet.

Callers 3

ReceivePacketsMethod · 0.80
ReceivePacketMethod · 0.80
CreatePacketForReadingFunction · 0.80

Calls 4

spanClass · 0.85
MACSizeMethod · 0.80
DecryptMethod · 0.80
sizeMethod · 0.45

Tested by 1

CreatePacketForReadingFunction · 0.64