NatTypeDetectionClient.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief Contains the NAT-type detection code for the client
  12. ///
  13. #include "NativeFeatureIncludes.h"
  14. #if _RAKNET_SUPPORT_NatTypeDetectionClient==1
  15. #ifndef __NAT_TYPE_DETECTION_CLIENT_H
  16. #define __NAT_TYPE_DETECTION_CLIENT_H
  17. #include "RakNetTypes.h"
  18. #include "Export.h"
  19. #include "PluginInterface2.h"
  20. #include "PacketPriority.h"
  21. #include "SocketIncludes.h"
  22. #include "DS_OrderedList.h"
  23. #include "RakString.h"
  24. #include "NatTypeDetectionCommon.h"
  25. namespace RakNet
  26. {
  27. /// Forward declarations
  28. class RakPeerInterface;
  29. struct Packet;
  30. /// \brief Client code for NatTypeDetection
  31. /// \details See NatTypeDetectionServer.h for algorithm
  32. /// To use, just connect to the server, and call DetectNAT
  33. /// You will get back ID_NAT_TYPE_DETECTION_RESULT with one of the enumerated values of NATTypeDetectionResult found in NATTypeDetectionCommon.h
  34. /// See also http://www.jenkinssoftware.com/raknet/manual/natpunchthrough.html
  35. /// \sa NatPunchthroughClient
  36. /// \sa NatTypeDetectionServer
  37. /// \ingroup NAT_TYPE_DETECTION_GROUP
  38. class RAK_DLL_EXPORT NatTypeDetectionClient : public PluginInterface2, public RNS2EventHandler
  39. {
  40. public:
  41. // GetInstance() and DestroyInstance(instance*)
  42. STATIC_FACTORY_DECLARATIONS(NatTypeDetectionClient)
  43. // Constructor
  44. NatTypeDetectionClient();
  45. // Destructor
  46. virtual ~NatTypeDetectionClient();
  47. /// Send the message to the server to detect the nat type
  48. /// Server must be running NatTypeDetectionServer
  49. /// We must already be connected to the server
  50. /// \param[in] serverAddress address of the server
  51. void DetectNATType(SystemAddress _serverAddress);
  52. /// \internal For plugin handling
  53. virtual void Update(void);
  54. /// \internal For plugin handling
  55. virtual PluginReceiveResult OnReceive(Packet *packet);
  56. virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
  57. virtual void OnRakPeerShutdown(void);
  58. virtual void OnDetach(void);
  59. virtual void OnRNS2Recv(RNS2RecvStruct *recvStruct);
  60. virtual void DeallocRNS2RecvStruct(RNS2RecvStruct *s, const char *file, unsigned int line);
  61. virtual RNS2RecvStruct *AllocRNS2RecvStruct(const char *file, unsigned int line);
  62. protected:
  63. DataStructures::Queue<RNS2RecvStruct*> bufferedPackets;
  64. SimpleMutex bufferedPacketsMutex;
  65. RakNetSocket2* c2;
  66. //unsigned short c2Port;
  67. void Shutdown(void);
  68. void OnCompletion(NATTypeDetectionResult result);
  69. bool IsInProgress(void) const;
  70. void OnTestPortRestricted(Packet *packet);
  71. SystemAddress serverAddress;
  72. };
  73. }
  74. #endif
  75. #endif // _RAKNET_SUPPORT_*
粤ICP备19079148号