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 client
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  // extend this with exchanging ICE parameters, some day?
28 };
29 
31  typedef uint32_t value;
32 
33  value v4 = 0, v6 = 0;
34 
35  void CompileFunc(StdCompiler *pComp);
36  bool operator==(const C4NetpuncherID& other) const { return v4 == other.v4 && v6 == other.v6; }
37 };
38 
40 public:
41  typedef std::unique_ptr<C4NetpuncherPacket> uptr;
42  static std::unique_ptr<C4NetpuncherPacket> Construct(const C4NetIOPacket& rpack);
43  virtual ~C4NetpuncherPacket() = default;
44  virtual C4NetpuncherPacketType GetType() const = 0;
45  C4NetIOPacket PackTo(const C4NetIO::addr_t&) const;
46 protected:
47  virtual StdBuf PackInto() const = 0;
49 };
50 
51 template<C4NetpuncherPacketType TYPE>
53 private:
54  CID id;
55  StdBuf PackInto() const override;
56 protected:
57  C4NetpuncherPacketID(const C4NetIOPacket& rpack);
58  C4NetpuncherPacketID(CID id) : id(id) {};
59 public:
60  C4NetpuncherPacketType GetType() const final { return TYPE; }
61  CID GetID() const { return id; }
62  ~C4NetpuncherPacketID() override = default;;
63 };
64 
65 #define PIDC(n) \
66  class C4NetpuncherPacket##n : public C4NetpuncherPacketID<PID_Puncher_##n> { \
67  public: explicit C4NetpuncherPacket##n(const C4NetIOPacket& p) : C4NetpuncherPacketID<PID_Puncher_##n>(p) {}; \
68  public: explicit C4NetpuncherPacket##n(CID id) : C4NetpuncherPacketID<PID_Puncher_##n>(id) {}; \
69  }
70 PIDC(AssID); PIDC(SReq);
71 #undef PIDC
72 
74 private:
75  C4NetIO::addr_t addr;
76  StdBuf PackInto() const override;
77 public:
79  explicit C4NetpuncherPacketCReq(const C4NetIOPacket& rpack);
80  explicit C4NetpuncherPacketCReq(const C4NetIO::addr_t& addr) : addr(addr) {};
81  const C4NetIO::addr_t& GetAddr() { return addr; }
82 };
83 
84 #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)
~C4NetpuncherPacketID() override=default
bool operator==(const C4NetpuncherID &other) const
#define PIDC(n)
void CompileFunc(StdCompiler *pComp)
C4NetpuncherPacketType
virtual C4NetpuncherPacketType GetType() const =0
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