OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4PuncherPacket.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef C4PuncherPacket_H
17 #define C4PuncherPacket_H
18 
19 /* I'm cooking up a seperate solution for the netpuncher because using C4Packet2.cpp would require introducing half a ton of stubs, and it seems like overkill */
20 
21 #include "network/C4NetIO.h"
22 
24  PID_Puncher_AssID = 0x51, // Puncher announcing ID to host
25  PID_Puncher_SReq = 0x52, // Client requesting to be served with punching (for an ID)
26  PID_Puncher_CReq = 0x53, // Puncher requesting clients to punch (towards an address)
27  PID_Puncher_IDReq = 0x54, // Host requesting an ID
28  // extend this with exchanging ICE parameters, some day?
29 };
30 
32  typedef uint32_t value;
33 
34  value v4 = 0, v6 = 0;
35 
36  void CompileFunc(StdCompiler *pComp);
37  bool operator==(const C4NetpuncherID& other) const { return v4 == other.v4 && v6 == other.v6; }
38 };
39 
41 public:
42  typedef std::unique_ptr<C4NetpuncherPacket> uptr;
43  static std::unique_ptr<C4NetpuncherPacket> Construct(const C4NetIOPacket& rpack);
44  virtual ~C4NetpuncherPacket() = default;
45  virtual C4NetpuncherPacketType GetType() const = 0;
46  C4NetIOPacket PackTo(const C4NetIO::addr_t&) const;
47 protected:
48  virtual StdBuf PackInto() const = 0;
50 };
51 
53 private:
54  StdBuf PackInto() const override { return StdBuf(); }
55 public:
56  C4NetpuncherPacketIDReq() = default;
59 };
60 
61 template<C4NetpuncherPacketType TYPE>
63 private:
64  CID id;
65  StdBuf PackInto() const override;
66 protected:
67  C4NetpuncherPacketID(const C4NetIOPacket& rpack);
68  C4NetpuncherPacketID(CID id) : id(id) {};
69 public:
70  C4NetpuncherPacketType GetType() const final { return TYPE; }
71  CID GetID() const { return id; }
72  ~C4NetpuncherPacketID() override = default;;
73 };
74 
75 #define PIDC(n) \
76  class C4NetpuncherPacket##n : public C4NetpuncherPacketID<PID_Puncher_##n> { \
77  public: explicit C4NetpuncherPacket##n(const C4NetIOPacket& p) : C4NetpuncherPacketID<PID_Puncher_##n>(p) {}; \
78  public: explicit C4NetpuncherPacket##n(CID id) : C4NetpuncherPacketID<PID_Puncher_##n>(id) {}; \
79  }
80 PIDC(AssID); PIDC(SReq);
81 #undef PIDC
82 
84 private:
85  C4NetIO::addr_t addr;
86  StdBuf PackInto() const override;
87 public:
89  explicit C4NetpuncherPacketCReq(const C4NetIOPacket& rpack);
90  explicit C4NetpuncherPacketCReq(const C4NetIO::addr_t& addr) : addr(addr) {};
91  const C4NetIO::addr_t& GetAddr() { return addr; }
92 };
93 
94 #endif
const C4NetIO::addr_t & GetAddr()
C4NetIOPacket PackTo(const C4NetIO::addr_t &) const
Definition: StdBuf.h:29
static std::unique_ptr< C4NetpuncherPacket > Construct(const C4NetIOPacket &rpack)
C4NetpuncherPacketIDReq(const C4NetIOPacket &rpack)
~C4NetpuncherPacketID() override=default
C4NetpuncherPacketType GetType() const final
bool operator==(const C4NetpuncherID &other) const
#define PIDC(n)
void CompileFunc(StdCompiler *pComp)
C4NetpuncherPacketType
virtual C4NetpuncherPacketType GetType() const =0
C4NetpuncherPacketIDReq()=default
C4NetpuncherPacketID(const C4NetIOPacket &rpack)
std::unique_ptr< C4NetpuncherPacket > uptr
C4NetpuncherPacketCReq(const C4NetIOPacket &rpack)
C4NetpuncherPacketType GetType() const final
C4NetpuncherPacketCReq(const C4NetIO::addr_t &addr)
C4NetpuncherPacketType GetType() const final
C4NetpuncherID::value CID
virtual ~C4NetpuncherPacket()=default
virtual StdBuf PackInto() const =0