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

Method ParsePacketSize

src/network/core/packet.cpp:259–272  ·  view source on GitHub ↗

* Reads the packet size from the raw packet and stores it in the packet->size * @return True iff the packet size seems plausible. */

Source from the content-addressed store, hash-verified

257 * @return True iff the packet size seems plausible.
258 */
259bool Packet::ParsePacketSize()
260{
261 size_t size = static_cast<size_t>(this->buffer[0]);
262 size += static_cast<size_t>(this->buffer[1]) << 8;
263
264 /* If the size of the packet is less than the bytes required for the size and type of
265 * the packet, or more than the allowed limit, then something is wrong with the packet.
266 * In those cases the packet can generally be regarded as containing garbage data. */
267 if (size < EncodedLengthOfPacketSize() + EncodedLengthOfPacketType() || size > this->limit) return false;
268
269 this->buffer.resize(size);
270 this->pos = static_cast<PacketSize>(EncodedLengthOfPacketSize());
271 return true;
272}
273
274/**
275 * Prepares the packet so it can be read

Callers 2

ReceivePacketsMethod · 0.80
ReceivePacketMethod · 0.80

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected