Skip to content

Commit

Permalink
Feature: raise the maximum NewGRF limit to 255
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Jun 30, 2021
1 parent b2c9f15 commit e765307
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/network/core/config.h
Expand Up @@ -87,9 +87,20 @@ static const uint NETWORK_GRF_NAME_LENGTH = 80; ///< Maximum l

/**
* Maximum number of GRFs that can be sent.
* This limit is reached when PACKET_UDP_SERVER_RESPONSE reaches the maximum size of UDP_MTU bytes.
*
* This limit exists to avoid that the SERVER_INFO packet exceeding the
* maximum MTU. At the time of writing this limit is 32767 (TCP_MTU).
*
* In the SERVER_INFO packet is the NetworkGameInfo struct, which is
* 142 bytes + 100 per NewGRF (under the assumption strings are used to
* their max). This brings us to roughly 326 possible NewGRFs. Round it
* down so people don't freak out because they see a weird value, and you
* get the limit: 255.
*
* PS: in case you ever want to raise this number, please be mindful that
* "amount of NewGRFs" in NetworkGameInfo is currently an uint8.
*/
static const uint NETWORK_MAX_GRF_COUNT = 62;
static const uint NETWORK_MAX_GRF_COUNT = 255;

/**
* The number of landscapes in OpenTTD.
Expand Down
2 changes: 1 addition & 1 deletion src/network/network_coordinator.cpp
Expand Up @@ -437,7 +437,7 @@ void ClientNetworkCoordinatorSocketHandler::SendServerUpdate(GameInfoNewGRFMode
Debug(net, 6, "Sending server update to Game Coordinator");
this->next_update = std::chrono::steady_clock::now() + NETWORK_COORDINATOR_DELAY_BETWEEN_UPDATES;

Packet *p = new Packet(PACKET_COORDINATOR_CLIENT_UPDATE);
Packet *p = new Packet(PACKET_COORDINATOR_CLIENT_UPDATE, TCP_MTU);
p->Send_uint8(NETWORK_COORDINATOR_VERSION);
SerializeNetworkGameInfo(p, GetCurrentNetworkServerGameInfo(), newgrf_mode);

Expand Down
4 changes: 2 additions & 2 deletions src/network/network_server.cpp
Expand Up @@ -354,7 +354,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo(NetworkClientIn
/** Send the client information about the server. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo()
{
Packet *p = new Packet(PACKET_SERVER_GAME_INFO);
Packet *p = new Packet(PACKET_SERVER_GAME_INFO, TCP_MTU);
SerializeNetworkGameInfo(p, GetCurrentNetworkServerGameInfo(), GAME_INFO_NEWGRF_MODE_FULL);

this->SendPacket(p);
Expand Down Expand Up @@ -470,7 +470,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err
/** Send the check for the NewGRFs. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
{
Packet *p = new Packet(PACKET_SERVER_CHECK_NEWGRFS);
Packet *p = new Packet(PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
const GRFConfig *c;
uint grf_count = 0;

Expand Down

0 comments on commit e765307

Please sign in to comment.