forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathNetPacket.h
More file actions
97 lines (81 loc) · 3.21 KB
/
NetPacket.h
File metadata and controls
97 lines (81 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
/*
Ok, how this should have been done is to make each of the command types
have a bitmask telling which command message header information
each command type required. That would make finding out the size of
a particular command easier to find, without so much repetitious code.
We would still need to have a separate function for each command type
for the data, but at least that wouldn't be repeating code, that would
be specialized code.
*/
#pragma once
#include "NetworkDefs.h"
#include "GameNetwork/NetCommandList.h"
#include "Common/MessageStream.h"
#include "Common/GameMemory.h"
class NetPacket;
typedef std::list<NetPacket *> NetPacketList;
typedef std::list<NetPacket *>::iterator NetPacketListIter;
class NetPacket : public MemoryPoolObject
{
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPacket, "NetPacket")
public:
NetPacket();
NetPacket(TransportMessage *msg);
//virtual ~NetPacket();
void init();
void reset();
void setAddress(Int addr, Int port);
Bool addCommand(NetCommandRef *msg);
Int getNumCommands();
NetCommandList *getCommandList();
static NetCommandRef *ConstructNetCommandMsgFromRawData(const UnsignedByte *data, UnsignedInt dataLength);
static NetPacketList ConstructBigCommandPacketList(NetCommandRef *ref);
UnsignedByte *getData();
Int getLength();
UnsignedInt getAddr();
UnsignedShort getPort();
// This function returns the size of the command without any compression, repetition, etc.
// i.e. All of the required fields are taken into account when returning the size.
static UnsignedInt GetBufferSizeNeededForCommand(NetCommandMsg *msg);
protected:
Bool isAckRepeat(NetCommandRef *msg);
Bool isAckBothRepeat(NetCommandRef *msg);
Bool isAckStage1Repeat(NetCommandRef *msg);
Bool isAckStage2Repeat(NetCommandRef *msg);
Bool isFrameRepeat(NetCommandRef *msg);
static void dumpPacketToLog(const UnsignedByte *packet, Int packetLen);
protected:
UnsignedByte m_packet[MAX_PACKET_SIZE];
Int m_packetLen;
UnsignedInt m_addr;
Int m_numCommands;
NetCommandRef* m_lastCommand;
UnsignedInt m_lastFrame;
UnsignedShort m_port;
UnsignedShort m_lastCommandID;
UnsignedByte m_lastPlayerID;
UnsignedByte m_lastCommandType;
UnsignedByte m_lastRelay;
};