PacketDropPlugin.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #pragma once
  11. #include "RakNetTypes.h"
  12. #include "PluginInterface2.h"
  13. #include "PacketPriority.h"
  14. #include "MessageIdentifiers.h"
  15. #include "InternalPacket.h"
  16. #include "RakTimer.h"
  17. using namespace RakNet;
  18. class PacketDropPlugin : public PluginInterface2
  19. {
  20. public:
  21. PacketDropPlugin(void);
  22. ~PacketDropPlugin(void);
  23. void StartTest();
  24. /// \param[in] peer the instance of RakPeer that is calling Receive
  25. void OnAttach(void) {}
  26. /// Called when the interface is detached
  27. /// \param[in] peer the instance of RakPeer that is calling Receive
  28. void OnDetach(void) {}
  29. /// Update is called every time a packet is checked for .
  30. void Update(void) {}
  31. /// OnReceive is called for every packet.
  32. /// \param[in] packet the packet that is being returned to the user
  33. /// \return True to allow the game and other plugins to get this message, false to absorb it
  34. PluginReceiveResult OnReceive(Packet *packet);// {(void) packet; return RR_CONTINUE_PROCESSING;}
  35. /// Called when RakPeer is initialized
  36. void OnStartup(void) {}
  37. /// Called when RakPeer is shutdown
  38. void OnShutdown(void) {}
  39. /// Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system
  40. /// \param[in] systemAddress The system whose connection was closed
  41. /// \param[in] rakNetGuid The guid of the specified system
  42. /// \param[in] lostConnectionReason How the connection was closed: manually, connection lost, or notification of disconnection
  43. void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason ){(void) systemAddress; (void) rakNetGUID; (void) lostConnectionReason;}
  44. /// Called when we got a new connection
  45. /// \param[in] systemAddress Address of the new connection
  46. /// \param[in] rakNetGuid The guid of the specified system
  47. /// \param[in] isIncoming If true, this is ID_NEW_INCOMING_CONNECTION, or the equivalent
  48. void OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming) {(void) systemAddress; (void) rakNetGUID; (void) isIncoming;}
  49. /// Called when a connection attempt fails
  50. /// \param[in] systemAddress Address of the connection
  51. /// \param[in] failedConnectionReason Why the connection failed
  52. void OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason) {(void) failedConnectionAttemptReason;}
  53. /// Called on a send to the socket, per datagram, that does not go through the reliability layer
  54. /// \param[in] data The data being sent
  55. /// \param[in] bitsUsed How many bits long \a data is
  56. /// \param[in] remoteSystemAddress Which system this message is being sent to
  57. void OnDirectSocketSend(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
  58. /// Called on a receive from the socket, per datagram, that does not go through the reliability layer
  59. /// \param[in] data The data being sent
  60. /// \param[in] bitsUsed How many bits long \a data is
  61. /// \param[in] remoteSystemAddress Which system this message is being sent to
  62. void OnDirectSocketReceive(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
  63. /// Called on a send or receive of a message within the reliability layer
  64. /// \param[in] internalPacket The user message, along with all send data.
  65. /// \param[in] frameNumber The number of frames sent or received so far for this player depending on \a isSend . Indicates the frame of this user message.
  66. /// \param[in] remoteSystemAddress The player we sent or got this packet from
  67. /// \param[in] time The current time as returned by GetTimeMS()
  68. /// \param[in] isSend Is this callback representing a send event or receive event?
  69. void OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, TimeMS time, int isSend) {(void) internalPacket; (void) frameNumber; (void) remoteSystemAddress; (void) time; (void) isSend;}
  70. /// Called when we get an ack for a message we reliabily sent
  71. /// \param[in] messageNumber The numerical identifier for which message this is
  72. /// \param[in] remoteSystemAddress The player we sent or got this packet from
  73. /// \param[in] time The current time as returned by GetTimeMS()
  74. void OnAck(unsigned int messageNumber, SystemAddress remoteSystemAddress, TimeMS time) {(void) messageNumber; (void) remoteSystemAddress; (void) time;}
  75. /// System called RakPeerInterface::PushBackPacket
  76. /// \param[in] data The data being sent
  77. /// \param[in] bitsUsed How many bits long \a data is
  78. /// \param[in] remoteSystemAddress The player we sent or got this packet from
  79. void OnPushBackPacket(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;}
  80. private:
  81. RakTimer timer;
  82. };
粤ICP备19079148号