![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
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 namespace RakNet 00023 { 00025 class RakPeerInterface; 00026 struct Packet; 00027 #if _RAKNET_SUPPORT_PacketLogger==1 00028 class PacketLogger; 00029 #endif 00030 00035 00037 struct RAK_DLL_EXPORT NatPunchthroughServerDebugInterface 00038 { 00039 NatPunchthroughServerDebugInterface() {} 00040 virtual ~NatPunchthroughServerDebugInterface() {} 00041 virtual void OnServerMessage(const char *msg)=0; 00042 }; 00043 00045 struct RAK_DLL_EXPORT NatPunchthroughServerDebugInterface_Printf : public NatPunchthroughServerDebugInterface 00046 { 00047 virtual void OnServerMessage(const char *msg); 00048 }; 00049 00050 #if _RAKNET_SUPPORT_PacketLogger==1 00051 00052 struct RAK_DLL_EXPORT NatPunchthroughServerDebugInterface_PacketLogger : public NatPunchthroughServerDebugInterface 00053 { 00054 // Set to non-zero to write to the packetlogger! 00055 PacketLogger *pl; 00056 00057 NatPunchthroughServerDebugInterface_PacketLogger() {pl=0;} 00058 ~NatPunchthroughServerDebugInterface_PacketLogger() {} 00059 virtual void OnServerMessage(const char *msg); 00060 }; 00061 #endif 00062 00070 class RAK_DLL_EXPORT NatPunchthroughServer : public PluginInterface2 00071 { 00072 public: 00073 00074 STATIC_FACTORY_DECLARATIONS(NatPunchthroughServer) 00075 00076 // Constructor 00077 NatPunchthroughServer(); 00078 00079 // Destructor 00080 virtual ~NatPunchthroughServer(); 00081 00084 void SetDebugInterface(NatPunchthroughServerDebugInterface *i); 00085 00087 virtual void Update(void); 00088 00090 virtual PluginReceiveResult OnReceive(Packet *packet); 00091 00093 virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason ); 00094 virtual void OnNewConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming); 00095 00096 // Each connected user has a ready state. Ready means ready for nat punchthrough. 00097 struct User; 00098 struct ConnectionAttempt 00099 { 00100 ConnectionAttempt() {sender=0; recipient=0; startTime=0; attemptPhase=NAT_ATTEMPT_PHASE_NOT_STARTED;} 00101 User *sender, *recipient; 00102 uint16_t sessionId; 00103 RakNet::Time startTime; 00104 enum 00105 { 00106 NAT_ATTEMPT_PHASE_NOT_STARTED, 00107 NAT_ATTEMPT_PHASE_GETTING_RECENT_PORTS, 00108 } attemptPhase; 00109 }; 00110 struct User 00111 { 00112 RakNetGUID guid; 00113 SystemAddress systemAddress; 00114 unsigned short mostRecentPort; 00115 bool isReady; 00116 DataStructures::OrderedList<RakNetGUID,RakNetGUID> groupPunchthroughRequests; 00117 00118 DataStructures::List<ConnectionAttempt *> connectionAttempts; 00119 bool HasConnectionAttemptToUser(User *user); 00120 void DerefConnectionAttempt(ConnectionAttempt *ca); 00121 void DeleteConnectionAttempt(ConnectionAttempt *ca); 00122 void LogConnectionAttempts(RakNet::RakString &rs); 00123 }; 00124 RakNet::Time lastUpdate; 00125 static int NatPunchthroughUserComp( const RakNetGUID &key, User * const &data ); 00126 protected: 00127 void OnNATPunchthroughRequest(Packet *packet); 00128 DataStructures::OrderedList<RakNetGUID, User*, NatPunchthroughServer::NatPunchthroughUserComp> users; 00129 00130 void OnGetMostRecentPort(Packet *packet); 00131 void OnClientReady(Packet *packet); 00132 00133 void SendTimestamps(void); 00134 void StartPendingPunchthrough(void); 00135 void StartPunchthroughForUser(User*user); 00136 uint16_t sessionId; 00137 NatPunchthroughServerDebugInterface *natPunchthroughServerDebugInterface; 00138 00139 }; 00140 00141 } // namespace RakNet 00142 00143 #endif 00144 00145 #endif // _RAKNET_SUPPORT_*
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.