Skip to content

Commit 5a4187c

Browse files
fix(network): Verify accepted type of incoming game messages (TheSuperHackers#2708)
1 parent f8476f0 commit 5a4187c

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

Core/GameEngine/Include/GameNetwork/NetCommandMsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class NetGameCommandMsg : public NetCommandMsgT<NetPacketGameCommand, SmallNetPa
174174
GameMessage *constructGameMessage() const;
175175
void addArgument(const GameMessageArgumentDataType type, GameMessageArgumentType arg);
176176
void setGameMessageType(GameMessage::Type type);
177+
GameMessage::Type getGameMessageType() const;
177178

178179
virtual Select getSmallNetPacketSelect() const override;
179180

Core/GameEngine/Source/GameNetwork/NetCommandMsg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ void NetGameCommandMsg::setGameMessageType(GameMessage::Type type) {
224224
m_type = type;
225225
}
226226

227+
GameMessage::Type NetGameCommandMsg::getGameMessageType() const {
228+
return m_type;
229+
}
230+
227231
NetCommandMsg::Select NetGameCommandMsg::getSmallNetPacketSelect() const {
228232
Select select;
229233
select.useCommandType = 1;

Core/GameEngine/Source/GameNetwork/Network.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Network : public NetworkInterface
183183
void SendCommandsToConnectionManager(); ///< Send the new commands to the ConnectionManager
184184
Bool AllCommandsReady(UnsignedInt frame); ///< Do we have all the commands for the given frame?
185185
void RelayCommandsToCommandList(UnsignedInt frame); ///< Put the commands for the given frame onto TheCommandList.
186-
Bool isTransferCommand(GameMessage *msg); ///< Is this a command that needs to be transfered to the other clients?
186+
static Bool isMessageTypeWithinNetworkRange(GameMessage::Type type);
187187
Bool processCommand(GameMessage *msg); ///< Whatever needs to be done as a result of this command, do it now.
188188
void processFrameSynchronizedNetCommand(NetCommandRef *msg); ///< If there is a network command that needs to be executed at the same frame number on all clients, it happens here.
189189
void processRunAheadCommand(NetRunAheadCommandMsg *msg); ///< Do what needs to be done when we get a new run ahead command.
@@ -446,14 +446,8 @@ void Network::attachTransport(Transport *transport) {
446446
}
447447
}
448448

449-
/**
450-
* Does this command need to be transfered to the other game clients?
451-
*/
452-
Bool Network::isTransferCommand(GameMessage *msg) {
453-
if ((msg != nullptr) && ((msg->getType() > GameMessage::MSG_BEGIN_NETWORK_MESSAGES) && (msg->getType() < GameMessage::MSG_END_NETWORK_MESSAGES))) {
454-
return TRUE;
455-
}
456-
return FALSE;
449+
Bool Network::isMessageTypeWithinNetworkRange(GameMessage::Type type) {
450+
return type > GameMessage::MSG_BEGIN_NETWORK_MESSAGES && type < GameMessage::MSG_END_NETWORK_MESSAGES;
457451
}
458452

459453
/**
@@ -464,7 +458,7 @@ void Network::GetCommandsFromCommandList() {
464458
GameMessage *next = nullptr;
465459
while (msg != nullptr) {
466460
next = msg->next();
467-
if (isTransferCommand(msg)) { // Is this something we should be sending to the other players?
461+
if (isMessageTypeWithinNetworkRange(msg->getType())) { // Is this something we should be sending to the other players?
468462
if (m_localStatus == NETLOCALSTATUS_INGAME) {
469463
m_conMgr->sendLocalGameMessage(msg, getExecutionFrame());
470464
}
@@ -586,8 +580,19 @@ void Network::RelayCommandsToCommandList(UnsignedInt frame) {
586580
while (msg != nullptr) {
587581
NetCommandType cmdType = msg->getCommand()->getNetCommandType();
588582
if (cmdType == NETCOMMANDTYPE_GAMECOMMAND) {
589-
//DEBUG_LOG(("Network::RelayCommandsToCommandList - appending command %d of type %s to command list on frame %d", msg->getCommand()->getID(), ((NetGameCommandMsg *)msg->getCommand())->constructGameMessage()->getCommandAsString(), TheGameLogic->getFrame()));
590-
TheCommandList->appendMessage(((NetGameCommandMsg *)msg->getCommand())->constructGameMessage());
583+
NetGameCommandMsg* gmsg = static_cast<NetGameCommandMsg*>(msg->getCommand());
584+
#if RETAIL_COMPATIBLE_CRC
585+
TheCommandList->appendMessage(gmsg->constructGameMessage());
586+
#else
587+
// TheSuperHackers @fix stephanmeesters 14/05/2026 Verify accepted type of incoming game messages
588+
if (isMessageTypeWithinNetworkRange(gmsg->getGameMessageType())) {
589+
//DEBUG_LOG(("Network::RelayCommandsToCommandList - appending command %d of type %s to command list on frame %d", msg->getCommand()->getID(), gmsg->getCommandAsString(), TheGameLogic->getFrame()));
590+
TheCommandList->appendMessage(gmsg->constructGameMessage());
591+
} else {
592+
DEBUG_LOG(("Network::RelayCommandsToCommandList - rejecting game message from player %d of type %s, which is not a network type.",
593+
gmsg->getPlayerID(), GameMessage::getCommandTypeAsString(gmsg->getGameMessageType())));
594+
}
595+
#endif
591596
} else {
592597
processFrameSynchronizedNetCommand(msg);
593598
}

0 commit comments

Comments
 (0)