LogCommandParser.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 LogCommandParser , Used to send logs to connected consoles
  12. ///
  13. #include "NativeFeatureIncludes.h"
  14. #if _RAKNET_SUPPORT_LogCommandParser==1
  15. #ifndef __LOG_COMMAND_PARSER
  16. #define __LOG_COMMAND_PARSER
  17. #include "CommandParserInterface.h"
  18. #include "Export.h"
  19. namespace RakNet
  20. {
  21. /// Forward declarations
  22. class RakPeerInterface;
  23. /// \brief Adds the ability to send logging output to a remote console
  24. class RAK_DLL_EXPORT LogCommandParser : public CommandParserInterface
  25. {
  26. public:
  27. // GetInstance() and DestroyInstance(instance*)
  28. STATIC_FACTORY_DECLARATIONS(LogCommandParser)
  29. LogCommandParser();
  30. ~LogCommandParser();
  31. /// Given \a command with parameters \a parameterList , do whatever processing you wish.
  32. /// \param[in] command The command to process
  33. /// \param[in] numParameters How many parameters were passed along with the command
  34. /// \param[in] parameterList The list of parameters. parameterList[0] is the first parameter and so on.
  35. /// \param[in] transport The transport interface we can use to write to
  36. /// \param[in] systemAddress The player that sent this command.
  37. /// \param[in] originalString The string that was actually sent over the network, in case you want to do your own parsing
  38. bool OnCommand(const char *command, unsigned numParameters, char **parameterList, TransportInterface *transport, const SystemAddress &systemAddress, const char *originalString);
  39. /// You are responsible for overriding this function and returning a static string, which will identifier your parser.
  40. /// This should return a static string
  41. /// \return The name that you return.
  42. const char *GetName(void) const;
  43. /// A callback for when you are expected to send a brief description of your parser to \a systemAddress
  44. /// \param[in] transport The transport interface we can use to write to
  45. /// \param[in] systemAddress The player that requested help.
  46. void SendHelp(TransportInterface *transport, const SystemAddress &systemAddress);
  47. /// All logs must be associated with a channel. This is a filter so that remote clients only get logs for a system they care about.
  48. // If you call Log with a channel that is unknown, that channel will automatically be added
  49. /// \param[in] channelName A persistent string naming the channel. Don't deallocate this string.
  50. void AddChannel(const char *channelName);
  51. /// Write a log to a channel.
  52. /// Logs are not buffered, so only remote consoles connected and subscribing at the time you write will get the output.
  53. /// \param[in] format Same as RAKNET_DEBUG_PRINTF()
  54. /// \param[in] ... Same as RAKNET_DEBUG_PRINTF()
  55. void WriteLog(const char *channelName, const char *format, ...);
  56. /// A callback for when \a systemAddress has connected to us.
  57. /// \param[in] systemAddress The player that has connected.
  58. /// \param[in] transport The transport interface that sent us this information. Can be used to send messages to this or other players.
  59. void OnNewIncomingConnection(const SystemAddress &systemAddress, TransportInterface *transport);
  60. /// A callback for when \a systemAddress has disconnected, either gracefully or forcefully
  61. /// \param[in] systemAddress The player that has disconnected.
  62. /// \param[in] transport The transport interface that sent us this information.
  63. void OnConnectionLost(const SystemAddress &systemAddress, TransportInterface *transport);
  64. /// This is called every time transport interface is registered. If you want to save a copy of the TransportInterface pointer
  65. /// This is the place to do it
  66. /// \param[in] transport The new TransportInterface
  67. void OnTransportChange(TransportInterface *transport);
  68. protected:
  69. /// Sends the currently active channels to the user
  70. /// \param[in] systemAddress The player to send to
  71. /// \param[in] transport The transport interface to use to send the channels
  72. void PrintChannels(const SystemAddress &systemAddress, TransportInterface *transport) const;
  73. /// Unsubscribe a user from a channel (or from all channels)
  74. /// \param[in] systemAddress The player to unsubscribe to
  75. /// \param[in] channelName If 0, then unsubscribe from all channels. Otherwise unsubscribe from the named channel
  76. unsigned Unsubscribe(const SystemAddress &systemAddress, const char *channelName);
  77. /// Subscribe a user to a channel (or to all channels)
  78. /// \param[in] systemAddress The player to subscribe to
  79. /// \param[in] channelName If 0, then subscribe from all channels. Otherwise subscribe to the named channel
  80. unsigned Subscribe(const SystemAddress &systemAddress, const char *channelName);
  81. /// Given the name of a channel, return the index into channelNames where it is located
  82. /// \param[in] channelName The name of the channel
  83. unsigned GetChannelIndexFromName(const char *channelName);
  84. /// One of these structures is created per player
  85. struct SystemAddressAndChannel
  86. {
  87. /// The ID of the player
  88. SystemAddress systemAddress;
  89. /// Bitwise representations of the channels subscribed to. If bit 0 is set, then we subscribe to channelNames[0] and so on.
  90. unsigned channels;
  91. };
  92. /// The list of remote users. Added to when users subscribe, removed when they disconnect or unsubscribe
  93. DataStructures::List<SystemAddressAndChannel> remoteUsers;
  94. /// Names of the channels at each bit, or 0 for an unused channel
  95. const char *channelNames[32];
  96. /// This is so I can save the current transport provider, solely so I can use it without having the user pass it to Log
  97. TransportInterface *trans;
  98. };
  99. } // namespace RakNet
  100. #endif
  101. #endif // _RAKNET_SUPPORT_*
粤ICP备19079148号