Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "NativeFeatureIncludes.h"
00009 #if _RAKNET_SUPPORT_NatPunchthroughServer==1
00010
00011 #ifndef __NAT_PUNCHTHROUGH_SERVER_H
00012 #define __NAT_PUNCHTHROUGH_SERVER_H
00013
00014 #include "RakNetTypes.h"
00015 #include "Export.h"
00016 #include "PluginInterface2.h"
00017 #include "PacketPriority.h"
00018 #include "SocketIncludes.h"
00019 #include "DS_OrderedList.h"
00020 #include "RakString.h"
00021
00022 class RakPeerInterface;
00023 struct Packet;
00024 #if _RAKNET_SUPPORT_PacketLogger==1
00025 class PacketLogger;
00026 #endif
00027
00032
00034 struct NatPunchthroughServerDebugInterface
00035 {
00036 NatPunchthroughServerDebugInterface() {}
00037 virtual ~NatPunchthroughServerDebugInterface() {}
00038 virtual void OnServerMessage(const char *msg)=0;
00039 };
00040
00042 struct NatPunchthroughServerDebugInterface_Printf : public NatPunchthroughServerDebugInterface
00043 {
00044 virtual void OnServerMessage(const char *msg);
00045 };
00046
00047 #if _RAKNET_SUPPORT_PacketLogger==1
00048
00049 struct NatPunchthroughServerDebugInterface_PacketLogger : public NatPunchthroughServerDebugInterface
00050 {
00051
00052 PacketLogger *pl;
00053
00054 NatPunchthroughServerDebugInterface_PacketLogger() {pl=0;}
00055 ~NatPunchthroughServerDebugInterface_PacketLogger() {}
00056 virtual void OnServerMessage(const char *msg);
00057 };
00058 #endif
00059
00067 class RAK_DLL_EXPORT NatPunchthroughServer : public PluginInterface2
00068 {
00069 public:
00070
00071 NatPunchthroughServer();
00072
00073
00074 virtual ~NatPunchthroughServer();
00075
00078 void SetDebugInterface(NatPunchthroughServerDebugInterface *i);
00079
00081 virtual void Update(void);
00082
00084 virtual PluginReceiveResult OnReceive(Packet *packet);
00085
00087 virtual void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
00088 virtual void OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming);
00089
00090
00091 struct User;
00092 struct ConnectionAttempt
00093 {
00094 ConnectionAttempt() {sender=0; recipient=0; startTime=0; attemptPhase=NAT_ATTEMPT_PHASE_NOT_STARTED;}
00095 User *sender, *recipient;
00096 uint16_t sessionId;
00097 RakNetTime startTime;
00098 enum
00099 {
00100 NAT_ATTEMPT_PHASE_NOT_STARTED,
00101 NAT_ATTEMPT_PHASE_GETTING_RECENT_PORTS,
00102 } attemptPhase;
00103 };
00104 struct User
00105 {
00106 RakNetGUID guid;
00107 SystemAddress systemAddress;
00108 unsigned short mostRecentPort;
00109 bool isReady;
00110
00111 DataStructures::List<ConnectionAttempt *> connectionAttempts;
00112 bool HasConnectionAttemptToUser(User *user);
00113 void DerefConnectionAttempt(ConnectionAttempt *ca);
00114 void DeleteConnectionAttempt(ConnectionAttempt *ca);
00115 void LogConnectionAttempts(RakNet::RakString &rs);
00116 };
00117 RakNetTime lastUpdate;
00118 static int NatPunchthroughUserComp( const RakNetGUID &key, User * const &data );
00119 protected:
00120 void OnNATPunchthroughRequest(Packet *packet);
00121 DataStructures::OrderedList<RakNetGUID, User*, NatPunchthroughServer::NatPunchthroughUserComp> users;
00122
00123 void OnGetMostRecentPort(Packet *packet);
00124 void OnClientReady(Packet *packet);
00125
00126 void SendTimestamps(void);
00127 void StartPendingPunchthrough(void);
00128 void StartPunchthroughForUser(User*user);
00129 uint16_t sessionId;
00130 NatPunchthroughServerDebugInterface *natPunchthroughServerDebugInterface;
00131
00132 };
00133
00134 #endif
00135
00136 #endif // _RAKNET_SUPPORT_*