OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4NetpuncherPacketCReq Class Reference

#include <C4PuncherPacket.h>

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

Public Types

typedef std::unique_ptr
< C4NetpuncherPacket
uptr
 

Public Member Functions

C4NetpuncherPacketType GetType () const final
 
 C4NetpuncherPacketCReq (const C4NetIOPacket &rpack)
 
 C4NetpuncherPacketCReq (const C4NetIO::addr_t &addr)
 
const C4NetIO::addr_tGetAddr ()
 
C4NetIOPacket PackTo (const C4NetIO::addr_t &) const
 

Static Public Member Functions

static std::unique_ptr
< C4NetpuncherPacket
Construct (const C4NetIOPacket &rpack)
 

Protected Types

typedef C4NetpuncherID::value CID
 

Detailed Description

Definition at line 83 of file C4PuncherPacket.h.

Member Typedef Documentation

typedef C4NetpuncherID::value C4NetpuncherPacket::CID
protectedinherited

Definition at line 49 of file C4PuncherPacket.h.

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

Definition at line 42 of file C4PuncherPacket.h.

Constructor & Destructor Documentation

C4NetpuncherPacketCReq::C4NetpuncherPacketCReq ( const C4NetIOPacket rpack)
explicit

Definition at line 60 of file C4PuncherPacket.cpp.

References C4NetIO::HostAddress::Any, C4NetIOPacket::getPSize(), and C4NetIO::EndpointAddress::SetAddress().

60  {
61  if (rpack.getPSize() < HeaderPSize + 2 + 16) throw "invalid size";
62  uint16_t port = *getBufPtr<uint16_t>(rpack, HeaderSize);
63  addr.SetAddress(C4NetIO::addr_t::Any, port);
64  memcpy(&static_cast<sockaddr_in6*>(&addr)->sin6_addr, getBufPtr<char>(rpack, HeaderSize + sizeof(port)), 16);
65 }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
size_t getPSize() const
Definition: C4NetIO.h:319

Here is the call graph for this function:

C4NetpuncherPacketCReq::C4NetpuncherPacketCReq ( const C4NetIO::addr_t addr)
inlineexplicit

Definition at line 90 of file C4PuncherPacket.h.

90 : addr(addr) {};

Member Function Documentation

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

Definition at line 30 of file C4PuncherPacket.cpp.

References C4NetIOPacket::getPData(), C4NetIOPacket::getStatus(), PID_Puncher_AssID, PID_Puncher_CReq, PID_Puncher_IDReq, and PID_Puncher_SReq.

Referenced by C4Network2IO::HandlePuncherPacket().

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 }
std::unique_ptr< C4NetpuncherPacket > uptr
uint8_t getStatus() const
Definition: C4NetIO.h:317
const char * getPData() const
Definition: C4NetIO.h:318

Here is the call graph for this function:

Here is the caller graph for this function:

const C4NetIO::addr_t& C4NetpuncherPacketCReq::GetAddr ( )
inline

Definition at line 91 of file C4PuncherPacket.h.

91 { return addr; }
C4NetpuncherPacketType C4NetpuncherPacketCReq::GetType ( ) const
inlinefinalvirtual

Implements C4NetpuncherPacket.

Definition at line 88 of file C4PuncherPacket.h.

References PID_Puncher_CReq.

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

Definition at line 45 of file C4PuncherPacket.cpp.

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

Referenced by C4Network2IO::SendPuncherPacket().

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 }
Definition: StdBuf.h:29
void New(size_t inSize)
Definition: StdBuf.h:146
virtual C4NetpuncherPacketType GetType() const =0
void Write(const void *pnData, size_t inSize, size_t iAt=0)
Definition: StdBuf.h:153
void SetAddr(const C4NetIO::addr_t &naddr)
Definition: C4NetIO.h:326
virtual StdBuf PackInto() const =0

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: