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 () 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 236 of file C4PacketBase.h.

Constructor & Destructor Documentation

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

Definition at line 189 of file C4Packet2.cpp.

190  : eID(eID), pPkt(pPkt), fOwnPkt(fTakePkt), pNext(nullptr)
191 {
192 
193 }
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 195 of file C4Packet2.cpp.

References C4PacketBase::unpack().

196  : C4PacketBase(Packet2)
197 {
198  // kinda hacky (note this might throw an uncaught exception)
199  C4PacketBase::unpack(Packet2.C4PacketBase::pack());
200 }
void unpack(const C4NetIOPacket &Pkt, char *pStatus=nullptr)
Definition: C4Packet2.cpp:159

Here is the call graph for this function:

C4IDPacket::~C4IDPacket ( )
override

Definition at line 202 of file C4Packet2.cpp.

References Clear().

203 {
204  Clear();
205 }
void Clear()
Definition: C4Packet2.cpp:221

Here is the call graph for this function:

Member Function Documentation

void C4IDPacket::Clear ( )

Definition at line 221 of file C4Packet2.cpp.

References eID, fOwnPkt, PID_None, and pPkt.

Referenced by ~C4IDPacket().

222 {
223  if (fOwnPkt) delete pPkt; pPkt = nullptr;
224  eID = PID_None;
225 }
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)
overridevirtual

Implements C4PacketBase.

Definition at line 227 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().

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

Here is the call graph for this function:

void C4IDPacket::Default ( )

Definition at line 216 of file C4Packet2.cpp.

References eID, PID_None, and pPkt.

Referenced by C4Playback::ExecuteControl().

217 {
218  eID = PID_None; pPkt = nullptr;
219 }
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 207 of file C4Packet2.cpp.

References eID, C4PktHandlingData::ID, and PID_None.

Referenced by CompileFunc().

208 {
209  // Use map
210  for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)
211  if (pPData->ID == eID && pPData->Name)
212  return pPData->Name;
213  return "Unknown Packet Type";
214 }
C4PacketType eID
Definition: C4PacketBase.h:246
const C4PktHandlingData PktHandlingData[]
Definition: C4Packet2.cpp:50
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 149 of file C4Packet2.cpp.

Referenced by MkC4NetIOPacket().

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

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 154 of file C4Packet2.cpp.

References mkDecompileAdapt(), and mkInsertAdapt().

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

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 159 of file C4Packet2.cpp.

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

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

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

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 {PID_None}
protected

Definition at line 246 of file C4PacketBase.h.

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

bool C4IDPacket::fOwnPkt {true}
protected

Definition at line 248 of file C4PacketBase.h.

Referenced by Clear(), and CompileFunc().

C4PacketBase* C4IDPacket::pPkt {nullptr}
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: