Skip to content

Commit dfb1c41

Browse files
committed
refactor(network): replicate to generals using patch method
refactor(network): move NetPacketStructs to Core
1 parent f11ab60 commit dfb1c41

File tree

6 files changed

+108
-432
lines changed

6 files changed

+108
-432
lines changed

Core/GameEngine/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(GAMEENGINE_SRC
33
# Include/Common/ActionManager.h
44
Include/Common/AddonCompat.h
55
Include/Common/ArchiveFile.h
6+
Include/GameNetwork/NetPacketStructs.h
67
Include/Common/ArchiveFileSystem.h
78
Include/Common/AsciiString.h
89
Include/Common/AudioAffect.h
@@ -545,7 +546,6 @@ set(GAMEENGINE_SRC
545546
Include/GameNetwork/NetCommandRef.h
546547
Include/GameNetwork/NetCommandWrapperList.h
547548
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "GameNetwork/NetworkDefs.h"
3333
#include "Common/UnicodeString.h"
3434

35+
//-----------------------------------------------------------------------------
3536
class NetCommandMsg : public MemoryPoolObject
3637
{
3738
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetCommandMsg, "NetCommandMsg")
@@ -64,6 +65,10 @@ class NetCommandMsg : public MemoryPoolObject
6465
};
6566

6667

68+
//-----------------------------------------------------------------------------
69+
/**
70+
* The NetGameCommandMsg is the NetCommandMsg representation of a GameMessage
71+
*/
6772
class NetGameCommandMsg : public NetCommandMsg
6873
{
6974
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetGameCommandMsg, "NetGameCommandMsg")
@@ -85,6 +90,11 @@ class NetGameCommandMsg : public NetCommandMsg
8590
GameMessageArgument *m_argList, *m_argTail;
8691
};
8792

93+
//-----------------------------------------------------------------------------
94+
/**
95+
* The NetAckBothCommandMsg is the NetCommandMsg representation of the combination of a
96+
* stage 1 ack and a stage 2 ack.
97+
*/
8898
class NetAckBothCommandMsg : public NetCommandMsg
8999
{
90100
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAckBothCommandMsg, "NetAckBothCommandMsg")
@@ -106,6 +116,11 @@ class NetAckBothCommandMsg : public NetCommandMsg
106116
UnsignedByte m_originalPlayerID;
107117
};
108118

119+
//-----------------------------------------------------------------------------
120+
/**
121+
* The NetAckStage1CommandMsg is the NetCommandMsg representation of an ack message for the initial
122+
* recipient.
123+
*/
109124
class NetAckStage1CommandMsg : public NetCommandMsg
110125
{
111126
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAckStage1CommandMsg, "NetAckStage1CommandMsg")
@@ -127,6 +142,11 @@ class NetAckStage1CommandMsg : public NetCommandMsg
127142
UnsignedByte m_originalPlayerID;
128143
};
129144

145+
//-----------------------------------------------------------------------------
146+
/**
147+
* The NetAckStage2CommandMsg is the NetCommandMsg representation of an ack message for all eventual
148+
* recipients. (when this is returned, all the players in the relay mask have received the packet)
149+
*/
130150
class NetAckStage2CommandMsg : public NetCommandMsg
131151
{
132152
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAckStage2CommandMsg, "NetAckStage2CommandMsg")
@@ -148,6 +168,7 @@ class NetAckStage2CommandMsg : public NetCommandMsg
148168
UnsignedByte m_originalPlayerID;
149169
};
150170

171+
//-----------------------------------------------------------------------------
151172
class NetFrameCommandMsg : public NetCommandMsg
152173
{
153174
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFrameCommandMsg, "NetFrameCommandMsg")
@@ -164,6 +185,7 @@ class NetFrameCommandMsg : public NetCommandMsg
164185
UnsignedShort m_commandCount;
165186
};
166187

188+
//-----------------------------------------------------------------------------
167189
class NetPlayerLeaveCommandMsg : public NetCommandMsg
168190
{
169191
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPlayerLeaveCommandMsg, "NetPlayerLeaveCommandMsg")
@@ -180,6 +202,7 @@ class NetPlayerLeaveCommandMsg : public NetCommandMsg
180202
UnsignedByte m_leavingPlayerID;
181203
};
182204

205+
//-----------------------------------------------------------------------------
183206
class NetRunAheadMetricsCommandMsg : public NetCommandMsg
184207
{
185208
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetRunAheadMetricsCommandMsg, "NetRunAheadMetricsCommandMsg")
@@ -199,6 +222,7 @@ class NetRunAheadMetricsCommandMsg : public NetCommandMsg
199222
Int m_averageFps;
200223
};
201224

225+
//-----------------------------------------------------------------------------
202226
class NetRunAheadCommandMsg : public NetCommandMsg
203227
{
204228
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetRunAheadCommandMsg, "NetRunAheadCommandMsg")
@@ -219,6 +243,7 @@ class NetRunAheadCommandMsg : public NetCommandMsg
219243
UnsignedByte m_frameRate;
220244
};
221245

246+
//-----------------------------------------------------------------------------
222247
class NetDestroyPlayerCommandMsg : public NetCommandMsg
223248
{
224249
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDestroyPlayerCommandMsg, "NetDestroyPlayerCommandMsg")
@@ -235,6 +260,7 @@ class NetDestroyPlayerCommandMsg : public NetCommandMsg
235260
UnsignedInt m_playerIndex;
236261
};
237262

263+
//-----------------------------------------------------------------------------
238264
class NetKeepAliveCommandMsg : public NetCommandMsg
239265
{
240266
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetKeepAliveCommandMsg, "NetKeepAliveCommandMsg")
@@ -245,6 +271,7 @@ class NetKeepAliveCommandMsg : public NetCommandMsg
245271
virtual size_t getPackedByteCount() const;
246272
};
247273

274+
//-----------------------------------------------------------------------------
248275
class NetDisconnectKeepAliveCommandMsg : public NetCommandMsg
249276
{
250277
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectKeepAliveCommandMsg, "NetDisconnectKeepAliveCommandMsg")
@@ -255,6 +282,7 @@ class NetDisconnectKeepAliveCommandMsg : public NetCommandMsg
255282
virtual size_t getPackedByteCount() const;
256283
};
257284

285+
//-----------------------------------------------------------------------------
258286
class NetDisconnectPlayerCommandMsg : public NetCommandMsg
259287
{
260288
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectPlayerCommandMsg, "NetDisconnectPlayerCommandMsg")
@@ -275,6 +303,7 @@ class NetDisconnectPlayerCommandMsg : public NetCommandMsg
275303
UnsignedInt m_disconnectFrame;
276304
};
277305

306+
//-----------------------------------------------------------------------------
278307
class NetPacketRouterQueryCommandMsg : public NetCommandMsg
279308
{
280309
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPacketRouterQueryCommandMsg, "NetPacketRouterQueryCommandMsg")
@@ -285,6 +314,7 @@ class NetPacketRouterQueryCommandMsg : public NetCommandMsg
285314
virtual size_t getPackedByteCount() const;
286315
};
287316

317+
//-----------------------------------------------------------------------------
288318
class NetPacketRouterAckCommandMsg : public NetCommandMsg
289319
{
290320
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPacketRouterAckCommandMsg, "NetPacketRouterAckCommandMsg")
@@ -295,6 +325,7 @@ class NetPacketRouterAckCommandMsg : public NetCommandMsg
295325
virtual size_t getPackedByteCount() const;
296326
};
297327

328+
//-----------------------------------------------------------------------------
298329
class NetDisconnectChatCommandMsg : public NetCommandMsg
299330
{
300331
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectChatCommandMsg, "NetDisconnectChatCommandMsg")
@@ -311,6 +342,7 @@ class NetDisconnectChatCommandMsg : public NetCommandMsg
311342
UnicodeString m_text;
312343
};
313344

345+
//-----------------------------------------------------------------------------
314346
class NetChatCommandMsg : public NetCommandMsg
315347
{
316348
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetChatCommandMsg, "NetChatCommandMsg")
@@ -331,6 +363,7 @@ class NetChatCommandMsg : public NetCommandMsg
331363
Int m_playerMask;
332364
};
333365

366+
//-----------------------------------------------------------------------------
334367
class NetDisconnectVoteCommandMsg : public NetCommandMsg
335368
{
336369
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectVoteCommandMsg, "NetDisconnectVoteCommandMsg")
@@ -351,6 +384,7 @@ class NetDisconnectVoteCommandMsg : public NetCommandMsg
351384
UnsignedInt m_voteFrame;
352385
};
353386

387+
//-----------------------------------------------------------------------------
354388
class NetProgressCommandMsg: public NetCommandMsg
355389
{
356390
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetProgressCommandMsg, "NetProgressCommandMsg")
@@ -366,6 +400,7 @@ class NetProgressCommandMsg: public NetCommandMsg
366400
UnsignedByte m_percent;
367401
};
368402

403+
//-----------------------------------------------------------------------------
369404
class NetWrapperCommandMsg : public NetCommandMsg
370405
{
371406
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetWrapperCommandMsg, "NetWrapperCommandMsg")
@@ -406,6 +441,7 @@ class NetWrapperCommandMsg : public NetCommandMsg
406441
UnsignedShort m_wrappedCommandID;
407442
};
408443

444+
//-----------------------------------------------------------------------------
409445
class NetFileCommandMsg : public NetCommandMsg
410446
{
411447
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFileCommandMsg, "NetFileCommandMsg")
@@ -433,6 +469,7 @@ class NetFileCommandMsg : public NetCommandMsg
433469
UnsignedInt m_dataLength;
434470
};
435471

472+
//-----------------------------------------------------------------------------
436473
class NetFileAnnounceCommandMsg : public NetCommandMsg
437474
{
438475
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFileAnnounceCommandMsg, "NetFileAnnounceCommandMsg")
@@ -460,6 +497,7 @@ class NetFileAnnounceCommandMsg : public NetCommandMsg
460497
UnsignedByte m_playerMask;
461498
};
462499

500+
//-----------------------------------------------------------------------------
463501
class NetFileProgressCommandMsg : public NetCommandMsg
464502
{
465503
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFileProgressCommandMsg, "NetFileProgressCommandMsg")
@@ -480,6 +518,7 @@ class NetFileProgressCommandMsg : public NetCommandMsg
480518
Int m_progress;
481519
};
482520

521+
//-----------------------------------------------------------------------------
483522
class NetDisconnectFrameCommandMsg : public NetCommandMsg
484523
{
485524
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectFrameCommandMsg, "NetDisconnectFrameCommandMsg")
@@ -495,6 +534,7 @@ class NetDisconnectFrameCommandMsg : public NetCommandMsg
495534
UnsignedInt m_disconnectFrame;
496535
};
497536

537+
//-----------------------------------------------------------------------------
498538
class NetDisconnectScreenOffCommandMsg : public NetCommandMsg
499539
{
500540
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectScreenOffCommandMsg, "NetDisconnectScreenOffCommandMsg")
@@ -510,6 +550,7 @@ class NetDisconnectScreenOffCommandMsg : public NetCommandMsg
510550
UnsignedInt m_newFrame;
511551
};
512552

553+
//-----------------------------------------------------------------------------
513554
class NetFrameResendRequestCommandMsg : public NetCommandMsg
514555
{
515556
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFrameResendRequestCommandMsg, "NetFrameResendRequestCommandMsg")

Core/GameEngine/Include/GameNetwork/NetPacketStructs.h

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@
3131
#pragma pack(push, 1)
3232

3333
////////////////////////////////////////////////////////////////////////////////
34-
// Common packet field structures
34+
// Network packet field type definitions
3535
////////////////////////////////////////////////////////////////////////////////
3636

37-
// Field header: 1-byte type identifier followed by data
38-
struct NetPacketFieldHeader {
39-
char fieldType; // 'T', 'R', 'P', 'F', 'C', or 'D'
40-
};
37+
// Network packet field type definitions
38+
typedef UnsignedByte NetPacketFieldType;
39+
40+
namespace NetPacketFieldTypes {
41+
constexpr const NetPacketFieldType CommandType = 'T'; // NetCommandType field
42+
constexpr const NetPacketFieldType Relay = 'R'; // Relay field
43+
constexpr const NetPacketFieldType PlayerId = 'P'; // Player ID field
44+
constexpr const NetPacketFieldType CommandId = 'C'; // Command ID field
45+
constexpr const NetPacketFieldType Frame = 'F'; // Frame field
46+
constexpr const NetPacketFieldType Data = 'D'; // Data payload field
47+
}
48+
49+
////////////////////////////////////////////////////////////////////////////////
50+
// Common packet field structures
51+
////////////////////////////////////////////////////////////////////////////////
4152

4253
// Command Type field: 'T' + UnsignedByte
4354
struct NetPacketCommandTypeField {
@@ -274,6 +285,37 @@ struct NetPacketDisconnectVoteCommand {
274285
UnsignedInt voteFrame;
275286
};
276287

288+
////////////////////////////////////////////////////////////////////////////////
289+
// Packed Structs for getPackedByteCount() calculations
290+
// These structs represent the fixed portion of variable-length command messages
291+
////////////////////////////////////////////////////////////////////////////////
292+
293+
struct NetPacketChatCommand {
294+
NetPacketCommandTypeField commandType;
295+
NetPacketRelayField relay;
296+
NetPacketPlayerIdField playerId;
297+
NetPacketDataFieldHeader dataHeader;
298+
NetPacketFrameField frame;
299+
NetPacketCommandIdField commandId;
300+
};
301+
302+
struct NetPacketDisconnectChatCommand {
303+
NetPacketCommandTypeField commandType;
304+
NetPacketRelayField relay;
305+
NetPacketPlayerIdField playerId;
306+
NetPacketDataFieldHeader dataHeader;
307+
};
308+
309+
// Game command packed struct (variable: game message data follows)
310+
struct NetPacketGameCommand {
311+
NetPacketCommandTypeField commandType;
312+
NetPacketRelayField relay;
313+
NetPacketPlayerIdField playerId;
314+
NetPacketDataFieldHeader dataHeader;
315+
NetPacketFrameField frame;
316+
NetPacketCommandIdField commandId;
317+
};
318+
277319
// Wrapper command packet (fixed size - contains metadata about wrapped command)
278320
// Fields: T + type, P + playerID, C + commandID, R + relay, D + metadata
279321
struct NetPacketWrapperCommand {
@@ -301,6 +343,15 @@ struct NetPacketFileCommandHeader {
301343
NetPacketDataFieldHeader dataHeader;
302344
};
303345

346+
// File command packed struct (variable: filename and file data follow)
347+
struct NetPacketFileCommand {
348+
NetPacketCommandTypeField commandType;
349+
NetPacketRelayField relay;
350+
NetPacketPlayerIdField playerId;
351+
NetPacketDataFieldHeader dataHeader;
352+
NetPacketCommandIdField commandId;
353+
};
354+
304355
// File announce command header (variable: filename and metadata follow)
305356
// Fixed fields: T + type, R + relay, P + playerID, C + commandID, D
306357
// Variable: null-terminated filename + UnsignedShort fileID + UnsignedByte playerMask
@@ -312,6 +363,15 @@ struct NetPacketFileAnnounceCommandHeader {
312363
NetPacketDataFieldHeader dataHeader;
313364
};
314365

366+
// File announce command packed struct (variable: filename and metadata follow)
367+
struct NetPacketFileAnnounceCommand {
368+
NetPacketCommandTypeField commandType;
369+
NetPacketRelayField relay;
370+
NetPacketPlayerIdField playerId;
371+
NetPacketDataFieldHeader dataHeader;
372+
NetPacketCommandIdField commandId;
373+
};
374+
315375
// File progress command packet
316376
// Fields: T + type, R + relay, P + playerID, C + commandID, D + fileID + progress
317377
struct NetPacketFileProgressCommand {
@@ -402,4 +462,3 @@ struct NetPacketFrameResendRequestCommand {
402462

403463
// Restore normal struct packing
404464
#pragma pack(pop)
405-

Core/GameEngine/Source/GameNetwork/NetCommandMsg.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,4 +1282,3 @@ NetTimeOutGameStartCommandMsg::~NetTimeOutGameStartCommandMsg() {
12821282
size_t NetTimeOutGameStartCommandMsg::getPackedByteCount() const {
12831283
return sizeof(NetPacketTimeOutGameStartMessage);
12841284
}
1285-

Generals/Code/GameEngine/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ set(GAMEENGINE_SRC
502502
# Include/GameNetwork/NetCommandRef.h
503503
# Include/GameNetwork/NetCommandWrapperList.h
504504
# Include/GameNetwork/NetPacket.h
505+
# Include/GameNetwork/NetPacketStructs.h
505506
# Include/GameNetwork/NetworkDefs.h
506507
# Include/GameNetwork/NetworkInterface.h
507508
# Include/GameNetwork/networkutil.h

0 commit comments

Comments
 (0)