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 1551 of file C4Network2IO.cpp.

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

◆ ~C4PacketPostMortem()

C4PacketPostMortem::~C4PacketPostMortem ( )
override

Definition at line 1558 of file C4Network2IO.cpp.

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

Member Function Documentation

◆ Add()

void C4PacketPostMortem::Add ( const C4NetIOPacket rPkt)

Definition at line 1589 of file C4Network2IO.cpp.

Referenced by C4Network2IOConnection::CreatePostMortem().

1590 {
1591  // Add to head of list (reverse order)
1592  PacketLink *pLink = new PacketLink();
1593  pLink->Pkt = rPkt;
1594  pLink->Next = pPackets;
1595  pPackets = pLink;
1596  iPacketCount++;
1597 }
Here is the caller graph for this function:

◆ CompileFunc()

void C4PacketPostMortem::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 1599 of file C4Network2IO.cpp.

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

1600 {
1601  bool deserializing = pComp->isDeserializer();
1602 
1603  // Connection ID, packet number and packet count
1604  pComp->Value(mkNamingAdapt(iConnID, "ConnID"));
1605  pComp->Value(mkNamingAdapt(iPacketCounter, "PacketCounter"));
1606  pComp->Value(mkNamingAdapt(iPacketCount, "PacketCount"));
1607 
1608  // Packets
1609  if (deserializing)
1610  {
1611  // Read packets
1612  for (uint32_t i = 0; i < iPacketCount; i++)
1613  {
1614  // Create list entry
1615  PacketLink *pLink = new PacketLink();
1616  pLink->Next = pPackets;
1617  pPackets = pLink;
1618  // Compile data
1619  pComp->Value(mkNamingAdapt(pLink->Pkt, "PacketData"));
1620  }
1621  // Reverse order
1622  PacketLink *pPackets2 = pPackets;
1623  pPackets = nullptr;
1624  while (pPackets2)
1625  {
1626  // Get link
1627  PacketLink *pLink = pPackets2;
1628  pPackets2 = pLink->Next;
1629  // Readd to list
1630  pLink->Next = pPackets;
1631  pPackets = pLink;
1632  }
1633  }
1634  else
1635  {
1636  // Write packets
1637  for (PacketLink *pLink = pPackets; pLink; pLink = pLink->Next)
1638  pComp->Value(mkNamingAdapt(pLink->Pkt, "PacketData"));
1639  }
1640 }
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
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 1569 of file C4Network2IO.cpp.

References Inside().

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

◆ getPacketCount()

uint32_t C4PacketPostMortem::getPacketCount ( ) const
inline

Definition at line 436 of file C4Network2IO.h.

Referenced by C4Network2::OnDisconn().

436 { return iPacketCount; }
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.

Referenced by MkC4NetIOPacket().

151 {
152  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
153 }
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.

References mkDecompileAdapt(), and mkInsertAdapt().

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

◆ SetConnID()

void C4PacketPostMortem::SetConnID ( uint32_t  inConnID)
inline

Definition at line 437 of file C4Network2IO.h.

References CompileFunc().

Referenced by C4Network2IOConnection::CreatePostMortem().

437 { iConnID = inConnID; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPacketCounter()

void C4PacketPostMortem::SetPacketCounter ( uint32_t  iPacketCounter)

Definition at line 1584 of file C4Network2IO.cpp.

Referenced by C4Network2IOConnection::CreatePostMortem().

1585 {
1586  iPacketCounter = inPacketCounter;
1587 }
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.

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

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

161 {
162  if (pStatus) *pStatus = Pkt.getStatus();
163  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
164 }
uint8_t getStatus() const
Definition: C4NetIO.h:318
StdBuf getPBuf() const
Definition: C4NetIO.h:321
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
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: