OpenClonk
C4PacketPostMortem Class Reference

#include <C4Network2IO.h>

Inheritance diagram for C4PacketPostMortem:
[legend]
Collaboration diagram for C4PacketPostMortem:
[legend]

Public Member Functions

 C4PacketPostMortem ()
 
 ~C4PacketPostMortem () override
 
uint32_t getConnID () const
 
uint32_t getPacketCount () const
 
void SetConnID (uint32_t inConnID)
 
const C4NetIOPacketgetPacket (uint32_t iNumber) const
 
void SetPacketCounter (uint32_t iPacketCounter)
 
void Add (const C4NetIOPacket &rPkt)
 
void CompileFunc (StdCompiler *pComp) override
 
C4NetIOPacket pack (const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
C4NetIOPacket pack (uint8_t cStatus, const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
void unpack (const C4NetIOPacket &Pkt, char *pStatus=nullptr)
 

Detailed Description

Definition at line 417 of file C4Network2IO.h.

Constructor & Destructor Documentation

◆ C4PacketPostMortem()

C4PacketPostMortem::C4PacketPostMortem ( )

Definition at line 1552 of file C4Network2IO.cpp.

1553  : iConnID(~0),
1554  iPacketCounter(~0)
1555 {
1556 
1557 }

◆ ~C4PacketPostMortem()

C4PacketPostMortem::~C4PacketPostMortem ( )
override

Definition at line 1559 of file C4Network2IO.cpp.

1560 {
1561  while (pPackets)
1562  {
1563  PacketLink *pDelete = pPackets;
1564  pPackets = pPackets->Next;
1565  delete pDelete;
1566  }
1567  iPacketCount = 0;
1568 }

Member Function Documentation

◆ Add()

void C4PacketPostMortem::Add ( const C4NetIOPacket rPkt)

Definition at line 1590 of file C4Network2IO.cpp.

1591 {
1592  // Add to head of list (reverse order)
1593  PacketLink *pLink = new PacketLink();
1594  pLink->Pkt = rPkt;
1595  pLink->Next = pPackets;
1596  pPackets = pLink;
1597  iPacketCount++;
1598 }

Referenced by C4Network2IOConnection::CreatePostMortem().

Here is the caller graph for this function:

◆ CompileFunc()

void C4PacketPostMortem::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 1600 of file C4Network2IO.cpp.

1601 {
1602  bool deserializing = pComp->isDeserializer();
1603 
1604  // Connection ID, packet number and packet count
1605  pComp->Value(mkNamingAdapt(iConnID, "ConnID"));
1606  pComp->Value(mkNamingAdapt(iPacketCounter, "PacketCounter"));
1607  pComp->Value(mkNamingAdapt(iPacketCount, "PacketCount"));
1608 
1609  // Packets
1610  if (deserializing)
1611  {
1612  // Read packets
1613  for (uint32_t i = 0; i < iPacketCount; i++)
1614  {
1615  // Create list entry
1616  PacketLink *pLink = new PacketLink();
1617  pLink->Next = pPackets;
1618  pPackets = pLink;
1619  // Compile data
1620  pComp->Value(mkNamingAdapt(pLink->Pkt, "PacketData"));
1621  }
1622  // Reverse order
1623  PacketLink *pPackets2 = pPackets;
1624  pPackets = nullptr;
1625  while (pPackets2)
1626  {
1627  // Get link
1628  PacketLink *pLink = pPackets2;
1629  pPackets2 = pLink->Next;
1630  // Readd to list
1631  pLink->Next = pPackets;
1632  pPackets = pLink;
1633  }
1634  }
1635  else
1636  {
1637  // Write packets
1638  for (PacketLink *pLink = pPackets; pLink; pLink = pLink->Next)
1639  pComp->Value(mkNamingAdapt(pLink->Pkt, "PacketData"));
1640  }
1641 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References StdCompiler::isDeserializer(), mkNamingAdapt(), and StdCompiler::Value().

Here is the call graph for this function:

◆ getConnID()

uint32_t C4PacketPostMortem::getConnID ( ) const
inline

Definition at line 435 of file C4Network2IO.h.

435 { return iConnID; }

◆ getPacket()

const C4NetIOPacket * C4PacketPostMortem::getPacket ( uint32_t  iNumber) const

Definition at line 1570 of file C4Network2IO.cpp.

1571 {
1572  // Security
1573  if (!Inside(iNumber, iPacketCounter - iPacketCount, iPacketCounter - 1))
1574  return nullptr;
1575  // Calculate position in list
1576  iNumber = iNumber + iPacketCount - iPacketCounter;
1577  // Search for the packet with the given number
1578  PacketLink *pLink = pPackets;
1579  for (; pLink && iNumber; iNumber--)
1580  pLink = pLink->Next;
1581  // Not found?
1582  return pLink ? &pLink->Pkt : nullptr;
1583 }
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

References Inside().

Here is the call graph for this function:

◆ getPacketCount()

uint32_t C4PacketPostMortem::getPacketCount ( ) const
inline

Definition at line 436 of file C4Network2IO.h.

436 { return iPacketCount; }

Referenced by C4Network2::OnDisconn().

Here is the caller graph for this function:

◆ pack() [1/2]

C4NetIOPacket C4PacketBase::pack ( const C4NetIO::addr_t addr = C4NetIO::addr_t()) const
inherited

Definition at line 150 of file C4Packet2.cpp.

151 {
152  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
153 }

Referenced by MkC4NetIOPacket().

Here is the caller graph for this function:

◆ pack() [2/2]

C4NetIOPacket C4PacketBase::pack ( uint8_t  cStatus,
const C4NetIO::addr_t addr = C4NetIO::addr_t() 
) const
inherited

Definition at line 155 of file C4Packet2.cpp.

156 {
157  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
158 }
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:469
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:153

References mkDecompileAdapt(), and mkInsertAdapt().

Here is the call graph for this function:

◆ SetConnID()

void C4PacketPostMortem::SetConnID ( uint32_t  inConnID)
inline

Definition at line 437 of file C4Network2IO.h.

437 { iConnID = inConnID; }

Referenced by C4Network2IOConnection::CreatePostMortem().

Here is the caller graph for this function:

◆ SetPacketCounter()

void C4PacketPostMortem::SetPacketCounter ( uint32_t  iPacketCounter)

Definition at line 1585 of file C4Network2IO.cpp.

1586 {
1587  iPacketCounter = inPacketCounter;
1588 }

Referenced by C4Network2IOConnection::CreatePostMortem().

Here is the caller graph for this function:

◆ unpack()

void C4PacketBase::unpack ( const C4NetIOPacket Pkt,
char *  pStatus = nullptr 
)
inherited

Definition at line 160 of file C4Packet2.cpp.

161 {
162  if (pStatus) *pStatus = Pkt.getStatus();
163  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
164 }
uint8_t getStatus() const
Definition: C4NetIO.h:319
StdBuf getPBuf() const
Definition: C4NetIO.h:322
C4NetIOPacket getRef() const
Definition: C4NetIO.h:325

References C4NetIOPacket::getPBuf(), C4NetIOPacket::getRef(), and C4NetIOPacket::getStatus().

Referenced by C4IDPacket::C4IDPacket(), and C4Network2IO::HandlePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: