diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-30 13:36:07 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-06-10 21:53:19 +0200 |
commit | bb8fd007605c17c4f96fdda75e3d2780b8944faf (patch) | |
tree | e2773a80f572ae78427768527e30e93448cb2c22 | |
parent | ab9b937ab7a80562b88d72ec17c6b2a6b3ed2b61 (diff) | |
download | openttd-bb8fd007605c17c4f96fdda75e3d2780b8944faf.tar.xz |
Cleanup: [Network] Remove C-string Recv_string and its last use
-rw-r--r-- | src/network/core/packet.cpp | 31 | ||||
-rw-r--r-- | src/network/core/packet.h | 1 | ||||
-rw-r--r-- | src/network/network_server.cpp | 6 |
3 files changed, 2 insertions, 36 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index c27a37d46..737b4624c 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -367,37 +367,6 @@ uint64 Packet::Recv_uint64() } /** - * Reads a string till it finds a '\0' in the stream. - * @param buffer The buffer to put the data into. - * @param size The size of the buffer. - * @param settings The string validation settings. - */ -void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings settings) -{ - char *bufp = buffer; - const char *last = buffer + size - 1; - - /* Don't allow reading from a closed socket */ - if (cs->HasClientQuit()) return; - - size_t pos = this->pos; - while (--size > 0 && pos < this->Size() && (*buffer++ = this->buffer[pos++]) != '\0') {} - - if (size == 0 || pos == this->Size()) { - *buffer = '\0'; - /* If size was sooner to zero then the string in the stream - * skip till the \0, so than packet can be read out correctly for the rest */ - while (pos < this->Size() && this->buffer[pos] != '\0') pos++; - pos++; - } - - assert(pos <= std::numeric_limits<PacketSize>::max()); - this->pos = static_cast<PacketSize>(pos); - - StrMakeValidInPlace(bufp, last, settings); -} - -/** * 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, diff --git a/src/network/core/packet.h b/src/network/core/packet.h index 21a88e3ea..277ff8bba 100644 --- a/src/network/core/packet.h +++ b/src/network/core/packet.h @@ -87,7 +87,6 @@ public: uint16 Recv_uint16(); uint32 Recv_uint32(); uint64 Recv_uint64(); - void Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); std::string Recv_string(size_t length, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); size_t RemainingBytesToTransfer() const; diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 5b1da8fa2..9b9dc6fc9 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -874,13 +874,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); } - char client_revision[NETWORK_REVISION_LENGTH]; - - p->Recv_string(client_revision, sizeof(client_revision)); + std::string client_revision = p->Recv_string(NETWORK_REVISION_LENGTH); uint32 newgrf_version = p->Recv_uint32(); /* Check if the client has revision control enabled */ - if (!IsNetworkCompatibleVersion(client_revision) || _openttd_newgrf_version != newgrf_version) { + if (!IsNetworkCompatibleVersion(client_revision.c_str()) || _openttd_newgrf_version != newgrf_version) { /* Different revisions!! */ return this->SendError(NETWORK_ERROR_WRONG_REVISION); } |