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 241 of file C4PacketBase.h.

Constructor & Destructor Documentation

◆ C4IDPacket() [1/3]

C4IDPacket::C4IDPacket ( )
default

◆ C4IDPacket() [2/3]

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

Definition at line 191 of file C4Packet2.cpp.

192  : eID(eID), pPkt(pPkt), fOwnPkt(fTakePkt), pNext(nullptr)
193 {
194 
195 }
C4PacketType eID
Definition: C4PacketBase.h:251
C4IDPacket * pNext
Definition: C4PacketBase.h:256
C4PacketBase * pPkt
Definition: C4PacketBase.h:252

◆ C4IDPacket() [3/3]

C4IDPacket::C4IDPacket ( const C4IDPacket Packet2)

Definition at line 197 of file C4Packet2.cpp.

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

References C4PacketBase::unpack().

Here is the call graph for this function:

◆ ~C4IDPacket()

C4IDPacket::~C4IDPacket ( )
override

Definition at line 204 of file C4Packet2.cpp.

205 {
206  Clear();
207 }
void Clear()
Definition: C4Packet2.cpp:223

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4IDPacket::Clear ( )

Definition at line 223 of file C4Packet2.cpp.

224 {
225  if (fOwnPkt) delete pPkt;
226  pPkt = nullptr;
227  eID = PID_None;
228 }
@ PID_None
Definition: C4PacketBase.h:78

References eID, fOwnPkt, PID_None, and pPkt.

Referenced by ~C4IDPacket().

Here is the caller graph for this function:

◆ CompileFunc()

void C4IDPacket::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 230 of file C4Packet2.cpp.

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

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

Here is the call graph for this function:

◆ Default()

void C4IDPacket::Default ( )

Definition at line 218 of file C4Packet2.cpp.

219 {
220  eID = PID_None; pPkt = nullptr;
221 }

References eID, PID_None, and pPkt.

Referenced by C4Playback::ExecuteControl(), and C4GameControlNetwork::HandlePacket().

Here is the caller graph for this function:

◆ getPkt()

C4PacketBase* C4IDPacket::getPkt ( ) const
inline

Definition at line 260 of file C4PacketBase.h.

260 { return pPkt; }

References pPkt.

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

Here is the caller graph for this function:

◆ getPktName()

const char * C4IDPacket::getPktName ( ) const

Definition at line 209 of file C4Packet2.cpp.

210 {
211  // Use map
212  for (const C4PktHandlingData *pPData = PktHandlingData; pPData->ID != PID_None; pPData++)
213  if (pPData->ID == eID && pPData->Name)
214  return pPData->Name;
215  return "Unknown Packet Type";
216 }

References eID, C4PktHandlingData::ID, PID_None, and PktHandlingData.

Referenced by CompileFunc().

Here is the caller graph for this function:

◆ getPktType()

C4PacketType C4IDPacket::getPktType ( ) const
inline

Definition at line 259 of file C4PacketBase.h.

259 { return eID; }

References eID.

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

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:

◆ 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.

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(), and C4Network2IO::HandlePacket().

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 243 of file C4PacketBase.h.

Member Data Documentation

◆ eID

C4PacketType C4IDPacket::eID {PID_None}
protected

Definition at line 251 of file C4PacketBase.h.

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

◆ fOwnPkt

bool C4IDPacket::fOwnPkt {true}
protected

Definition at line 253 of file C4PacketBase.h.

Referenced by Clear(), and CompileFunc().

◆ pNext

◆ pPkt

C4PacketBase* C4IDPacket::pPkt {nullptr}
protected

Definition at line 252 of file C4PacketBase.h.

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


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