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

Method Recv_string

src/network/core/packet.cpp:425–441  ·  view source on GitHub ↗

* Reads characters (bytes) from the packet until it finds a '\0', or reaches a * maximum of \c length characters. * When the '\0' has not been reached in the first \c length read characters, * more characters are read from the packet until '\0' has been reached. However, * these characters will not end up in the returned string. * The length of the returned string will be at most \c length -

Source from the content-addressed store, hash-verified

423 * @return The validated string.
424 */
425std::string Packet::Recv_string(size_t length, StringValidationSettings settings)
426{
427 assert(length > 1);
428
429 /* Both loops with Recv_uint8 terminate when reading past the end of the
430 * packet as Recv_uint8 then closes the connection and returns 0. */
431 std::string str;
432 char character;
433 while (--length > 0 && (character = this->Recv_uint8()) != '\0') str.push_back(character);
434
435 if (length == 0) {
436 /* The string in the packet was longer. Read until the termination. */
437 while (this->Recv_uint8() != '\0') {}
438 }
439
440 return StrMakeValid(str, settings);
441}
442
443/**
444 * Get the amount of bytes that are still available for the Transfer functions.

Callers 15

Receive_ADMIN_RCONMethod · 0.80
Receive_ADMIN_JOINMethod · 0.80
Receive_ADMIN_CHATMethod · 0.80
Receive_GC_ERRORMethod · 0.80
Receive_GC_LISTINGMethod · 0.80
Receive_GC_CONNECTINGMethod · 0.80

Calls 3

Recv_uint8Method · 0.95
push_backMethod · 0.80
StrMakeValidFunction · 0.50

Tested by

no test coverage detected