Skip to content

Commit 022692a

Browse files
committed
tweak(network): Increase message buffer and max packet sizes to reduce connection issues
1 parent 8536a29 commit 022692a

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

Core/GameEngine/Include/Common/GameDefines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
#define RETAIL_COMPATIBLE_PATHFINDING_ALLOCATION (1)
4646
#endif
4747

48+
// Disable non retail fixes in the networking, such as putting more data per UDP packet
49+
#ifndef RETAIL_COMPATIBLE_NETWORKING
50+
#define RETAIL_COMPATIBLE_NETWORKING (1)
51+
#endif
52+
4853
// This is essentially synonymous for RETAIL_COMPATIBLE_CRC. There is a lot wrong with AIGroup, such as use-after-free, double-free, leaks,
4954
// but we cannot touch it much without breaking retail compatibility. Do not shy away from using massive hacks when fixing issues with AIGroup,
5055
// but put them behind this macro.

Core/GameEngine/Include/GameNetwork/LANAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static const Int g_lanHostNameLength = 1;
4444
static const Int g_lanGameNameLength = 16; // reduced length because of game option length
4545
static const Int g_lanGameNameReservedLength = 16; // save N wchars for ID info
4646
static const Int g_lanMaxChatLength = 100;
47-
static const Int m_lanMaxOptionsLength = MAX_PACKET_SIZE - ( 8 + (g_lanGameNameLength+1)*2 + 4 + (g_lanPlayerNameLength+1)*2
47+
static const Int m_lanMaxOptionsLength = MAX_LANAPI_PACKET_SIZE - ( 8 + (g_lanGameNameLength+1)*2 + 4 + (g_lanPlayerNameLength+1)*2
4848
+ (g_lanLoginNameLength+1) + (g_lanHostNameLength+1) );
4949
static const Int g_maxSerialLength = 23; // including the trailing '\0'
5050

@@ -271,7 +271,7 @@ struct LANMessage
271271
};
272272
#pragma pack(pop)
273273

274-
static_assert(sizeof(LANMessage) <= MAX_PACKET_SIZE, "LANMessage struct cannot be larger than the max packet size");
274+
static_assert(sizeof(LANMessage) <= MAX_LANAPI_PACKET_SIZE, "LANMessage struct cannot be larger than the max packet size");
275275

276276

277277
/**

Core/GameEngine/Include/GameNetwork/NetworkDefs.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,34 @@ enum ConnectionNumbers CPP_11(: Int)
4848
NUM_CONNECTIONS
4949
};
5050

51-
static const Int MAX_SLOTS = MAX_PLAYER+1;
51+
static constexpr const Int MAX_SLOTS = MAX_PLAYER+1;
5252

53+
// TheSuperHackers @info As we are not detecting for network fragmentation and adjusting max payload, we set 1200 bytes UDP payload as a safe upper limit for various networks
54+
// We chose 1200 bytes as when taking mobile networks into account, maximum transmission unit sizes can vary from 1340 - 1500 bytes
55+
// and when the packet headers for PPPOE, IPV6 and virtual network encapsulation are considered, we need a lower safe UDP payload to prevent fragmentation.
56+
static constexpr const Int MAX_UDP_PAYLOAD = 1200;
5357
// UDP (8 bytes) + IP header (28 bytes) = 36 bytes total. We want a total packet size of 512, so 512 - 36 = 476
54-
static const Int MAX_PACKET_SIZE = 476;
58+
static constexpr const Int RESTRICTED_UDP_PAYLOAD = 476;
59+
60+
// TheSuperHackers @info The legacy lanapi cannot use a larger packet size without breaking the gameinfo command
61+
static constexpr const Int MAX_LANAPI_PACKET_SIZE = RESTRICTED_UDP_PAYLOAD;
62+
63+
// TheSuperHackers @bugfix Mauller 08/02/2026 Allow larger ethernet UDP payload to be used for game messages, this fixes connection issues and eliminates disconnection bugs
64+
#if RETAIL_COMPATIBLE_NETWORKING
65+
static constexpr const Int MAX_PACKET_SIZE = RESTRICTED_UDP_PAYLOAD;
66+
static constexpr const Int MAX_MESSAGE_LEN = 1024;
67+
#else
68+
static constexpr const Int MAX_PACKET_SIZE = MAX_UDP_PAYLOAD;
69+
static constexpr const Int MAX_MESSAGE_LEN = MAX_UDP_PAYLOAD;
70+
#endif
71+
72+
// TheSuperHackers @bugfix Mauller 08/02/2026 Double send and receive buffer sizes to alleviate the occurance of disconnection issues in retail and non retail code.
73+
static constexpr const Int MAX_MESSAGES = 256;
5574

5675
/**
5776
* Command packet - contains frame #, total # of commands, and each command. This is what gets sent
5877
* to each player every frame
5978
*/
60-
#define MAX_MESSAGE_LEN 1024
61-
#define MAX_MESSAGES 128
6279
static const Int numCommandsPerCommandPacket = (MAX_MESSAGE_LEN - sizeof(UnsignedInt) - sizeof(UnsignedShort))/sizeof(GameMessage);
6380
#pragma pack(push, 1)
6481
struct CommandPacket

Core/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LANGame::LANGame( void )
6868
LANAPI::LANAPI( void ) : m_transport(nullptr)
6969
{
7070
DEBUG_LOG(("LANAPI::LANAPI() - max game option size is %d, sizeof(LANMessage)=%d, MAX_PACKET_SIZE=%d",
71-
m_lanMaxOptionsLength, sizeof(LANMessage), MAX_PACKET_SIZE));
71+
m_lanMaxOptionsLength, sizeof(LANMessage), MAX_LANAPI_PACKET_SIZE));
7272

7373
m_lastResendTime = 0;
7474
//

0 commit comments

Comments
 (0)