diff options
-rw-r--r-- | src/network/core/packet.cpp | 9 | ||||
-rw-r--r-- | src/network/core/packet.h | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index 644490e0f..6f56e4a56 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -178,12 +178,11 @@ void Packet::Send_uint64(uint64 data) * the string + '\0'. No size-byte or something. * @param data The string to send */ -void Packet::Send_string(const char *data) +void Packet::Send_string(const std::string_view data) { - assert(data != nullptr); - /* Length of the string + 1 for the '\0' termination. */ - assert(this->CanWriteToPacket(strlen(data) + 1)); - while (this->buffer.emplace_back(*data++) != '\0') {} + assert(this->CanWriteToPacket(data.size() + 1)); + this->buffer.insert(this->buffer.end(), data.begin(), data.end()); + this->buffer.emplace_back('\0'); } /** diff --git a/src/network/core/packet.h b/src/network/core/packet.h index bc7bab6c4..0f58d3be8 100644 --- a/src/network/core/packet.h +++ b/src/network/core/packet.h @@ -71,7 +71,7 @@ public: void Send_uint16(uint16 data); void Send_uint32(uint32 data); void Send_uint64(uint64 data); - void Send_string(const char *data); + void Send_string(const std::string_view data); size_t Send_bytes (const byte *begin, const byte *end); /* Reading/receiving of packets */ |