TransportInterface.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 TransportInterface from which you can derive custom transport providers for ConsoleServer.
  12. ///
  13. #ifndef __TRANSPORT_INTERFACE_H
  14. #define __TRANSPORT_INTERFACE_H
  15. #include "RakNetTypes.h"
  16. #include "Export.h"
  17. #include "RakMemoryOverride.h"
  18. #define REMOTE_MAX_TEXT_INPUT 2048
  19. namespace RakNet
  20. {
  21. class CommandParserInterface;
  22. /// \brief Defines an interface that is used to send and receive null-terminated strings.
  23. /// \details In practice this is only used by the CommandParser system for for servers.
  24. class RAK_DLL_EXPORT TransportInterface
  25. {
  26. public:
  27. TransportInterface() {}
  28. virtual ~TransportInterface() {}
  29. /// Start the transport provider on the indicated port.
  30. /// \param[in] port The port to start the transport provider on
  31. /// \param[in] serverMode If true, you should allow incoming connections (I don't actually use this anywhere)
  32. /// \return Return true on success, false on failure.
  33. virtual bool Start(unsigned short port, bool serverMode)=0;
  34. /// Stop the transport provider. You can clear memory and shutdown threads here.
  35. virtual void Stop(void)=0;
  36. /// Send a null-terminated string to \a systemAddress
  37. /// If your transport method requires particular formatting of the outgoing data (e.g. you don't just send strings) you can do it here
  38. /// and parse it out in Receive().
  39. /// \param[in] systemAddress The player to send the string to
  40. /// \param[in] data format specifier - same as RAKNET_DEBUG_PRINTF
  41. /// \param[in] ... format specification arguments - same as RAKNET_DEBUG_PRINTF
  42. virtual void Send( SystemAddress systemAddress, const char *data, ... )=0;
  43. /// Disconnect \a systemAddress . The binary address and port defines the SystemAddress structure.
  44. /// \param[in] systemAddress The player/address to disconnect
  45. virtual void CloseConnection( SystemAddress systemAddress )=0;
  46. /// Return a string. The string should be allocated and written to Packet::data .
  47. /// The byte length should be written to Packet::length . The player/address should be written to Packet::systemAddress
  48. /// If your transport protocol adds special formatting to the data stream you should parse it out before returning it in the packet
  49. /// and thus only return a string in Packet::data
  50. /// \return The packet structure containing the result of Receive, or 0 if no data is available
  51. virtual Packet* Receive( void )=0;
  52. /// Deallocate the Packet structure returned by Receive
  53. /// \param[in] The packet to deallocate
  54. virtual void DeallocatePacket( Packet *packet )=0;
  55. /// If a new system connects to you, you should queue that event and return the systemAddress/address of that player in this function.
  56. /// \return The SystemAddress/address of the system
  57. virtual SystemAddress HasNewIncomingConnection(void)=0;
  58. /// If a system loses the connection, you should queue that event and return the systemAddress/address of that player in this function.
  59. /// \return The SystemAddress/address of the system
  60. virtual SystemAddress HasLostConnection(void)=0;
  61. /// Your transport provider can itself have command parsers if the transport layer has user-modifiable features
  62. /// For example, your transport layer may have a password which you want remote users to be able to set or you may want
  63. /// to allow remote users to turn on or off command echo
  64. /// \return 0 if you do not need a command parser - otherwise the desired derivation of CommandParserInterface
  65. virtual CommandParserInterface* GetCommandParser(void)=0;
  66. protected:
  67. };
  68. } // namespace RakNet
  69. #endif
粤ICP备19079148号