From 6611ed5a533a6730ceeb28cd78d5eb7343b2ed04 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 2 Nov 2021 23:28:03 +0000 Subject: [PATCH] Encode oversize map dimensions in non-extended game info serialisation Use non power of 2 values for sizes >= 64k --- src/network/core/game_info.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp index 3962529249..7fc63a698d 100644 --- a/src/network/core/game_info.cpp +++ b/src/network/core/game_info.cpp @@ -250,8 +250,16 @@ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool p->Send_uint8 (info->clients_max); p->Send_uint8 (info->clients_on); p->Send_uint8 (info->spectators_on); - p->Send_uint16(info->map_width); - p->Send_uint16(info->map_height); + + auto encode_map_size = [&](uint32 in) -> uint16 { + if (in < UINT16_MAX) { + return in; + } else { + return 65000 + FindFirstBit(in); + } + }; + p->Send_uint16(encode_map_size(info->map_width)); + p->Send_uint16(encode_map_size(info->map_height)); p->Send_uint8 (info->landscape); p->Send_bool (info->dedicated); } @@ -415,8 +423,17 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfo info->start_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR; } if (game_info_version < 6) while (p->Recv_uint8() != 0) {} // Used to contain the map-name. - info->map_width = p->Recv_uint16(); - info->map_height = p->Recv_uint16(); + + auto decode_map_size = [&](uint16 in) -> uint32 { + if (in >= 65000) { + return 1 << (in - 65000); + } else { + return in; + } + }; + info->map_width = decode_map_size(p->Recv_uint16()); + info->map_height = decode_map_size(p->Recv_uint16()); + info->landscape = p->Recv_uint8 (); info->dedicated = p->Recv_bool ();