Fix assertion failure in RequestContentList with many GRFs

This commit is contained in:
Jonathan G Rennison
2018-06-11 01:47:44 +01:00
parent 2c7b96cf1e
commit 847a46d107

View File

@@ -248,15 +248,18 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
this->Connect(); this->Connect();
assert(cv->Length() < 255); const uint max_per_packet = min<uint>(255, (SEND_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint8)) /
assert(cv->Length() < (SEND_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint8)) / (sizeof(uint8) + sizeof(uint32) + (send_md5sum ? /*sizeof(ContentInfo::md5sum)*/16 : 0))) - 1;
(sizeof(uint8) + sizeof(uint32) + (send_md5sum ? /*sizeof(ContentInfo::md5sum)*/16 : 0)));
uint offset = 0;
while (cv->Length() > offset) {
Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID); Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID);
p->Send_uint8(cv->Length()); const uint to_send = min<uint>(cv->Length() - offset, max_per_packet);
p->Send_uint8(to_send);
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) { for (uint i = 0; i < to_send; i++) {
const ContentInfo *ci = *iter; const ContentInfo *ci = (*cv)[offset + i];
p->Send_uint8((byte)ci->type); p->Send_uint8((byte)ci->type);
p->Send_uint32(ci->unique_id); p->Send_uint32(ci->unique_id);
if (!send_md5sum) continue; if (!send_md5sum) continue;
@@ -268,6 +271,9 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
this->SendPacket(p); this->SendPacket(p);
offset += to_send;
}
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) { for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) {
ContentInfo *ci = *iter; ContentInfo *ci = *iter;
bool found = false; bool found = false;