Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/GameEngine/Include/GameNetwork/NetCommandList.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class NetCommandList : public MemoryPoolObject
void init(); ///< Initialize the list
void reset(); ///< Reset the list to the initial state.
NetCommandRef * addMessage(NetCommandMsg *cmdMsg); ///< Add message to the list in its properly ordered place.
NetCommandRef * addMessage(NetCommandRef *&msg); ///< Add message to the list in its properly ordered place.
Bool isEqualCommandMsg(NetCommandMsg *msg1, NetCommandMsg *msg2);
NetCommandRef * getFirstMessage(); ///< Get the first message on the list.
NetCommandRef * findMessage(NetCommandMsg *msg); ///< Find and return a reference to the given message if one exists.
Expand Down
123 changes: 92 additions & 31 deletions Core/GameEngine/Include/GameNetwork/NetCommandMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,61 @@

class NetCommandRef;

//-----------------------------------------------------------------------------
class NetCommandDataChunk
{
NetCommandDataChunk(const NetCommandDataChunk&) CPP_11(= delete);
void operator=(const NetCommandDataChunk&) CPP_11(= delete);

public:
NetCommandDataChunk(Byte *data, UnsignedInt size)
: m_data(reinterpret_cast<UnsignedByte *>(data))
, m_size(size)
{}

NetCommandDataChunk(UnsignedByte *data, UnsignedInt size)
: m_data(data)
, m_size(size)
{}

NetCommandDataChunk(UnsignedInt size)
: m_data(NEW UnsignedByte[size])
, m_size(size)
{}

~NetCommandDataChunk()
{
delete[] m_data;
}

const UnsignedByte *data() const
{
return m_data;
}

UnsignedByte *data()
{
return m_data;
}

UnsignedInt size() const
{
return m_size;
}

UnsignedByte *release()
{
UnsignedByte *ret = m_data;
m_data = nullptr;
m_size = 0;
return ret;
}

private:
UnsignedByte *m_data;
UnsignedInt m_size;
};

//-----------------------------------------------------------------------------
class NetCommandMsg : public MemoryPoolObject
{
Expand All @@ -60,6 +115,7 @@ class NetCommandMsg : public MemoryPoolObject
virtual size_t getSizeForSmallNetPacket(const Select* select = nullptr) const = 0;
virtual size_t copyBytesForSmallNetPacket(UnsignedByte* buffer, const NetCommandRef& ref, const Select* select = nullptr) const = 0;
virtual Select getSmallNetPacketSelect() const = 0;
virtual size_t readMessageData(NetCommandRef& ref, NetPacketBuf buf) const = 0;
void attach();
void detach();

Expand All @@ -77,25 +133,30 @@ class NetCommandMsg : public MemoryPoolObject
template<typename NetPacketType, typename SmallNetPacketType>
class NetCommandMsgT : public NetCommandMsg
{
virtual size_t getSizeForNetPacket() const
virtual size_t getSizeForNetPacket() const override
{
return NetPacketType::getSize(*this);
}

virtual size_t copyBytesForNetPacket(UnsignedByte* buffer, const NetCommandRef& ref) const
virtual size_t copyBytesForNetPacket(UnsignedByte* buffer, const NetCommandRef& ref) const override
{
return NetPacketType::copyBytes(buffer, ref);
}

virtual size_t getSizeForSmallNetPacket(const Select* select = nullptr) const
virtual size_t getSizeForSmallNetPacket(const Select* select = nullptr) const override
{
return SmallNetPacketType::getSize(*this, select);
}

virtual size_t copyBytesForSmallNetPacket(UnsignedByte* buffer, const NetCommandRef& ref, const Select* select = nullptr) const
virtual size_t copyBytesForSmallNetPacket(UnsignedByte* buffer, const NetCommandRef& ref, const Select* select = nullptr) const override
{
return SmallNetPacketType::copyBytes(buffer, ref, select);
}

virtual size_t readMessageData(NetCommandRef& ref, NetPacketBuf buf) const override
{
return SmallNetPacketType::CommandData::readMessage(ref, buf);
}
};

//-----------------------------------------------------------------------------
Expand All @@ -114,7 +175,7 @@ class NetGameCommandMsg : public NetCommandMsgT<NetPacketGameCommand, SmallNetPa
void addArgument(const GameMessageArgumentDataType type, GameMessageArgumentType arg);
void setGameMessageType(GameMessage::Type type);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
Int m_numArgs;
Expand Down Expand Up @@ -148,7 +209,7 @@ class NetAckCommandMsg : public NetCommandMsgT<NetPacketAckCommand, SmallNetPack
void setOriginalPlayerID(UnsignedByte originalPlayerID);
virtual Int getSortNumber() const;

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedShort m_commandID;
Expand Down Expand Up @@ -208,7 +269,7 @@ class NetFrameCommandMsg : public NetCommandMsgT<NetPacketFrameCommand, SmallNet
void setCommandCount(UnsignedShort commandCount);
UnsignedShort getCommandCount() const;

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedShort m_commandCount;
Expand All @@ -225,7 +286,7 @@ class NetPlayerLeaveCommandMsg : public NetCommandMsgT<NetPacketPlayerLeaveComma
UnsignedByte getLeavingPlayerID() const;
void setLeavingPlayerID(UnsignedByte id);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedByte m_leavingPlayerID;
Expand All @@ -244,7 +305,7 @@ class NetRunAheadMetricsCommandMsg : public NetCommandMsgT<NetPacketRunAheadMetr
Int getAverageFps() const;
void setAverageFps(Int fps);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
Real m_averageLatency;
Expand All @@ -265,7 +326,7 @@ class NetRunAheadCommandMsg : public NetCommandMsgT<NetPacketRunAheadCommand, Sm
UnsignedByte getFrameRate() const;
void setFrameRate(UnsignedByte frameRate);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedShort m_runAhead;
Expand All @@ -283,7 +344,7 @@ class NetDestroyPlayerCommandMsg : public NetCommandMsgT<NetPacketDestroyPlayerC
UnsignedInt getPlayerIndex() const;
void setPlayerIndex(UnsignedInt playerIndex);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedInt m_playerIndex;
Expand All @@ -297,7 +358,7 @@ class NetKeepAliveCommandMsg : public NetCommandMsgT<NetPacketKeepAliveCommand,
NetKeepAliveCommandMsg();
//virtual ~NetKeepAliveCommandMsg();

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;
};

//-----------------------------------------------------------------------------
Expand All @@ -308,7 +369,7 @@ class NetDisconnectKeepAliveCommandMsg : public NetCommandMsgT<NetPacketDisconne
NetDisconnectKeepAliveCommandMsg();
//virtual ~NetDisconnectKeepAliveCommandMsg();

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;
};

//-----------------------------------------------------------------------------
Expand All @@ -325,7 +386,7 @@ class NetDisconnectPlayerCommandMsg : public NetCommandMsgT<NetPacketDisconnectP
UnsignedInt getDisconnectFrame() const;
void setDisconnectFrame(UnsignedInt frame);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedByte m_disconnectSlot;
Expand All @@ -340,7 +401,7 @@ class NetPacketRouterQueryCommandMsg : public NetCommandMsgT<NetPacketRouterQuer
NetPacketRouterQueryCommandMsg();
//virtual ~NetPacketRouterQueryCommandMsg();

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;
};

//-----------------------------------------------------------------------------
Expand All @@ -351,7 +412,7 @@ class NetPacketRouterAckCommandMsg : public NetCommandMsgT<NetPacketRouterAckCom
NetPacketRouterAckCommandMsg();
//virtual ~NetPacketRouterAckCommandMsg();

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;
};

//-----------------------------------------------------------------------------
Expand All @@ -365,7 +426,7 @@ class NetDisconnectChatCommandMsg : public NetCommandMsgT<NetPacketDisconnectCha
UnicodeString getText() const;
void setText(UnicodeString text);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnicodeString m_text;
Expand All @@ -385,7 +446,7 @@ class NetChatCommandMsg : public NetCommandMsgT<NetPacketChatCommand, SmallNetPa
Int getPlayerMask() const;
void setPlayerMask( Int playerMask );

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnicodeString m_text;
Expand All @@ -406,7 +467,7 @@ class NetDisconnectVoteCommandMsg : public NetCommandMsgT<NetPacketDisconnectVot
UnsignedInt getVoteFrame() const;
void setVoteFrame(UnsignedInt voteFrame);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedByte m_slot;
Expand All @@ -424,7 +485,7 @@ class NetProgressCommandMsg: public NetCommandMsgT<NetPacketProgressCommand, Sma
UnsignedByte getPercentage() const;
void setPercentage( UnsignedByte percent );

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedByte m_percent;
Expand All @@ -440,7 +501,7 @@ class NetWrapperCommandMsg : public NetCommandMsgT<NetPacketWrapperCommand, Smal

const UnsignedByte * getData() const;
UnsignedByte * getData();
void setData(UnsignedByte *data, UnsignedInt dataLength);
void setData(NetCommandDataChunk &dataChunk);

UnsignedInt getChunkNumber() const;
void setChunkNumber(UnsignedInt chunkNumber);
Expand All @@ -459,7 +520,7 @@ class NetWrapperCommandMsg : public NetCommandMsgT<NetPacketWrapperCommand, Smal
UnsignedShort getWrappedCommandID() const;
void setWrappedCommandID(UnsignedShort wrappedCommandID);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

private:
UnsignedByte *m_data;
Expand Down Expand Up @@ -490,9 +551,9 @@ class NetFileCommandMsg : public NetCommandMsgT<NetPacketFileCommand, SmallNetPa

const UnsignedByte * getFileData() const;
UnsignedByte * getFileData();
void setFileData(UnsignedByte *data, UnsignedInt dataLength);
void setFileData(NetCommandDataChunk &dataChunk);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
AsciiString m_portableFilename;
Expand Down Expand Up @@ -521,7 +582,7 @@ class NetFileAnnounceCommandMsg : public NetCommandMsgT<NetPacketFileAnnounceCom
UnsignedByte getPlayerMask() const;
void setPlayerMask(UnsignedByte playerMask);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
AsciiString m_portableFilename;
Expand All @@ -543,7 +604,7 @@ class NetFileProgressCommandMsg : public NetCommandMsgT<NetPacketFileProgressCom
Int getProgress() const;
void setProgress(Int val);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedShort m_fileID;
Expand All @@ -560,7 +621,7 @@ class NetDisconnectFrameCommandMsg : public NetCommandMsgT<NetPacketDisconnectFr
UnsignedInt getDisconnectFrame() const;
void setDisconnectFrame(UnsignedInt disconnectFrame);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedInt m_disconnectFrame;
Expand All @@ -576,7 +637,7 @@ class NetDisconnectScreenOffCommandMsg : public NetCommandMsgT<NetPacketDisconne
UnsignedInt getNewFrame() const;
void setNewFrame(UnsignedInt newFrame);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedInt m_newFrame;
Expand All @@ -592,7 +653,7 @@ class NetFrameResendRequestCommandMsg : public NetCommandMsgT<NetPacketFrameRese
UnsignedInt getFrameToResend() const;
void setFrameToResend(UnsignedInt frame);

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;

protected:
UnsignedInt m_frameToResend;
Expand All @@ -605,7 +666,7 @@ class NetLoadCompleteCommandMsg : public NetCommandMsgT<NetPacketLoadCompleteCom
NetLoadCompleteCommandMsg();
//virtual ~NetLoadCompleteCommandMsg();

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;
};

class NetTimeOutGameStartCommandMsg : public NetCommandMsgT<NetPacketTimeOutGameStartCommand, SmallNetPacketTimeOutGameStartCommand>
Expand All @@ -615,5 +676,5 @@ class NetTimeOutGameStartCommandMsg : public NetCommandMsgT<NetPacketTimeOutGame
NetTimeOutGameStartCommandMsg();
//virtual ~NetTimeOutGameStartCommandMsg();

virtual Select getSmallNetPacketSelect() const;
virtual Select getSmallNetPacketSelect() const override;
};
35 changes: 2 additions & 33 deletions Core/GameEngine/Include/GameNetwork/NetPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class NetPacket : public MemoryPoolObject

NetCommandList *getCommandList();

static NetCommandRef * ConstructNetCommandMsgFromRawData(UnsignedByte *data, UnsignedShort dataLength);
static NetCommandRef *ConstructNetCommandMsgFromRawData(const UnsignedByte *data, UnsignedInt dataLength);
static NetPacketList ConstructBigCommandPacketList(NetCommandRef *ref);

UnsignedByte *getData();
Expand All @@ -80,38 +80,7 @@ class NetPacket : public MemoryPoolObject
Bool isAckStage2Repeat(NetCommandRef *msg);
Bool isFrameRepeat(NetCommandRef *msg);

static NetCommandMsg * readGameMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readAckBothMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readAckStage1Message(UnsignedByte *data, Int &i);
static NetCommandMsg * readAckStage2Message(UnsignedByte *data, Int &i);
static NetCommandMsg * readFrameMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readPlayerLeaveMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readRunAheadMetricsMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readRunAheadMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDestroyPlayerMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readKeepAliveMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDisconnectKeepAliveMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDisconnectPlayerMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readPacketRouterQueryMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readPacketRouterAckMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDisconnectChatMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDisconnectVoteMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readChatMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readProgressMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readLoadCompleteMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readTimeOutGameStartMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readWrapperMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readFileMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readFileAnnounceMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readFileProgressMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDisconnectFrameMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readDisconnectScreenOffMessage(UnsignedByte *data, Int &i);
static NetCommandMsg * readFrameResendRequestMessage(UnsignedByte *data, Int &i);

void writeGameMessageArgumentToPacket(GameMessageArgumentDataType type, GameMessageArgumentType arg);
static void readGameMessageArgumentFromPacket(GameMessageArgumentDataType type, NetGameCommandMsg *msg, UnsignedByte *data, Int &i);

void dumpPacketToLog();
static void dumpPacketToLog(const UnsignedByte *packet, Int packetLen);

protected:
UnsignedByte m_packet[MAX_PACKET_SIZE];
Expand Down
Loading
Loading