OpenClonk
C4IDPacket Class Reference

#include <C4PacketBase.h>

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

Public Member Functions

 C4IDPacket ()
 
 C4IDPacket (C4PacketType eID, C4PacketBase *pPkt, bool fTakePkt=true)
 
 C4IDPacket (const C4IDPacket &Packet2)
 
 ~C4IDPacket () override
 
C4PacketType getPktType () const
 
C4PacketBasegetPkt () const
 
const char * getPktName () const
 
void Clear ()
 
void Default ()
 
void Set (C4PacketType eType, C4PacketBase *pPkt)
 
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)
 

Protected Attributes

C4PacketType eID {PID_None}
 
C4PacketBasepPkt {nullptr}
 
bool fOwnPkt {true}
 
C4IDPacketpNext {nullptr}
 

Friends

class C4PacketList
 

Detailed Description

Definition at line 239 of file C4PacketBase.h.

Constructor & Destructor Documentation

◆ C4IDPacket() [1/3]

C4IDPacket::C4IDPacket ( )
default

Referenced by C4PktBuf::CompileFunc().

Here is the caller graph for this function:

◆ C4IDPacket() [2/3]

C4IDPacket::C4IDPacket ( C4PacketType  eID,
C4PacketBase pPkt,
bool  fTakePkt = true 
)

Definition at line 190 of file C4Packet2.cpp.

191  : eID(eID), pPkt(pPkt), fOwnPkt(fTakePkt), pNext(nullptr)
192 {
193 
194 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:250
C4IDPacket * pNext
Definition: C4PacketBase.h:254
C4PacketType eID
Definition: C4PacketBase.h:249

◆ C4IDPacket() [3/3]

C4IDPacket::C4IDPacket ( const C4IDPacket Packet2)

Definition at line 196 of file C4Packet2.cpp.

References C4PacketBase::unpack().

197  : C4PacketBase(Packet2)
198 {
199  // kinda hacky (note this might throw an uncaught exception)
200  C4PacketBase::unpack(Packet2.C4PacketBase::pack());
201 }
void unpack(const C4NetIOPacket &Pkt, char *pStatus=nullptr)
Definition: C4Packet2.cpp:160
Here is the call graph for this function:

◆ ~C4IDPacket()

C4IDPacket::~C4IDPacket ( )
override

Definition at line 203 of file C4Packet2.cpp.

References Clear().

204 {
205  Clear();
206 }
void Clear()
Definition: C4Packet2.cpp:222
Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4IDPacket::Clear ( )

Definition at line 222 of file C4Packet2.cpp.

References eID, fOwnPkt, PID_None, and pPkt.

Referenced by ~C4IDPacket().

223 {
224  if (fOwnPkt) delete pPkt; pPkt = nullptr;
225  eID = PID_None;
226 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:250
C4PacketType eID
Definition: C4PacketBase.h:249
Here is the caller graph for this function:

◆ CompileFunc()

void C4IDPacket::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 228 of file C4Packet2.cpp.

References C4PacketList::C4PacketList(), eID, StdCompiler::excCorrupt(), fOwnPkt, getPktName(), C4PktHandlingData::ID, StdCompiler::isDeserializer(), mkNamingAdapt(), StdCompiler::Name(), StdCompiler::NameEnd(), PID_None, pPkt, and StdCompiler::Value().

229 {
230  // Packet ID
231  pComp->Value(mkNamingAdapt(mkIntAdaptT<uint8_t>(eID), "ID", PID_None));
232  // Compiling or Decompiling?
233  if (pComp->isDeserializer())
234  {
235  if (!pComp->Name(getPktName()))
236  { pComp->excCorrupt("C4IDPacket: Data value needed! Packet data missing!"); return; }
237  // Delete old packet
238  if (fOwnPkt) delete pPkt; pPkt = nullptr;
239  if (eID == PID_None) return;
240  // Search unpacking function
241  for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)
242  if (pPData->ID == eID && pPData->FnUnpack)
243  {
244  pPkt = pPData->FnUnpack(pComp);
245  break;
246  }
247  if (!pPkt)
248  pComp->excCorrupt("C4IDPacket: could not unpack packet id %02x!", eID);
249  pComp->NameEnd();
250  }
251  else if (eID != PID_None)
252  // Just write
253  pComp->Value(mkNamingAdapt(*pPkt, getPktName()));
254 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:250
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
C4PacketType eID
Definition: C4PacketBase.h:249
virtual bool Name(const char *szName)
Definition: StdCompiler.h:77
const C4PktHandlingData PktHandlingData[]
Definition: C4Packet2.cpp:50
C4PacketType ID
Definition: C4PacketBase.h:204
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
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:78
const char * getPktName() const
Definition: C4Packet2.cpp:208
Here is the call graph for this function:

◆ Default()

void C4IDPacket::Default ( )

Definition at line 217 of file C4Packet2.cpp.

References eID, PID_None, and pPkt.

Referenced by C4Playback::ExecuteControl().

218 {
219  eID = PID_None; pPkt = nullptr;
220 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:250
C4PacketType eID
Definition: C4PacketBase.h:249
Here is the caller graph for this function:

◆ getPkt()

C4PacketBase* C4IDPacket::getPkt ( ) const
inline

Definition at line 258 of file C4PacketBase.h.

References C4PacketList::Clear(), and C4PacketBase::CompileFunc().

Referenced by C4Network2IO::CallHandlers(), C4Playback::Check(), C4PacketList::CompileFunc(), C4Network2::EndVote(), C4Network2::Execute(), C4Playback::ExecuteControl(), C4ControlVote::getDescWarning(), and C4Record::Rec().

258 { return pPkt; }
C4PacketBase * pPkt
Definition: C4PacketBase.h:250
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPktName()

const char * C4IDPacket::getPktName ( ) const

Definition at line 208 of file C4Packet2.cpp.

References eID, C4PktHandlingData::ID, and PID_None.

Referenced by CompileFunc().

209 {
210  // Use map
211  for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)
212  if (pPData->ID == eID && pPData->Name)
213  return pPData->Name;
214  return "Unknown Packet Type";
215 }
C4PacketType eID
Definition: C4PacketBase.h:249
const C4PktHandlingData PktHandlingData[]
Definition: C4Packet2.cpp:50
C4PacketType ID
Definition: C4PacketBase.h:204
Here is the caller graph for this function:

◆ getPktType()

C4PacketType C4IDPacket::getPktType ( ) const
inline

Definition at line 257 of file C4PacketBase.h.

Referenced by C4Network2IO::CallHandlers(), C4Playback::Check(), C4Playback::ExecuteControl(), and C4Network2IO::HandlePacket().

257 { return eID; }
C4PacketType eID
Definition: C4PacketBase.h:249
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:

◆ Set()

void C4IDPacket::Set ( C4PacketType  eType,
C4PacketBase pPkt 
)

◆ 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(), 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:

Friends And Related Function Documentation

◆ C4PacketList

friend class C4PacketList
friend

Definition at line 241 of file C4PacketBase.h.

Member Data Documentation

◆ eID

C4PacketType C4IDPacket::eID {PID_None}
protected

Definition at line 249 of file C4PacketBase.h.

Referenced by Clear(), CompileFunc(), Default(), and getPktName().

◆ fOwnPkt

bool C4IDPacket::fOwnPkt {true}
protected

Definition at line 251 of file C4PacketBase.h.

Referenced by Clear(), and CompileFunc().

◆ pNext

◆ pPkt

C4PacketBase* C4IDPacket::pPkt {nullptr}
protected

Definition at line 250 of file C4PacketBase.h.

Referenced by Clear(), CompileFunc(), and Default().


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