RakNetTransport2.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 RakNetTransportCommandParser and RakNetTransport used to provide a secure console connection.
  12. ///
  13. #include "NativeFeatureIncludes.h"
  14. #if _RAKNET_SUPPORT_TelnetTransport==1
  15. #ifndef __RAKNET_TRANSPORT_2
  16. #define __RAKNET_TRANSPORT_2
  17. #include "TransportInterface.h"
  18. #include "DS_Queue.h"
  19. #include "CommandParserInterface.h"
  20. #include "PluginInterface2.h"
  21. #include "Export.h"
  22. namespace RakNet
  23. {
  24. /// Forward declarations
  25. class BitStream;
  26. class RakPeerInterface;
  27. class RakNetTransport;
  28. /// \defgroup RAKNET_TRANSPORT_GROUP RakNetTransport
  29. /// \brief UDP based transport implementation for the ConsoleServer
  30. /// \details
  31. /// \ingroup PLUGINS_GROUP
  32. /// \brief Use RakNetTransport if you need a secure connection between the client and the console server.
  33. /// \details RakNetTransport automatically initializes security for the system. Use the project CommandConsoleClient to connect
  34. /// To the ConsoleServer if you use RakNetTransport
  35. /// \ingroup RAKNET_TRANSPORT_GROUP
  36. class RAK_DLL_EXPORT RakNetTransport2 : public TransportInterface, public PluginInterface2
  37. {
  38. public:
  39. // GetInstance() and DestroyInstance(instance*)
  40. STATIC_FACTORY_DECLARATIONS(RakNetTransport2)
  41. RakNetTransport2();
  42. virtual ~RakNetTransport2();
  43. /// Start the transport provider on the indicated port.
  44. /// \param[in] port The port to start the transport provider on
  45. /// \param[in] serverMode If true, you should allow incoming connections (I don't actually use this anywhere)
  46. /// \return Return true on success, false on failure.
  47. bool Start(unsigned short port, bool serverMode);
  48. /// Stop the transport provider. You can clear memory and shutdown threads here.
  49. void Stop(void);
  50. /// Send a null-terminated string to \a systemAddress
  51. /// If your transport method requires particular formatting of the outgoing data (e.g. you don't just send strings) you can do it here
  52. /// and parse it out in Receive().
  53. /// \param[in] systemAddress The player to send the string to
  54. /// \param[in] data format specifier - same as RAKNET_DEBUG_PRINTF
  55. /// \param[in] ... format specification arguments - same as RAKNET_DEBUG_PRINTF
  56. void Send( SystemAddress systemAddress, const char *data, ... );
  57. /// Disconnect \a systemAddress . The binary address and port defines the SystemAddress structure.
  58. /// \param[in] systemAddress The player/address to disconnect
  59. void CloseConnection( SystemAddress systemAddress );
  60. /// Return a string. The string should be allocated and written to Packet::data .
  61. /// The byte length should be written to Packet::length . The player/address should be written to Packet::systemAddress
  62. /// If your transport protocol adds special formatting to the data stream you should parse it out before returning it in the packet
  63. /// and thus only return a string in Packet::data
  64. /// \return The packet structure containing the result of Receive, or 0 if no data is available
  65. Packet* Receive( void );
  66. /// Deallocate the Packet structure returned by Receive
  67. /// \param[in] The packet to deallocate
  68. void DeallocatePacket( Packet *packet );
  69. /// If a new system connects to you, you should queue that event and return the systemAddress/address of that player in this function.
  70. /// \return The SystemAddress/address of the system
  71. SystemAddress HasNewIncomingConnection(void);
  72. /// If a system loses the connection, you should queue that event and return the systemAddress/address of that player in this function.
  73. /// \return The SystemAddress/address of the system
  74. SystemAddress HasLostConnection(void);
  75. virtual CommandParserInterface* GetCommandParser(void) {return 0;}
  76. /// \internal
  77. virtual PluginReceiveResult OnReceive(Packet *packet);
  78. /// \internal
  79. virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
  80. /// \internal
  81. virtual void OnNewConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming);
  82. protected:
  83. DataStructures::Queue<SystemAddress> newConnections, lostConnections;
  84. DataStructures::Queue<Packet*> packetQueue;
  85. };
  86. } // namespace RakNet
  87. #endif
  88. #endif // _RAKNET_SUPPORT_*
粤ICP备19079148号