Skip to content

Commit 1a30bfe

Browse files
committed
refactor(netpacket): Remove duplicate packed commands and cleanup code comments (#2283)
1 parent 77e4510 commit 1a30bfe

2 files changed

Lines changed: 11 additions & 158 deletions

File tree

Core/GameEngine/Include/GameNetwork/NetPacketStructs.h

Lines changed: 8 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
** along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
////////////////////////////////////////////////////////////////////////////////
20-
//
2119
// TheSuperHackers @refactor BobTista 07/10/2025
22-
// Packed struct definitions for network packet serialization/deserialization.
23-
//
24-
////////////////////////////////////////////////////////////////////////////////
20+
// Packed struct definitions for network packet serialization.
2521

2622
#pragma once
2723

@@ -34,63 +30,54 @@
3430
// Network packet field type definitions
3531
////////////////////////////////////////////////////////////////////////////////
3632

37-
// Network packet field type definitions
3833
typedef UnsignedByte NetPacketFieldType;
3934

4035
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
36+
constexpr const NetPacketFieldType CommandType = 'T';
37+
constexpr const NetPacketFieldType Relay = 'R';
38+
constexpr const NetPacketFieldType PlayerId = 'P';
39+
constexpr const NetPacketFieldType CommandId = 'C';
40+
constexpr const NetPacketFieldType Frame = 'F';
41+
constexpr const NetPacketFieldType Data = 'D';
4742
}
4843

4944
////////////////////////////////////////////////////////////////////////////////
5045
// Common packet field structures
5146
////////////////////////////////////////////////////////////////////////////////
5247

53-
// Command Type field: 'T' + UnsignedByte
5448
struct NetPacketCommandTypeField {
5549
char header;
5650
UnsignedByte commandType;
5751
};
5852

59-
// Relay field: 'R' + UnsignedByte
6053
struct NetPacketRelayField {
6154
char header;
6255
UnsignedByte relay;
6356
};
6457

65-
// Player ID field: 'P' + UnsignedByte
6658
struct NetPacketPlayerIdField {
6759
char header;
6860
UnsignedByte playerId;
6961
};
7062

71-
// Frame field: 'F' + UnsignedInt
7263
struct NetPacketFrameField {
7364
char header;
7465
UnsignedInt frame;
7566
};
7667

77-
// Command ID field: 'C' + UnsignedShort
7868
struct NetPacketCommandIdField {
7969
char header;
8070
UnsignedShort commandId;
8171
};
8272

83-
// Data field header: 'D' (followed by variable-length data)
8473
struct NetPacketDataFieldHeader {
8574
char header;
8675
};
8776

8877
////////////////////////////////////////////////////////////////////////////////
89-
// Acknowledgment Command Packets
78+
// Packed Network structures
9079
////////////////////////////////////////////////////////////////////////////////
9180

92-
// ACK command packet structure
93-
// Fields: T + type, P + playerID, D + commandID + originalPlayerID
9481
struct NetPacketAckCommand {
9582
NetPacketCommandTypeField commandType;
9683
NetPacketPlayerIdField playerId;
@@ -99,12 +86,6 @@ struct NetPacketAckCommand {
9986
UnsignedByte originalPlayerId; // Original player who sent the command
10087
};
10188

102-
////////////////////////////////////////////////////////////////////////////////
103-
// Frame Info Command Packet
104-
////////////////////////////////////////////////////////////////////////////////
105-
106-
// Frame info command packet structure
107-
// Fields: T + type, F + frame, R + relay, P + playerID, C + commandID, D + commandCount
10889
struct NetPacketFrameCommand {
10990
NetPacketCommandTypeField commandType;
11091
NetPacketFrameField frame;
@@ -115,12 +96,6 @@ struct NetPacketFrameCommand {
11596
UnsignedShort commandCount;
11697
};
11798

118-
////////////////////////////////////////////////////////////////////////////////
119-
// Player Leave Command Packet
120-
////////////////////////////////////////////////////////////////////////////////
121-
122-
// Player leave command packet structure
123-
// Fields: T + type, R + relay, F + frame, P + playerID, C + commandID, D + leavingPlayerID
12499
struct NetPacketPlayerLeaveCommand {
125100
NetPacketCommandTypeField commandType;
126101
NetPacketRelayField relay;
@@ -131,12 +106,6 @@ struct NetPacketPlayerLeaveCommand {
131106
UnsignedByte leavingPlayerId;
132107
};
133108

134-
////////////////////////////////////////////////////////////////////////////////
135-
// Run Ahead Metrics Command Packet
136-
////////////////////////////////////////////////////////////////////////////////
137-
138-
// Run ahead metrics command packet structure
139-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + averageLatency + averageFps
140109
struct NetPacketRunAheadMetricsCommand {
141110
NetPacketCommandTypeField commandType;
142111
NetPacketRelayField relay;
@@ -147,12 +116,6 @@ struct NetPacketRunAheadMetricsCommand {
147116
UnsignedShort averageFps;
148117
};
149118

150-
////////////////////////////////////////////////////////////////////////////////
151-
// Run Ahead Command Packet
152-
////////////////////////////////////////////////////////////////////////////////
153-
154-
// Run ahead command packet structure
155-
// Fields: T + type, R + relay, F + frame, P + playerID, C + commandID, D + runAhead + frameRate
156119
struct NetPacketRunAheadCommand {
157120
NetPacketCommandTypeField commandType;
158121
NetPacketRelayField relay;
@@ -164,12 +127,6 @@ struct NetPacketRunAheadCommand {
164127
UnsignedByte frameRate;
165128
};
166129

167-
////////////////////////////////////////////////////////////////////////////////
168-
// Destroy Player Command Packet
169-
////////////////////////////////////////////////////////////////////////////////
170-
171-
// Destroy player command packet structure
172-
// Fields: T + type, R + relay, F + frame, P + playerID, C + commandID, D + playerIndex
173130
struct NetPacketDestroyPlayerCommand {
174131
NetPacketCommandTypeField commandType;
175132
NetPacketRelayField relay;
@@ -180,38 +137,20 @@ struct NetPacketDestroyPlayerCommand {
180137
UnsignedInt playerIndex;
181138
};
182139

183-
////////////////////////////////////////////////////////////////////////////////
184-
// Keep Alive Command Packet
185-
////////////////////////////////////////////////////////////////////////////////
186-
187-
// Keep alive command packet structure
188-
// Fields: T + type, R + relay, P + playerID, D
189140
struct NetPacketKeepAliveCommand {
190141
NetPacketCommandTypeField commandType;
191142
NetPacketRelayField relay;
192143
NetPacketPlayerIdField playerId;
193144
NetPacketDataFieldHeader dataHeader;
194145
};
195146

196-
////////////////////////////////////////////////////////////////////////////////
197-
// Disconnect Keep Alive Command Packet
198-
////////////////////////////////////////////////////////////////////////////////
199-
200-
// Disconnect keep alive command packet structure
201-
// Fields: T + type, R + relay, P + playerID, D
202147
struct NetPacketDisconnectKeepAliveCommand {
203148
NetPacketCommandTypeField commandType;
204149
NetPacketRelayField relay;
205150
NetPacketPlayerIdField playerId;
206151
NetPacketDataFieldHeader dataHeader;
207152
};
208153

209-
////////////////////////////////////////////////////////////////////////////////
210-
// Disconnect Player Command Packet
211-
////////////////////////////////////////////////////////////////////////////////
212-
213-
// Disconnect player command packet structure
214-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + slot + disconnectFrame
215154
struct NetPacketDisconnectPlayerCommand {
216155
NetPacketCommandTypeField commandType;
217156
NetPacketRelayField relay;
@@ -222,34 +161,20 @@ struct NetPacketDisconnectPlayerCommand {
222161
UnsignedInt disconnectFrame;
223162
};
224163

225-
////////////////////////////////////////////////////////////////////////////////
226-
// Packet Router Command Packets
227-
////////////////////////////////////////////////////////////////////////////////
228-
229-
// Packet router query command packet
230-
// Fields: T + type, R + relay, P + playerID, D
231164
struct NetPacketRouterQueryCommand {
232165
NetPacketCommandTypeField commandType;
233166
NetPacketRelayField relay;
234167
NetPacketPlayerIdField playerId;
235168
NetPacketDataFieldHeader dataHeader;
236169
};
237170

238-
// Packet router ack command packet
239-
// Fields: T + type, R + relay, P + playerID, D
240171
struct NetPacketRouterAckCommand {
241172
NetPacketCommandTypeField commandType;
242173
NetPacketRelayField relay;
243174
NetPacketPlayerIdField playerId;
244175
NetPacketDataFieldHeader dataHeader;
245176
};
246177

247-
////////////////////////////////////////////////////////////////////////////////
248-
// Disconnect Vote Command Packet
249-
////////////////////////////////////////////////////////////////////////////////
250-
251-
// Disconnect vote command
252-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + slot + voteFrame
253178
struct NetPacketDisconnectVoteCommand {
254179
NetPacketCommandTypeField commandType;
255180
NetPacketRelayField relay;
@@ -260,52 +185,6 @@ struct NetPacketDisconnectVoteCommand {
260185
UnsignedInt voteFrame;
261186
};
262187

263-
////////////////////////////////////////////////////////////////////////////////
264-
// Packed Structs for getPackedByteCount() calculations
265-
// These structs represent the fixed portion of variable-length command messages
266-
////////////////////////////////////////////////////////////////////////////////
267-
268-
// Chat command packed struct
269-
// Fixed fields: T + type, F + frame, R + relay, P + playerID, C + commandID, D
270-
struct NetPacketChatCommand {
271-
NetPacketCommandTypeField commandType;
272-
NetPacketFrameField frame;
273-
NetPacketRelayField relay;
274-
NetPacketPlayerIdField playerId;
275-
NetPacketCommandIdField commandId;
276-
NetPacketDataFieldHeader dataHeader;
277-
// Variable fields: UnsignedByte textLength + UnsignedShort text[textLength] + Int playerMask
278-
};
279-
280-
// Disconnect chat command packed struct
281-
// Fixed fields: T + type, R + relay, P + playerID, D
282-
struct NetPacketDisconnectChatCommand {
283-
NetPacketCommandTypeField commandType;
284-
NetPacketRelayField relay;
285-
NetPacketPlayerIdField playerId;
286-
NetPacketDataFieldHeader dataHeader;
287-
// Variable fields: UnsignedByte textLength + UnsignedShort text[textLength]
288-
};
289-
290-
// Game command packed struct
291-
// Fixed fields: T + type, F + frame, R + relay, P + playerID, C + commandID, D
292-
struct NetPacketGameCommand {
293-
NetPacketCommandTypeField commandType;
294-
NetPacketFrameField frame;
295-
NetPacketRelayField relay;
296-
NetPacketPlayerIdField playerId;
297-
NetPacketCommandIdField commandId;
298-
NetPacketDataFieldHeader dataHeader;
299-
// Variable fields: game message arguments
300-
};
301-
302-
////////////////////////////////////////////////////////////////////////////////
303-
// Variable-Length Packet Headers for FillBufferWithXXX serialization
304-
// These structs include the textLength field for direct buffer overlay
305-
////////////////////////////////////////////////////////////////////////////////
306-
307-
// Chat command header (includes textLength for serialization)
308-
// Fixed fields: T + type, F + frame, R + relay, P + playerID, C + commandID, D + textLength
309188
struct NetPacketChatCommandHeader {
310189
NetPacketCommandTypeField commandType;
311190
NetPacketFrameField frame;
@@ -317,8 +196,6 @@ struct NetPacketChatCommandHeader {
317196
// Variable fields: WideChar text[textLength] + Int playerMask
318197
};
319198

320-
// Disconnect chat command header (includes textLength for serialization)
321-
// Fixed fields: T + type, R + relay, P + playerID, D + textLength
322199
struct NetPacketDisconnectChatCommandHeader {
323200
NetPacketCommandTypeField commandType;
324201
NetPacketRelayField relay;
@@ -328,8 +205,6 @@ struct NetPacketDisconnectChatCommandHeader {
328205
// Variable fields: WideChar text[textLength]
329206
};
330207

331-
// Game command header (for serialization)
332-
// Fixed fields: T + type, F + frame, R + relay, P + playerID, C + commandID, D
333208
struct NetPacketGameCommandHeader {
334209
NetPacketCommandTypeField commandType;
335210
NetPacketFrameField frame;
@@ -340,8 +215,6 @@ struct NetPacketGameCommandHeader {
340215
// Variable fields: GameMessage type + argument types + argument data
341216
};
342217

343-
// Wrapper command packet (fixed size - contains metadata about wrapped command)
344-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + metadata
345218
struct NetPacketWrapperCommand {
346219
NetPacketCommandTypeField commandType;
347220
NetPacketRelayField relay;
@@ -356,8 +229,6 @@ struct NetPacketWrapperCommand {
356229
UnsignedInt dataOffset;
357230
};
358231

359-
// File command packed struct
360-
// Fixed fields: T + type, R + relay, P + playerID, C + commandID, D
361232
struct NetPacketFileCommand {
362233
NetPacketCommandTypeField commandType;
363234
NetPacketRelayField relay;
@@ -367,8 +238,6 @@ struct NetPacketFileCommand {
367238
// Variable fields: null-terminated filename + UnsignedInt fileDataLength + file data
368239
};
369240

370-
// File announce command packed struct
371-
// Fixed fields: T + type, R + relay, P + playerID, C + commandID, D
372241
struct NetPacketFileAnnounceCommand {
373242
NetPacketCommandTypeField commandType;
374243
NetPacketRelayField relay;
@@ -378,8 +247,6 @@ struct NetPacketFileAnnounceCommand {
378247
// Variable fields: null-terminated filename + UnsignedShort fileID + UnsignedByte playerMask
379248
};
380249

381-
// File progress command packet
382-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + fileID + progress
383250
struct NetPacketFileProgressCommand {
384251
NetPacketCommandTypeField commandType;
385252
NetPacketRelayField relay;
@@ -390,8 +257,6 @@ struct NetPacketFileProgressCommand {
390257
Int progress;
391258
};
392259

393-
// Progress message packet
394-
// Fields: T + type, R + relay, P + playerID, D + percentage
395260
struct NetPacketProgressMessage {
396261
NetPacketCommandTypeField commandType;
397262
NetPacketRelayField relay;
@@ -400,8 +265,6 @@ struct NetPacketProgressMessage {
400265
UnsignedByte percentage;
401266
};
402267

403-
// Load complete message packet
404-
// Fields: T + type, R + relay, P + playerID, C + commandID, D
405268
struct NetPacketLoadCompleteMessage {
406269
NetPacketCommandTypeField commandType;
407270
NetPacketRelayField relay;
@@ -410,8 +273,6 @@ struct NetPacketLoadCompleteMessage {
410273
NetPacketDataFieldHeader dataHeader;
411274
};
412275

413-
// Timeout game start message packet
414-
// Fields: T + type, R + relay, P + playerID, C + commandID, D
415276
struct NetPacketTimeOutGameStartMessage {
416277
NetPacketCommandTypeField commandType;
417278
NetPacketRelayField relay;
@@ -420,8 +281,6 @@ struct NetPacketTimeOutGameStartMessage {
420281
NetPacketDataFieldHeader dataHeader;
421282
};
422283

423-
// Disconnect frame command packet
424-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + disconnectFrame
425284
struct NetPacketDisconnectFrameCommand {
426285
NetPacketCommandTypeField commandType;
427286
NetPacketRelayField relay;
@@ -431,8 +290,6 @@ struct NetPacketDisconnectFrameCommand {
431290
UnsignedInt disconnectFrame;
432291
};
433292

434-
// Disconnect screen off command packet
435-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + newFrame
436293
struct NetPacketDisconnectScreenOffCommand {
437294
NetPacketCommandTypeField commandType;
438295
NetPacketRelayField relay;
@@ -442,8 +299,6 @@ struct NetPacketDisconnectScreenOffCommand {
442299
UnsignedInt newFrame;
443300
};
444301

445-
// Frame resend request command packet
446-
// Fields: T + type, R + relay, P + playerID, C + commandID, D + frameToResend
447302
struct NetPacketFrameResendRequestCommand {
448303
NetPacketCommandTypeField commandType;
449304
NetPacketRelayField relay;

0 commit comments

Comments
 (0)