From 532ce1a9079d67f8fbbef80507350111ea93bea7 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 1 May 2024 18:55:54 +0100 Subject: [PATCH] Codechange: Use Recv/Send_bytes for md5sum. (#12602) Use existing functions to handle serialisation of arrays instead of indexed for-loop. --- src/network/core/network_game_info.cpp | 8 ++------ src/network/network_content.cpp | 9 ++------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/network/core/network_game_info.cpp b/src/network/core/network_game_info.cpp index 623be7fa84..becc7d405e 100644 --- a/src/network/core/network_game_info.cpp +++ b/src/network/core/network_game_info.cpp @@ -375,9 +375,7 @@ void DeserializeNetworkGameInfo(Packet &p, NetworkGameInfo &info, const GameInfo void SerializeGRFIdentifier(Packet &p, const GRFIdentifier &grf) { p.Send_uint32(grf.grfid); - for (size_t j = 0; j < grf.md5sum.size(); j++) { - p.Send_uint8(grf.md5sum[j]); - } + p.Send_bytes(grf.md5sum); } /** @@ -388,9 +386,7 @@ void SerializeGRFIdentifier(Packet &p, const GRFIdentifier &grf) void DeserializeGRFIdentifier(Packet &p, GRFIdentifier &grf) { grf.grfid = p.Recv_uint32(); - for (size_t j = 0; j < grf.md5sum.size(); j++) { - grf.md5sum[j] = p.Recv_uint8(); - } + p.Recv_bytes(grf.md5sum); } /** diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 2395180a27..66926d26d8 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -63,9 +63,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p) ci->description = p.Recv_string(NETWORK_CONTENT_DESC_LENGTH, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE); ci->unique_id = p.Recv_uint32(); - for (size_t j = 0; j < ci->md5sum.size(); j++) { - ci->md5sum[j] = p.Recv_uint8(); - } + p.Recv_bytes(ci->md5sum); uint dependency_count = p.Recv_uint8(); ci->dependencies.reserve(dependency_count); @@ -276,10 +274,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo p->Send_uint8((uint8_t)ci->type); p->Send_uint32(ci->unique_id); if (!send_md5sum) continue; - - for (size_t j = 0; j < ci->md5sum.size(); j++) { - p->Send_uint8(ci->md5sum[j]); - } + p->Send_bytes(ci->md5sum); } this->SendPacket(std::move(p));