1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-18 01:42:38 +01:00

Codechange: use std::unique_ptr for the Packets created to send via TCP

This commit is contained in:
Rubidium
2024-02-03 19:55:51 +01:00
committed by rubidium42
parent 36e1b32ccf
commit 031a9d4e26
10 changed files with 164 additions and 169 deletions

View File

@@ -204,7 +204,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type)
this->Connect();
Packet *p = new Packet(PACKET_CONTENT_CLIENT_INFO_LIST);
auto p = std::make_unique<Packet>(PACKET_CONTENT_CLIENT_INFO_LIST);
p->Send_uint8 ((byte)type);
p->Send_uint32(0xffffffff);
p->Send_uint8 (1);
@@ -221,7 +221,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type)
*/
this->SendPacket(p);
this->SendPacket(std::move(p));
}
/**
@@ -240,14 +240,14 @@ void ClientNetworkContentSocketHandler::RequestContentList(uint count, const Con
* The rest of the packet can be used for the IDs. */
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t));
Packet *p = new Packet(PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU);
auto p = std::make_unique<Packet>(PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU);
p->Send_uint16(p_count);
for (uint i = 0; i < p_count; i++) {
p->Send_uint32(content_ids[i]);
}
this->SendPacket(p);
this->SendPacket(std::move(p));
count -= p_count;
content_ids += p_count;
}
@@ -268,7 +268,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
assert(cv->size() < (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint8_t)) /
(sizeof(uint8_t) + sizeof(uint32_t) + (send_md5sum ? MD5_HASH_BYTES : 0)));
Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID, TCP_MTU);
auto p = std::make_unique<Packet>(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID, TCP_MTU);
p->Send_uint8((uint8_t)cv->size());
for (const ContentInfo *ci : *cv) {
@@ -281,7 +281,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
}
}
this->SendPacket(p);
this->SendPacket(std::move(p));
for (ContentInfo *ci : *cv) {
bool found = false;
@@ -365,14 +365,14 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
* The rest of the packet can be used for the IDs. */
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t));
Packet *p = new Packet(PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU);
auto p = std::make_unique<Packet>(PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU);
p->Send_uint16(p_count);
for (uint i = 0; i < p_count; i++) {
p->Send_uint32(content_ids[i]);
}
this->SendPacket(p);
this->SendPacket(std::move(p));
count -= p_count;
content_ids += p_count;
}