OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Network2Discover.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 #ifndef INC_C4Network2Discover
17 #define INC_C4Network2Discover
18 
19 #include "network/C4NetIO.h"
20 
21 const int C4NetMaxDiscover = 64;
22 
24 
26 {
27 public:
28  C4Network2IODiscover(uint16_t iRefServerPort) : iRefServerPort(iRefServerPort), fEnabled(false)
30 
31 protected:
32 
33  // callbacks (will handle everything here)
34  virtual void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO);
35 
36 public:
37  bool Init(uint16_t iPort = C4NetIO::addr_t::IPPORT_NONE);
38  void SetDiscoverable(bool fnEnabled) { fEnabled = fnEnabled; }
39  bool Announce();
40 
41 private:
42  C4NetIO::addr_t DiscoveryAddr;
43 
44  uint16_t iRefServerPort;
45  bool fEnabled;
46 };
47 
49 {
50 public:
51  C4Network2IODiscoverClient() : iDiscoverCount(0)
53 
54 protected:
55 
56  // callbacks (will handle everything here)
57  virtual void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO);
58 
59 public:
60  int getDiscoverCount() const { return iDiscoverCount; }
61  const C4NetIO::addr_t &getDiscover(int i) { return Discovers[i]; }
62 
63  void Clear() { iDiscoverCount = 0; }
64  bool Init(uint16_t iPort = C4NetIO::addr_t::IPPORT_NONE);
65  bool StartDiscovery();
66  bool PopDiscover(C4NetIO::addr_t &Discover);
67 
68 private:
69  C4NetIO::addr_t DiscoveryAddr;
70 
71  int iDiscoverCount;
73 
74 };
75 
76 #endif // INC_C4Network2Discover
const StdStrBuf C4NetDiscoveryAddress
const C4NetIO::addr_t & getDiscover(int i)
bool Init(uint16_t iPort=C4NetIO::addr_t::IPPORT_NONE)
bool PopDiscover(C4NetIO::addr_t &Discover)
bool Init(uint16_t iPort=C4NetIO::addr_t::IPPORT_NONE)
void SetDiscoverable(bool fnEnabled)
C4Network2IODiscover(uint16_t iRefServerPort)
virtual void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
virtual void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
const int C4NetMaxDiscover
virtual void SetCallback(CBClass *pnCallback)
Definition: C4NetIO.h:572