Skip to content

Commit 07b592f

Browse files
committed
refactor(network): complete struct inheritance for all command message getByteCount() functions
1 parent 852766f commit 07b592f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacketStructs.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,22 @@ struct PackedNetChatCommandMsg : public PackedNetCommandMsg {
269269
struct PackedNetDisconnectChatCommandMsg : public PackedNetCommandMsg {
270270
};
271271

272+
// Game command packed struct (variable: game message data follows)
273+
struct PackedNetGameCommandMsg : public PackedNetCommandMsg {
274+
NetPacketFrameField frame;
275+
NetPacketCommandIdField commandId;
276+
};
277+
278+
// File command packed struct (variable: filename and file data follow)
279+
struct PackedNetFileCommandMsg : public PackedNetCommandMsg {
280+
NetPacketCommandIdField commandId;
281+
};
282+
283+
// File announce command packed struct (variable: filename and metadata follow)
284+
struct PackedNetFileAnnounceCommandMsg : public PackedNetCommandMsg {
285+
NetPacketCommandIdField commandId;
286+
};
287+
272288
struct NetPacketDisconnectVoteCommand {
273289
NetPacketCommandTypeField commandType;
274290
NetPacketRelayField relay;

GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ void NetGameCommandMsg::setGameMessageType(GameMessage::Type type) {
236236
* Get the byte count for this game command message.
237237
*/
238238
size_t NetGameCommandMsg::getByteCount() const {
239-
// Fixed header portion
240-
UnsignedShort msglen = sizeof(NetPacketGameCommandHeader);
239+
UnsignedShort msglen = sizeof(PackedNetGameCommandMsg);
241240

242241
// Variable data portion
243242
GameMessage *gmsg = const_cast<NetGameCommandMsg*>(this)->constructGameMessage();
@@ -1036,7 +1035,7 @@ void NetFileCommandMsg::setFileData(UnsignedByte *data, UnsignedInt dataLength)
10361035
*/
10371036
size_t NetFileCommandMsg::getByteCount() const
10381037
{
1039-
return m_portableFilename.getLength() + 1 // filename + null terminator
1038+
return sizeof(PackedNetFileCommandMsg) + m_portableFilename.getLength() + 1 // filename + null terminator
10401039
+ sizeof(UnsignedInt) // file data length
10411040
+ m_dataLength; // the file data
10421041
}
@@ -1085,7 +1084,7 @@ void NetFileAnnounceCommandMsg::setPlayerMask(UnsignedByte playerMask) {
10851084
*/
10861085
size_t NetFileAnnounceCommandMsg::getByteCount() const
10871086
{
1088-
return m_portableFilename.getLength() + 1 // filename + null terminator
1087+
return sizeof(PackedNetFileAnnounceCommandMsg) + m_portableFilename.getLength() + 1 // filename + null terminator
10891088
+ sizeof(m_fileID) // file ID
10901089
+ sizeof(m_playerMask); // player mask
10911090
}

0 commit comments

Comments
 (0)