1 /// \file 2 /// \brief \b RakNet's plugin functionality system, version 2. You can derive from this to create your own plugins. 3 /// 4 /// This file is part of RakNet Copyright 2003 Jenkins Software LLC 5 /// 6 /// Raknet is available under the terms of the GPLv3 license, see /usr/local/share/licenses/raknet-3.9.2_10,1/GPLv3. 7 8 9 #ifndef __PLUGIN_INTERFACE_2_H 10 #define __PLUGIN_INTERFACE_2_H 11 12 #include "NativeFeatureIncludes.h" 13 14 class RakPeerInterface; 15 class PacketizedTCP; 16 struct Packet; 17 struct InternalPacket; 18 19 /// \defgroup PLUGIN_INTERFACE_GROUP PluginInterface2 20 21 /// \defgroup PLUGINS_GROUP Plugins 22 /// \ingroup PLUGIN_INTERFACE_GROUP 23 24 /// For each message that arrives on an instance of RakPeer, the plugins get an opportunity to process them first. This enumeration represents what to do with the message 25 /// \ingroup PLUGIN_INTERFACE_GROUP 26 enum PluginReceiveResult 27 { 28 /// The plugin used this message and it shouldn't be given to the user. 29 RR_STOP_PROCESSING_AND_DEALLOCATE=0, 30 31 /// This message will be processed by other plugins, and at last by the user. 32 RR_CONTINUE_PROCESSING, 33 34 /// The plugin is going to hold on to this message. Do not deallocate it but do not pass it to other plugins either. 35 RR_STOP_PROCESSING, 36 }; 37 38 #include "RakNetTypes.h" 39 #include "Export.h" 40 #include "PacketPriority.h" 41 42 /// Reasons why a connection was lost 43 /// \ingroup PLUGIN_INTERFACE_GROUP 44 enum PI2_LostConnectionReason 45 { 46 /// Called RakPeer::CloseConnection() 47 LCR_CLOSED_BY_USER, 48 49 /// Got ID_DISCONNECTION_NOTIFICATION 50 LCR_DISCONNECTION_NOTIFICATION, 51 52 /// GOT ID_CONNECTION_LOST 53 LCR_CONNECTION_LOST 54 }; 55 56 /// Returns why a connection attempt failed 57 /// \ingroup PLUGIN_INTERFACE_GROUP 58 enum PI2_FailedConnectionAttemptReason 59 { 60 FCAR_CONNECTION_ATTEMPT_FAILED, 61 FCAR_ALREADY_CONNECTED, 62 FCAR_NO_FREE_INCOMING_CONNECTIONS, 63 FCAR_RSA_PUBLIC_KEY_MISMATCH, 64 FCAR_CONNECTION_BANNED, 65 FCAR_INVALID_PASSWORD, 66 FCAR_INCOMPATIBLE_PROTOCOL, 67 FCAR_IP_RECENTLY_CONNECTED 68 }; 69 70 /// RakNet's plugin system. Each plugin processes the following events: 71 /// -Connection attempts 72 /// -The result of connection attempts 73 /// -Each incoming message 74 /// -Updates over time, when RakPeer::Receive() is called 75 /// 76 /// \ingroup PLUGIN_INTERFACE_GROUP 77 class RAK_DLL_EXPORT PluginInterface2 78 { 79 public: 80 PluginInterface2(); 81 virtual ~PluginInterface2(); 82 83 /// Called when the interface is attached 84 /// \param[in] peer the instance of RakPeer that is calling Receive OnAttach(void)85 virtual void OnAttach(void) {} 86 87 /// Called when the interface is detached 88 /// \param[in] peer the instance of RakPeer that is calling Receive OnDetach(void)89 virtual void OnDetach(void) {} 90 91 /// Update is called every time a packet is checked for . Update(void)92 virtual void Update(void) {} 93 94 /// OnReceive is called for every packet. 95 /// \param[in] packet the packet that is being returned to the user 96 /// \return True to allow the game and other plugins to get this message, false to absorb it OnReceive(Packet * packet)97 virtual PluginReceiveResult OnReceive(Packet *packet) {(void) packet; return RR_CONTINUE_PROCESSING;} 98 99 /// Called when RakPeer is initialized OnRakPeerStartup(void)100 virtual void OnRakPeerStartup(void) {} 101 102 /// Called when RakPeer is shutdown OnRakPeerShutdown(void)103 virtual void OnRakPeerShutdown(void) {} 104 105 /// Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system 106 /// \param[in] systemAddress The system whose connection was closed 107 /// \param[in] rakNetGuid The guid of the specified system 108 /// \param[in] lostConnectionReason How the connection was closed: manually, connection lost, or notification of disconnection OnClosedConnection(SystemAddress systemAddress,RakNetGUID rakNetGUID,PI2_LostConnectionReason lostConnectionReason)109 virtual void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason ){(void) systemAddress; (void) rakNetGUID; (void) lostConnectionReason;} 110 111 /// Called when we got a new connection 112 /// \param[in] systemAddress Address of the new connection 113 /// \param[in] rakNetGuid The guid of the specified system 114 /// \param[in] isIncoming If true, this is ID_NEW_INCOMING_CONNECTION, or the equivalent OnNewConnection(SystemAddress systemAddress,RakNetGUID rakNetGUID,bool isIncoming)115 virtual void OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming) {(void) systemAddress; (void) rakNetGUID; (void) isIncoming;} 116 117 /// Called when a connection attempt fails 118 /// \param[in] packet Packet to be returned to the user 119 /// \param[in] failedConnectionReason Why the connection failed OnFailedConnectionAttempt(Packet * packet,PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)120 virtual void OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason) {(void) packet; (void) failedConnectionAttemptReason;} 121 122 /// Called on a send to the socket, per datagram, that does not go through the reliability layer 123 /// \param[in] data The data being sent 124 /// \param[in] bitsUsed How many bits long \a data is 125 /// \param[in] remoteSystemAddress Which system this message is being sent to OnDirectSocketSend(const char * data,const BitSize_t bitsUsed,SystemAddress remoteSystemAddress)126 virtual void OnDirectSocketSend(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;} 127 128 /// Called on a receive from the socket, per datagram, that does not go through the reliability layer 129 /// \param[in] data The data being sent 130 /// \param[in] bitsUsed How many bits long \a data is 131 /// \param[in] remoteSystemAddress Which system this message is being sent to OnDirectSocketReceive(const char * data,const BitSize_t bitsUsed,SystemAddress remoteSystemAddress)132 virtual void OnDirectSocketReceive(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;} 133 134 /// Called when the reliability layer rejects a send or receive 135 /// \param[in] bitsUsed How many bits long \a data is 136 /// \param[in] remoteSystemAddress Which system this message is being sent to OnReliabilityLayerPacketError(const char * errorMessage,const BitSize_t bitsUsed,SystemAddress remoteSystemAddress)137 virtual void OnReliabilityLayerPacketError(const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) errorMessage; (void) bitsUsed; (void) remoteSystemAddress;} 138 139 /// Called on a send or receive of a message within the reliability layer 140 /// \param[in] internalPacket The user message, along with all send data. 141 /// \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. 142 /// \param[in] remoteSystemAddress The player we sent or got this packet from 143 /// \param[in] time The current time as returned by RakNet::GetTime() 144 /// \param[in] isSend Is this callback representing a send event or receive event? OnInternalPacket(InternalPacket * internalPacket,unsigned frameNumber,SystemAddress remoteSystemAddress,RakNetTime time,int isSend)145 virtual void OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, RakNetTime time, int isSend) {(void) internalPacket; (void) frameNumber; (void) remoteSystemAddress; (void) time; (void) isSend;} 146 147 /// Called when we get an ack for a message we reliabily sent 148 /// \param[in] messageNumber The numerical identifier for which message this is 149 /// \param[in] remoteSystemAddress The player we sent or got this packet from 150 /// \param[in] time The current time as returned by RakNet::GetTime() OnAck(unsigned int messageNumber,SystemAddress remoteSystemAddress,RakNetTime time)151 virtual void OnAck(unsigned int messageNumber, SystemAddress remoteSystemAddress, RakNetTime time) {(void) messageNumber; (void) remoteSystemAddress; (void) time;} 152 153 /// System called RakPeerInterface::PushBackPacket 154 /// \param[in] data The data being sent 155 /// \param[in] bitsUsed How many bits long \a data is 156 /// \param[in] remoteSystemAddress The player we sent or got this packet from OnPushBackPacket(const char * data,const BitSize_t bitsUsed,SystemAddress remoteSystemAddress)157 virtual void OnPushBackPacket(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) {(void) data; (void) bitsUsed; (void) remoteSystemAddress;} 158 GetRakPeerInterface(void)159 RakPeerInterface *GetRakPeerInterface(void) const {return rakPeerInterface;} 160 161 /// \internal 162 void SetRakPeerInterface( RakPeerInterface *ptr ); 163 164 #if _RAKNET_SUPPORT_PacketizedTCP==1 165 /// \internal 166 void SetPacketizedTCP( PacketizedTCP *ptr ); 167 #endif 168 protected: 169 // Send through either rakPeerInterface or packetizedTCP, whichever is available 170 void SendUnified( const RakNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast ); 171 bool SendListUnified( const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast ); 172 173 Packet *AllocatePacketUnified(unsigned dataSize); 174 void PushBackPacketUnified(Packet *packet, bool pushAtHead); 175 void DeallocPacketUnified(Packet *packet); 176 177 // Filled automatically in when attached 178 RakPeerInterface *rakPeerInterface; 179 #if _RAKNET_SUPPORT_PacketizedTCP==1 180 PacketizedTCP *packetizedTCP; 181 #endif 182 }; 183 184 #endif 185 186