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

Method CanReadFromPacket

src/network/core/packet.cpp:219–231  ·  view source on GitHub ↗

* Is it safe to read from the packet, i.e. didn't we run over the buffer? * In case \c close_connection is true, the connection will be closed when one would * overrun the buffer. When it is false, the connection remains untouched. * @param bytes_to_read The amount of bytes we want to try to read. * @param close_connection Whether to close the connection if one cannot read that amount. * @

Source from the content-addressed store, hash-verified

217 * @return True if that is safe, otherwise false.
218 */
219bool Packet::CanReadFromPacket(size_t bytes_to_read, bool close_connection)
220{
221 /* Don't allow reading from a quit client/client who send bad data */
222 if (this->cs->HasClientQuit()) return false;
223
224 /* Check if variable is within packet-size */
225 if (this->pos + bytes_to_read > this->Size()) {
226 if (close_connection) this->cs->NetworkSocketHandler::MarkClosed();
227 return false;
228 }
229
230 return true;
231}
232
233/**
234 * Check whether the packet, given the position of the "write" pointer, has read

Callers 7

Recv_uint8Method · 0.95
Recv_uint16Method · 0.95
Recv_uint32Method · 0.95
Recv_uint64Method · 0.95
Recv_bufferMethod · 0.95
Receive_SERVER_ERRORMethod · 0.80
network_client.cppFile · 0.80

Calls 2

SizeMethod · 0.95
HasClientQuitMethod · 0.80

Tested by

no test coverage detected