Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/GameEngine/Include/GameNetwork/networkutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
UnsignedInt AssembleIp(UnsignedByte a, UnsignedByte b, UnsignedByte c, UnsignedByte d);
UnsignedInt ResolveIP(AsciiString host);
UnsignedShort GenerateNextCommandID();
UnsignedShort GetCommandID();
void ResetCommandID();
Bool DoesCommandRequireACommandID(NetCommandType type);
Bool CommandRequiresAck(const NetCommandMsg *msg);
Bool CommandRequiresDirectSend(const NetCommandMsg *msg);
Expand Down
4 changes: 4 additions & 0 deletions Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ void NetCommandList::reset() {
/**
* Insert sorts msg. Assumes that all the previous message inserts were done using this function.
* The message is sorted in based first on command type, then player id, and then command id.
*
* TheSuperHackers @info Caball009 06/06/2026 The command id may overflow and the sorting in this function
* does not check against that. Changing the sorting implementation to deal with overflows is not retail compatible,
* unlike resetting the command id.
*/
NetCommandRef * NetCommandList::addMessage(NetCommandMsg *cmdMsg) {
if (cmdMsg == nullptr) {
Expand Down
21 changes: 18 additions & 3 deletions Core/GameEngine/Source/GameNetwork/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "GameNetwork/NetworkInterface.h"
#include "GameNetwork/networkutil.h"
#include "GameNetwork/udp.h"
#include "GameNetwork/Transport.h"
#include "strtok_r.h"
Expand Down Expand Up @@ -356,6 +357,7 @@ void Network::init()
DEBUG_LOG(("FRAME_DATA_LENGTH = %d", FRAME_DATA_LENGTH));
DEBUG_LOG(("FRAMES_TO_KEEP = %d", FRAMES_TO_KEEP));

ResetCommandID();

#if defined(RTS_DEBUG)
m_networkOn = TRUE;
Expand Down Expand Up @@ -456,6 +458,7 @@ Bool Network::isMessageTypeWithinNetworkRange(GameMessage::Type type) {
void Network::GetCommandsFromCommandList() {
GameMessage *msg = TheCommandList->getFirstMessage();
GameMessage *next = nullptr;

while (msg != nullptr) {
next = msg->next();
if (isMessageTypeWithinNetworkRange(msg->getType())) { // Is this something we should be sending to the other players?
Expand Down Expand Up @@ -702,6 +705,18 @@ void Network::update()
}
#endif

const UnsignedInt frame = TheGameLogic->getFrame();

if (m_localStatus == NETLOCALSTATUS_INGAME) {
Comment thread
xezon marked this conversation as resolved.
if (frame + m_runAhead > m_lastExecutionFrame) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this condition. Can you explain it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's extracted from Network::getExecutionFrame. It should prevent the command id from getting reset in the middle of an execution frame.

// TheSuperHackers @bugfix Caball009 06/06/2026 Reset the network command id to prevent it from overflowing.
// This prevents commands from being sorted incorrectly, which can cause spurious mismatches at low CRC intervals.
if (GetCommandID() >= 64000) {
ResetCommandID();
}
}
}

GetCommandsFromCommandList(); // Remove commands from TheCommandList and send them to the connection manager.
if (m_conMgr != nullptr) {
if (m_localStatus == NETLOCALSTATUS_INGAME) {
Expand All @@ -718,11 +733,11 @@ void Network::update()
endOfGameCheck();
}

if (AllCommandsReady(TheGameLogic->getFrame())) { // If all the commands are ready for the next frame...
if (AllCommandsReady(frame)) { // If all the commands are ready for the next frame...
m_conMgr->handleAllCommandsReady();
// DEBUG_LOG(("Network::update - frame %d is ready", TheGameLogic->getFrame()));
// DEBUG_LOG(("Network::update - frame %d is ready", frame));
if (timeForNewFrame()) { // This needs to come after any other pre-frame execution checks as this changes the timing variables.
RelayCommandsToCommandList(TheGameLogic->getFrame()); // Put the commands for the next frame on TheCommandList.
RelayCommandsToCommandList(frame); // Put the commands for the next frame on TheCommandList.
m_frameDataReady = TRUE; // Tell the GameEngine to run the commands for the new frame.
}
}
Expand Down
18 changes: 14 additions & 4 deletions Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,20 @@ UnsignedInt ResolveIP(AsciiString host)
/**
* Returns the next network command ID.
*/
UnsignedShort GenerateNextCommandID() {
static UnsignedShort commandID = 64000;
++commandID;
return commandID;
static UnsignedShort s_commandID = 0;
UnsignedShort GenerateNextCommandID()
{
return s_commandID++;
}

UnsignedShort GetCommandID()
{
return s_commandID;
}

void ResetCommandID()
{
s_commandID = 0;
}

/**
Expand Down
Loading