Skip to content

Commit c873f9b

Browse files
committed
address comments
1 parent c414fab commit c873f9b

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

Core/GameEngine/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ set(GAMEENGINE_SRC
33
# Include/Common/ActionManager.h
44
Include/Common/AddonCompat.h
55
Include/Common/ArchiveFile.h
6-
Include/GameNetwork/NetPacketStructs.h
76
Include/Common/ArchiveFileSystem.h
87
Include/Common/AsciiString.h
98
Include/Common/AudioAffect.h
@@ -546,6 +545,7 @@ set(GAMEENGINE_SRC
546545
Include/GameNetwork/NetCommandRef.h
547546
Include/GameNetwork/NetCommandWrapperList.h
548547
Include/GameNetwork/NetPacket.h
548+
Include/GameNetwork/NetPacketStructs.h
549549
Include/GameNetwork/NetworkDefs.h
550550
Include/GameNetwork/NetworkInterface.h
551551
Include/GameNetwork/networkutil.h

Core/GameEngine/Include/GameNetwork/NetCommandMsg.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class NetCommandMsg : public MemoryPoolObject
4444
inline void setExecutionFrame(UnsignedInt frame) { m_executionFrame = frame; }
4545
inline void setPlayerID(UnsignedInt playerID) { m_playerID = playerID; }
4646
inline void setID(UnsignedShort id) { m_id = id; }
47-
inline UnsignedInt getExecutionFrame() { return m_executionFrame; }
48-
inline UnsignedInt getPlayerID() { return m_playerID; }
49-
inline UnsignedShort getID() { return m_id; }
47+
inline UnsignedInt getExecutionFrame() const { return m_executionFrame; }
48+
inline UnsignedInt getPlayerID() const { return m_playerID; }
49+
inline UnsignedShort getID() const { return m_id; }
5050
inline void setNetCommandType(NetCommandType type) { m_commandType = type; }
5151
inline NetCommandType getNetCommandType() { return m_commandType; }
5252
virtual Int getSortNumber();
@@ -77,7 +77,7 @@ class NetGameCommandMsg : public NetCommandMsg
7777
NetGameCommandMsg(GameMessage *msg);
7878
//virtual ~NetGameCommandMsg();
7979

80-
GameMessage *constructGameMessage();
80+
GameMessage *constructGameMessage() const;
8181
void addArgument(const GameMessageArgumentDataType type, GameMessageArgumentType arg);
8282
void setGameMessageType(GameMessage::Type type);
8383

@@ -396,6 +396,7 @@ class NetProgressCommandMsg: public NetCommandMsg
396396
void setPercentage( UnsignedByte percent );
397397

398398
virtual size_t getPackedByteCount() const;
399+
399400
protected:
400401
UnsignedByte m_percent;
401402
};

Core/GameEngine/Include/GameNetwork/NetPacketStructs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
** Command & Conquer Generals Zero Hour(tm)
3-
** Copyright 2025 TheSuperHackers.
3+
** Copyright 2025 TheSuperHackers
44
**
55
** This program is free software: you can redistribute it and/or modify
66
** it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
1818

1919
////////////////////////////////////////////////////////////////////////////////
2020
//
21-
// TheSuperHackers @refactor BobTista 10/07/2025
21+
// TheSuperHackers @refactor BobTista 07/10/2025
2222
// Packed struct definitions for network packet serialization/deserialization.
2323
//
2424
////////////////////////////////////////////////////////////////////////////////
@@ -52,37 +52,37 @@ namespace NetPacketFieldTypes {
5252

5353
// Command Type field: 'T' + UnsignedByte
5454
struct NetPacketCommandTypeField {
55-
char header; // 'T'
55+
char header;
5656
UnsignedByte commandType;
5757
};
5858

5959
// Relay field: 'R' + UnsignedByte
6060
struct NetPacketRelayField {
61-
char header; // 'R'
61+
char header;
6262
UnsignedByte relay;
6363
};
6464

6565
// Player ID field: 'P' + UnsignedByte
6666
struct NetPacketPlayerIdField {
67-
char header; // 'P'
67+
char header;
6868
UnsignedByte playerId;
6969
};
7070

7171
// Frame field: 'F' + UnsignedInt
7272
struct NetPacketFrameField {
73-
char header; // 'F'
73+
char header;
7474
UnsignedInt frame;
7575
};
7676

7777
// Command ID field: 'C' + UnsignedShort
7878
struct NetPacketCommandIdField {
79-
char header; // 'C'
79+
char header;
8080
UnsignedShort commandId;
8181
};
8282

8383
// Data field header: 'D' (followed by variable-length data)
8484
struct NetPacketDataFieldHeader {
85-
char header; // 'D'
85+
char header;
8686
};
8787

8888
////////////////////////////////////////////////////////////////////////////////

Core/GameEngine/Source/GameNetwork/NetCommandMsg.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static Int indexFromMask(UnsignedInt mask)
171171
/**
172172
* Construct a new GameMessage object from the data in this object.
173173
*/
174-
GameMessage *NetGameCommandMsg::constructGameMessage()
174+
GameMessage *NetGameCommandMsg::constructGameMessage() const
175175
{
176176
GameMessage *retval = newInstance(GameMessage)(m_type);
177177

@@ -232,14 +232,11 @@ void NetGameCommandMsg::setGameMessageType(GameMessage::Type type) {
232232
m_type = type;
233233
}
234234

235-
/**
236-
* Get the byte count for this game command message.
237-
*/
238235
size_t NetGameCommandMsg::getPackedByteCount() const {
239236
UnsignedShort msglen = sizeof(NetPacketGameCommand);
240237

241238
// Variable data portion
242-
GameMessage *gmsg = const_cast<NetGameCommandMsg*>(this)->constructGameMessage();
239+
GameMessage *gmsg = constructGameMessage();
243240
GameMessageParser *parser = newInstance(GameMessageParser)(gmsg);
244241

245242
msglen += sizeof(GameMessage::Type);
@@ -882,23 +879,19 @@ void NetChatCommandMsg::setPlayerMask( Int playerMask )
882879
m_playerMask = playerMask;
883880
}
884881

885-
/**
886-
* Get the byte count for this chat message.
887-
*/
888882
size_t NetChatCommandMsg::getPackedByteCount() const
889883
{
890-
return sizeof(NetPacketChatCommand) + sizeof(UnsignedByte) /* text length byte */ + m_text.getByteCount() + sizeof(m_playerMask);
884+
return sizeof(NetPacketChatCommand) + sizeof(UnsignedByte) /* text length byte */ + m_text.getByteCount()
885+
+ sizeof(m_playerMask);
891886
}
892887

893888
//-------------------------
894889
// NetDisconnectChatCommandMsg
895890
//-------------------------
896-
/**
897-
* Get the byte count for this disconnect chat message.
898-
*/
899891
size_t NetDisconnectChatCommandMsg::getPackedByteCount() const
900892
{
901-
return sizeof(NetPacketDisconnectChatCommand) + sizeof(UnsignedByte) /* text length byte */ + m_text.getByteCount();
893+
return sizeof(NetPacketDisconnectChatCommand) + sizeof(UnsignedByte) /* text length byte */
894+
+ m_text.getByteCount();
902895
}
903896

904897
//-------------------------
@@ -1094,13 +1087,11 @@ void NetFileCommandMsg::setFileData(UnsignedByte *data, UnsignedInt dataLength)
10941087
memcpy(m_data, data, dataLength);
10951088
}
10961089

1097-
/**
1098-
* Get the byte count for this file command message.
1099-
*/
11001090
size_t NetFileCommandMsg::getPackedByteCount() const
11011091
{
1102-
return sizeof(NetPacketFileCommand) + m_portableFilename.getLength() + 1 // filename + null terminator
1103-
+ sizeof(UnsignedInt) // file data length
1092+
return sizeof(NetPacketFileCommand)
1093+
+ m_portableFilename.getLength() + 1 // filename + null terminator
1094+
+ sizeof(m_dataLength) // file data length
11041095
+ m_dataLength; // the file data
11051096
}
11061097

@@ -1143,9 +1134,6 @@ void NetFileAnnounceCommandMsg::setPlayerMask(UnsignedByte playerMask) {
11431134
m_playerMask = playerMask;
11441135
}
11451136

1146-
/**
1147-
* Get the byte count for this file announce command message.
1148-
*/
11491137
size_t NetFileAnnounceCommandMsg::getPackedByteCount() const
11501138
{
11511139
return sizeof(NetPacketFileAnnounceCommand)

0 commit comments

Comments
 (0)