Shadowrun: Awakened 29 September 2011 - Build 871
NatTypeDetectionServer.h
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "NativeFeatureIncludes.h"
00009 #if _RAKNET_SUPPORT_NatTypeDetectionServer==1
00010 
00011 #ifndef __NAT_TYPE_DETECTION_SERVER_H
00012 #define __NAT_TYPE_DETECTION_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 #include "NatTypeDetectionCommon.h"
00022 
00023 
00024 namespace RakNet
00025 {
00027 class RakPeerInterface;
00028 struct Packet;
00029 
00048 class RAK_DLL_EXPORT NatTypeDetectionServer : public PluginInterface2
00049 {
00050 public:
00051 
00052     // GetInstance() and DestroyInstance(instance*)
00053     STATIC_FACTORY_DECLARATIONS(NatTypeDetectionServer)
00054 
00055     // Constructor
00056     NatTypeDetectionServer();
00057 
00058     // Destructor
00059     virtual ~NatTypeDetectionServer();
00060 
00065     void Startup(
00066         const char *nonRakNetIP2,
00067         const char *nonRakNetIP3,
00068         const char *nonRakNetIP4);
00069 
00070     // Releases the sockets created in Startup();
00071     void Shutdown(void);
00072 
00074     virtual void Update(void);
00075 
00077     virtual PluginReceiveResult OnReceive(Packet *packet);
00078     virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
00079 
00080     enum NATDetectionState
00081     {
00082         STATE_NONE,
00083         STATE_TESTING_NONE_1,
00084         STATE_TESTING_NONE_2,
00085         STATE_TESTING_FULL_CONE_1,
00086         STATE_TESTING_FULL_CONE_2,
00087         STATE_TESTING_ADDRESS_RESTRICTED_1,
00088         STATE_TESTING_ADDRESS_RESTRICTED_2,
00089         STATE_TESTING_PORT_RESTRICTED_1,
00090         STATE_TESTING_PORT_RESTRICTED_2,
00091         STATE_DONE,
00092     };
00093 
00094     struct NATDetectionAttempt
00095     {
00096         SystemAddress systemAddress;
00097         NATDetectionState detectionState;
00098         RakNet::TimeMS nextStateTime;
00099         RakNet::TimeMS timeBetweenAttempts;
00100         unsigned short c2Port;
00101         RakNetGUID guid;
00102     };
00103 
00104 protected:
00105     void OnDetectionRequest(Packet *packet);
00106     DataStructures::List<NATDetectionAttempt> natDetectionAttempts;
00107     unsigned int GetDetectionAttemptIndex(const SystemAddress &sa);
00108     unsigned int GetDetectionAttemptIndex(RakNetGUID guid);
00109 
00110     // s1p1 is rakpeer itself
00111     SOCKET s1p2,s2p3,s3p4,s4p5;
00112     unsigned short s1p2Port, s2p3Port, s3p4Port, s4p5Port;
00113     char s3p4Address[64];
00114 };
00115 }
00116 
00117 
00118 #endif
00119 
00120 #endif // _RAKNET_SUPPORT_*

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net