refactor(netpacket): Simplify NetPacket functions for packet buffer writes and size tests#2329
refactor(netpacket): Simplify NetPacket functions for packet buffer writes and size tests#2329xezon wants to merge 5 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/GameNetwork/NetPacketStructs.h | New header file introducing templated packet structure system with helper functions for network serialization. Well-organized with packed structs for network compatibility. |
| Core/GameEngine/Source/GameNetwork/NetPacketStructs.cpp | New implementation file providing copyBytes functions for all network command types. Systematically replaces old buffer filling code with cleaner template-based approach. |
| Core/GameEngine/Source/GameNetwork/NetPacket.cpp | Removed ~600 lines of repetitive FillBufferWithXXX functions, replaced with single virtual function call. Field ordering in ConstructNetCommandMsgFromRawData fixed to match packet structure. |
| Core/GameEngine/Include/GameNetwork/NetCommandMsg.h | Replaced getPackedByteCount with getSizeForNetPacket/getSizeForSmallNetPacket and copyBytesForNetPacket/copyBytesForSmallNetPacket virtual functions. Introduced NetCommandMsgT template base class for consistency. |
| Core/GameEngine/Source/GameNetwork/NetCommandMsg.cpp | Removed getPackedByteCount implementations, replaced with getSmallNetPacketSelect. Consolidated duplicated code in Ack command classes by introducing NetAckCommandMsg base class. |
Class Diagram
%%{init: {'theme': 'neutral'}}%%
classDiagram
class NetCommandMsg {
<<abstract>>
+getSizeForNetPacket()
+copyBytesForNetPacket()
+getSizeForSmallNetPacket()
+copyBytesForSmallNetPacket()
+getSmallNetPacketSelect()
}
class NetCommandMsgT~NetPacketType, SmallNetPacketType~ {
+getSizeForNetPacket()
+copyBytesForNetPacket()
+getSizeForSmallNetPacket()
+copyBytesForSmallNetPacket()
}
class NetGameCommandMsg {
+constructGameMessage()
+getSmallNetPacketSelect()
}
class NetAckCommandMsg {
+getCommandID()
+getOriginalPlayerID()
+getSmallNetPacketSelect()
}
class NetAckBothCommandMsg
class NetAckStage1CommandMsg
class NetAckStage2CommandMsg
class NetPacketCommandTemplate~Base, Data~ {
+getSize()
+copyBytes()
}
class SmallNetPacketCommandTemplate~Base, Data~ {
+getSize()
+copyBytes()
}
class NetPacketGameCommand
class SmallNetPacketGameCommand
NetCommandMsg <|-- NetCommandMsgT
NetCommandMsgT <|-- NetGameCommandMsg
NetCommandMsgT <|-- NetAckCommandMsg
NetAckCommandMsg <|-- NetAckBothCommandMsg
NetAckCommandMsg <|-- NetAckStage1CommandMsg
NetAckCommandMsg <|-- NetAckStage2CommandMsg
NetPacketCommandTemplate ..> NetGameCommandMsg : uses
SmallNetPacketCommandTemplate ..> NetGameCommandMsg : uses
NetPacketGameCommand --|> NetPacketCommandTemplate
SmallNetPacketGameCommand --|> SmallNetPacketCommandTemplate
Last reviewed commit: 86faf0d
aea8b1a to
d8f9dc1
Compare
|
Would it make sense to use macros? For some of the repeating stuff like: |
|
Preferably a template. I will think about it. |
|
Replicated to Generals. |
d8f9dc1 to
9c9ffb9
Compare
Simplified in fixup commit with template. |
|
|
||
| size_t size = 0; | ||
| size += network::writeObject(buffer, data); | ||
| size += network::writeBytes(buffer, cmdMsg->getData(), cmdMsg->getDataLength()); |
There was a problem hiding this comment.
buffer + size? That's what NetPacketFileCommandData::copyBytes does
There was a problem hiding this comment.
Indeed. This was strong bug. Fixed.
|
|
||
| size_t size = 0; | ||
| size += network::writePrimitive(buffer + size, (UnsignedByte)textLength); | ||
| size += network::writeStringWithoutNull(buffer + size, cmdMsg->getText()); |
There was a problem hiding this comment.
Would
size += network::writeBytes(buffer + size, (const UnsignedByte*)cmdMsg->getText().str(), textLength * sizeof(WideChar));
be good? writeStringWithoutNull always writes the full string, and we truncate to textLength - so we may record the size wrong for messages longer than 255 characters, right?
There was a problem hiding this comment.
Indeed. This was very unsafe. Fixed.
| void setNetCommandType(NetCommandType type) { m_commandType = type; } | ||
| NetCommandType getNetCommandType() { return m_commandType; } | ||
| NetCommandType getNetCommandType() const { return m_commandType; } | ||
| virtual Int getSortNumber(); |
There was a problem hiding this comment.
Indeed. This was bug, preventing virtual override in NetAckCommandMsg. Fixed.
…NetAckStage1CommandMsg, NetAckStage2CommandMsg (#2329)
…NetCommandMsg::getSizeForNetPacket (#2329)
…rites and size tests (#2329)
9c9ffb9 to
86faf0d
Compare
Merge with Rebase
This change has 5 commits with refactors/fixes to greatly simplify all Net Packet buffer writes and size tests. All original networking behavior should be correctly preserved.
The only thing left to refactor for a follow up change are the Net Packet read functions.
TODO