OpenClonk
C4NetpuncherPacketID< TYPE > Class Template Reference

#include <C4PuncherPacket.h>

Inheritance diagram for C4NetpuncherPacketID< TYPE >:
[legend]
Collaboration diagram for C4NetpuncherPacketID< TYPE >:
[legend]

Public Types

typedef std::unique_ptr< C4NetpuncherPacketuptr
 

Public Member Functions

C4NetpuncherPacketType GetType () const final
 
CID GetID () const
 
 ~C4NetpuncherPacketID () override=default
 
C4NetIOPacket PackTo (const C4NetIO::addr_t &) const
 

Static Public Member Functions

static std::unique_ptr< C4NetpuncherPacketConstruct (const C4NetIOPacket &rpack)
 

Protected Types

typedef C4NetpuncherID::value CID
 

Protected Member Functions

 C4NetpuncherPacketID (const C4NetIOPacket &rpack)
 
 C4NetpuncherPacketID (CID id)
 

Detailed Description

template<C4NetpuncherPacketType TYPE>
class C4NetpuncherPacketID< TYPE >

Definition at line 62 of file C4PuncherPacket.h.

Member Typedef Documentation

◆ CID

typedef C4NetpuncherID::value C4NetpuncherPacket::CID
protectedinherited

Definition at line 49 of file C4PuncherPacket.h.

◆ uptr

typedef std::unique_ptr<C4NetpuncherPacket> C4NetpuncherPacket::uptr
inherited

Definition at line 42 of file C4PuncherPacket.h.

Constructor & Destructor Documentation

◆ C4NetpuncherPacketID() [1/2]

template<C4NetpuncherPacketType TYPE>
C4NetpuncherPacketID< TYPE >::C4NetpuncherPacketID ( const C4NetIOPacket rpack)
protected

Definition at line 81 of file C4PuncherPacket.cpp.

81  {
82  if (rpack.getPSize() < HeaderPSize + sizeof(id)) throw "invalid size";
83  id = *getBufPtr<CID>(rpack, HeaderSize);
84 }
size_t getPSize() const
Definition: C4NetIO.h:321

References C4NetIOPacket::getPSize().

Here is the call graph for this function:

◆ C4NetpuncherPacketID() [2/2]

template<C4NetpuncherPacketType TYPE>
C4NetpuncherPacketID< TYPE >::C4NetpuncherPacketID ( CID  id)
inlineprotected

Definition at line 68 of file C4PuncherPacket.h.

68 : id(id) {};

◆ ~C4NetpuncherPacketID()

template<C4NetpuncherPacketType TYPE>
C4NetpuncherPacketID< TYPE >::~C4NetpuncherPacketID ( )
overridedefault

Member Function Documentation

◆ Construct()

std::unique_ptr< C4NetpuncherPacket > C4NetpuncherPacket::Construct ( const C4NetIOPacket rpack)
staticinherited

Definition at line 30 of file C4PuncherPacket.cpp.

30  {
31  if (!rpack.getPData() || *rpack.getPData() != C4NetpuncherProtocolVersion) return nullptr;
32  try {
33  switch (rpack.getStatus())
34  {
35  case PID_Puncher_AssID: return uptr(new C4NetpuncherPacketAssID(rpack));
36  case PID_Puncher_SReq: return uptr(new C4NetpuncherPacketSReq(rpack));
37  case PID_Puncher_CReq: return uptr(new C4NetpuncherPacketCReq(rpack));
38  case PID_Puncher_IDReq: return uptr(new C4NetpuncherPacketIDReq(rpack));
39  default: return nullptr;
40  }
41  }
42  catch (StdCompiler::Exception *e) { delete e; return nullptr; }
43  catch (...) { return nullptr; }
44 }
@ PID_Puncher_SReq
@ PID_Puncher_CReq
@ PID_Puncher_AssID
@ PID_Puncher_IDReq
uint8_t getStatus() const
Definition: C4NetIO.h:319
const char * getPData() const
Definition: C4NetIO.h:320
std::unique_ptr< C4NetpuncherPacket > uptr

References C4NetIOPacket::getPData().

Referenced by C4Network2IO::HandlePuncherPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetID()

template<C4NetpuncherPacketType TYPE>
CID C4NetpuncherPacketID< TYPE >::GetID ( ) const
inline

Definition at line 71 of file C4PuncherPacket.h.

71 { return id; }

◆ GetType()

template<C4NetpuncherPacketType TYPE>
C4NetpuncherPacketType C4NetpuncherPacketID< TYPE >::GetType ( ) const
inlinefinalvirtual

Implements C4NetpuncherPacket.

Definition at line 70 of file C4PuncherPacket.h.

70 { return TYPE; }

◆ PackTo()

C4NetIOPacket C4NetpuncherPacket::PackTo ( const C4NetIO::addr_t addr) const
inherited

Definition at line 45 of file C4PuncherPacket.cpp.

45  {
46  C4NetIOPacket pkt;
47  pkt.SetAddr(addr);
48  StdBuf content(PackInto());
49  char type = GetType();
50  pkt.New(sizeof(type) + sizeof(C4NetpuncherProtocolVersion) + content.getSize());
51  size_t offset = 0;
52  pkt.Write(&type, sizeof(type), offset);
53  offset += sizeof(type);
54  pkt.Write(&C4NetpuncherProtocolVersion, sizeof(C4NetpuncherProtocolVersion), offset);
55  offset += sizeof(C4NetpuncherProtocolVersion);
56  pkt.Write(content, offset);
57  return pkt;
58 }
void SetAddr(const C4NetIO::addr_t &naddr)
Definition: C4NetIO.h:328
virtual StdBuf PackInto() const =0
virtual C4NetpuncherPacketType GetType() const =0
Definition: StdBuf.h:30
void New(size_t inSize)
Definition: StdBuf.h:146
void Write(const void *pnData, size_t inSize, size_t iAt=0)
Definition: StdBuf.h:153

References C4NetpuncherPacket::GetType(), StdBuf::New(), C4NetpuncherPacket::PackInto(), and C4NetIOPacket::SetAddr().

Referenced by C4Network2IO::SendPuncherPacket().

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: