ReplicaNet and RNLobby  1
NATDetectClient.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _NATDETECTCLIENT_H_
13 #define _NATDETECTCLIENT_H_
14 #include "RNLobby/Inc/NATDetectServer.h"
15 #include "RNXPURL/Inc/Transport.h"
16 
17 namespace RNReplicaNet
18 {
19 
20 namespace RNLobby
21 {
22 
26 {
27 public:
28  enum NATType
29  {
30  kOpen = 0,
31  kModerate,
32  kStrict
33  };
34 
36  virtual ~NATDetectClient();
37 
40  bool Start(const int channel = TransportAnyGameChannel);
41 
43  void SetServers(const XPAddress &address1,const XPAddress &address2);
44 
47  bool GetCompleted(void);
48 
51  NATDetectServer::Reply GetReply(void);
52 
54  NATType GetNATType(void) const;
55 
57  XPAddress GetPublicAddress(void) const;
58 
60  virtual void CallbackCompleted(void) {}
61 
63  void GetAddressReplies(XPAddress &addr1,XPAddress &addr2);
64 
65 private:
66  void Init(void);
67  bool CallbackParseValidMessage(DynamicMessageHelper &message,const size_t length,const XPAddress &address);
68  bool DoSuccessState(void);
69 
70  bool CallbackPoll(void);
71 
72  SysTimeType mLastSentTime;
73  int mGot1Times;
74  int mGot2Times;
75  int mTries;
76  volatile NATDetectServer::Reply mReply;
77  XPAddress mAddress1;
78  XPAddress mAddress2;
79 
80  XPAddress mAddress1Reply;
81  XPAddress mAddress2Reply;
82 
83  bool mIsNiceNAT;
84 
85  bool mGotOther;
86  bool mServerAddressSet;
87 };
88 
89 } // namespace RNLobby
90 
91 } // namespace RNReplicaNet
92 
93 #endif
bool Start(const int channel=TransportAnyGameChannel)
Definition: XPSocket.h:91
Definition: NATDetectClient.h:25
NATType GetNATType(void) const
If GetReply() == NATDetectServer::kReply_Success this returns the type of NAT calculated by this clas...
void GetAddressReplies(XPAddress &addr1, XPAddress &addr2)
Gets the two addresses as seen by the NATDetectServer.
virtual void CallbackCompleted(void)
A virtual callback that is triggered when the NATDetect calculation is complete. GetReply(), GetNATType() and GetPublicAddress() can be used during this callback or at any time after completion.
Definition: NATDetectClient.h:60
XPAddress GetPublicAddress(void) const
Returns the public internet address of this computer as seen by the NATDetectServer.
NATDetectServer::Reply GetReply(void)
Definition: MessageHelper.h:211
void SetServers(const XPAddress &address1, const XPAddress &address2)
Sets the address and port of the servers. The default for the instance of the class is localhost and ...
A server base class that handles encrypted messages to and from a socket.
Definition: BaseServer.h:24