OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 ()
 
C4PacketType getPktType () const
 
C4PacketBasegetPkt () const
 
const char * getPktName () const
 
void Clear ()
 
void Default ()
 
void Set (C4PacketType eType, C4PacketBase *pPkt)
 
virtual void CompileFunc (StdCompiler *pComp)
 
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
 
C4PacketBasepPkt
 
bool fOwnPkt
 
C4IDPacketpNext
 

Friends

class C4PacketList
 

Detailed Description

Definition at line 236 of file C4PacketBase.h.

Constructor & Destructor Documentation

C4IDPacket::C4IDPacket ( )

Definition at line 196 of file C4Packet2.cpp.

197  : eID(PID_None), pPkt(nullptr), fOwnPkt(true), pNext(nullptr)
198 {
199 
200 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4PacketType eID
Definition: C4PacketBase.h:246
C4IDPacket::C4IDPacket ( C4PacketType  eID,
C4PacketBase pPkt,
bool  fTakePkt = true 
)

Definition at line 202 of file C4Packet2.cpp.

203  : eID(eID), pPkt(pPkt), fOwnPkt(fTakePkt), pNext(nullptr)
204 {
205 
206 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4PacketType eID
Definition: C4PacketBase.h:246
C4IDPacket::C4IDPacket ( const C4IDPacket Packet2)

Definition at line 208 of file C4Packet2.cpp.

References C4PacketBase::unpack().

209  : C4PacketBase(Packet2),
210  eID(PID_None), pPkt(nullptr), fOwnPkt(true), pNext(nullptr)
211 {
212  // kinda hacky (note this might throw an uncaught exception)
213  C4PacketBase::unpack(Packet2.C4PacketBase::pack());
214 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4PacketType eID
Definition: C4PacketBase.h:246
void unpack(const C4NetIOPacket &Pkt, char *pStatus=nullptr)
Definition: C4Packet2.cpp:166

Here is the call graph for this function:

C4IDPacket::~C4IDPacket ( )

Definition at line 216 of file C4Packet2.cpp.

References Clear().

217 {
218  Clear();
219 }
void Clear()
Definition: C4Packet2.cpp:235

Here is the call graph for this function:

Member Function Documentation

void C4IDPacket::Clear ( )

Definition at line 235 of file C4Packet2.cpp.

References eID, fOwnPkt, PID_None, and pPkt.

Referenced by ~C4IDPacket().

236 {
237  if (fOwnPkt) delete pPkt; pPkt = nullptr;
238  eID = PID_None;
239 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247
C4PacketType eID
Definition: C4PacketBase.h:246

Here is the caller graph for this function:

void C4IDPacket::CompileFunc ( StdCompiler pComp)
virtual

Implements C4PacketBase.

Definition at line 241 of file C4Packet2.cpp.

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

242 {
243  // Packet ID
244  pComp->Value(mkNamingAdapt(mkIntAdaptT<uint8_t>(eID), "ID", PID_None));
245  // Compiling or Decompiling?
246  if (pComp->isDeserializer())
247  {
248  if (!pComp->Name(getPktName()))
249  { pComp->excCorrupt("C4IDPacket: Data value needed! Packet data missing!"); return; }
250  // Delete old packet
251  if (fOwnPkt) delete pPkt; pPkt = nullptr;
252  if (eID == PID_None) return;
253  // Search unpacking function
254  for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)
255  if (pPData->ID == eID && pPData->FnUnpack)
256  {
257  pPkt = pPData->FnUnpack(pComp);
258  break;
259  }
260  if (!pPkt)
261  pComp->excCorrupt("C4IDPacket: could not unpack packet id %02x!", eID);
262  pComp->NameEnd();
263  }
264  else if (eID != PID_None)
265  // Just write
266  pComp->Value(mkNamingAdapt(*pPkt, getPktName()));
267 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
C4PacketType eID
Definition: C4PacketBase.h:246
virtual bool Name(const char *szName)
Definition: StdCompiler.h:87
const C4PktHandlingData PktHandlingData[]
Definition: C4Packet2.cpp:51
C4PacketType ID
Definition: C4PacketBase.h:201
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
const char * getPktName() const
Definition: C4Packet2.cpp:221
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:88

Here is the call graph for this function:

void C4IDPacket::Default ( )

Definition at line 230 of file C4Packet2.cpp.

References eID, PID_None, and pPkt.

Referenced by C4Playback::ExecuteControl().

231 {
232  eID = PID_None; pPkt = nullptr;
233 }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247
C4PacketType eID
Definition: C4PacketBase.h:246

Here is the caller graph for this function:

C4PacketBase* C4IDPacket::getPkt ( ) const
inline

Definition at line 255 of file C4PacketBase.h.

References pPkt.

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

255 { return pPkt; }
C4PacketBase * pPkt
Definition: C4PacketBase.h:247

Here is the caller graph for this function:

const char * C4IDPacket::getPktName ( ) const

Definition at line 221 of file C4Packet2.cpp.

References eID, C4PktHandlingData::ID, and PID_None.

Referenced by CompileFunc().

222 {
223  // Use map
224  for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)
225  if (pPData->ID == eID && pPData->Name)
226  return pPData->Name;
227  return "Unknown Packet Type";
228 }
C4PacketType eID
Definition: C4PacketBase.h:246
const C4PktHandlingData PktHandlingData[]
Definition: C4Packet2.cpp:51
C4PacketType ID
Definition: C4PacketBase.h:201

Here is the caller graph for this function:

C4PacketType C4IDPacket::getPktType ( ) const
inline

Definition at line 254 of file C4PacketBase.h.

References eID.

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

254 { return eID; }
C4PacketType eID
Definition: C4PacketBase.h:246

Here is the caller graph for this function:

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

Definition at line 156 of file C4Packet2.cpp.

Referenced by MkC4NetIOPacket().

157 {
158  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
159 }

Here is the caller graph for this function:

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

Definition at line 161 of file C4Packet2.cpp.

References mkDecompileAdapt(), and mkInsertAdapt().

162 {
163  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
164 }
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:438

Here is the call graph for this function:

void C4IDPacket::Set ( C4PacketType  eType,
C4PacketBase pPkt 
)
void C4PacketBase::unpack ( const C4NetIOPacket Pkt,
char *  pStatus = nullptr 
)
inherited

Definition at line 166 of file C4Packet2.cpp.

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

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

167 {
168  if (pStatus) *pStatus = Pkt.getStatus();
169  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
170 }
StdBuf getPBuf() const
Definition: C4NetIO.h:321
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
uint8_t getStatus() const
Definition: C4NetIO.h:318

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4PacketList
friend

Definition at line 238 of file C4PacketBase.h.

Member Data Documentation

C4PacketType C4IDPacket::eID
protected

Definition at line 246 of file C4PacketBase.h.

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

bool C4IDPacket::fOwnPkt
protected

Definition at line 248 of file C4PacketBase.h.

Referenced by Clear(), and CompileFunc().

C4PacketBase* C4IDPacket::pPkt
protected

Definition at line 247 of file C4PacketBase.h.

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


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