Zstd: Use zstd for network joins if supported at both ends

See also: https://github.com/OpenTTD/OpenTTD/pull/8773
This commit is contained in:
Jonathan G Rennison
2021-03-01 18:22:21 +00:00
parent 922e8554de
commit c2ae7580e0
5 changed files with 55 additions and 31 deletions

View File

@@ -482,6 +482,11 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap()
my_client->status = STATUS_MAP_WAIT;
Packet *p = new Packet(PACKET_CLIENT_GETMAP);
#if defined(WITH_ZSTD)
p->Send_bool(true);
#else
p->Send_bool(false);
#endif
my_client->SendPacket(p);
return NETWORK_RECV_STATUS_OKAY;
}

View File

@@ -654,7 +654,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
sent_packets = 4; // We start with trying 4 packets
/* Make a dump of the current game */
if (SaveWithFilter(this->savegame, true, true) != SL_OK) usererror("network savedump failed");
SaveModeFlags flags = SMF_NET_SERVER;
if (this->supports_zstd) flags |= SMF_ZSTD_OK;
if (SaveWithFilter(this->savegame, true, flags) != SL_OK) usererror("network savedump failed");
}
if (this->status == STATUS_MAP) {
@@ -1098,6 +1100,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *
return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED);
}
this->supports_zstd = p->Recv_bool();
/* Check if someone else is receiving the map */
for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
if (new_cs->status == STATUS_MAP) {

View File

@@ -75,6 +75,7 @@ public:
uint32 rcon_hash_bits; ///< Rcon password hash entropy bits
uint32 settings_hash_bits; ///< Settings password hash entropy bits
bool settings_authed = false;///< Authorised to control all game settings
bool supports_zstd = false; ///< Client supports zstd compression
struct PacketWriter *savegame; ///< Writer used to write the savegame.
NetworkAddress client_address; ///< IP-address of the client (so he can be banned)