SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes
MessageFilter
Plugins

Remote incoming packets from unauthorized systems. More...

## Classes

class | SLNet::MessageFilter
| Assigns systems to FilterSets. Each FilterSet limits what kinds of messages are allowed. More...

## Detailed Description

Remote incoming packets from unauthorized systems.

## Class Documentation

class SLNet::MessageFilter

Assigns systems to FilterSets. Each FilterSet limits what kinds of messages are allowed.

The MessageFilter plugin is used for security where you limit what systems can send what kind of messages.
You implicitly define FilterSets, and add allowed message IDs to these FilterSets.
You then add systems to these filters, such that those systems are limited to sending what the filters allows.
You can automatically assign systems to a filter.
You can automatically kick and possibly ban users that stay in a filter too long, or send the wrong message.
Each system is a member of either zero or one filters.
Add this plugin before any plugin you wish to filter (most likely just add this plugin before any other).

Definition at line 85 of file MessageFilter.h.

Inheritance diagram for SLNet::MessageFilter:

### Public Member Functions

| MessageFilter ()
virtual | ~MessageFilter ()
void | SetAutoAddNewConnectionsToFilter (int filterSetID)
void | SetAllowMessageID (bool allow, int messageIDStart, int messageIDEnd, int filterSetID)
void | SetAllowRPC4 (bool allow, const char *uniqueID, int filterSetID)
void | SetActionOnDisallowedMessage (bool kickOnDisallowed, bool banOnDisallowed, SLNet::TimeMS banTimeMS, int filterSetID)
void | SetDisallowedMessageCallback (int filterSetID, void *userData, void(*invalidMessageCallback)(RakPeerInterface *peer, AddressOrGUID addressOrGUID, int filterSetID, void *userData, unsigned char messageID))
void | SetTimeoutCallback (int filterSetID, void *userData, void(*invalidMessageCallback)(RakPeerInterface *peer, AddressOrGUID addressOrGUID, int filterSetID, void *userData))
void | SetFilterMaxTime (int allowedTimeMS, bool banOnExceed, SLNet::TimeMS banTimeMS, int filterSetID)
int | GetSystemFilterSet (AddressOrGUID addressOrGUID)
void | SetSystemFilterSet (AddressOrGUID addressOrGUID, int filterSetID)
unsigned | GetSystemCount (int filterSetID) const
unsigned | GetFilterSetCount (void) const
int | GetFilterSetIDByIndex (unsigned index)
void | DeleteFilterSet (int filterSetID)
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
Public Member Functions inherited from SLNet::PluginInterface2
| PluginInterface2 ()
virtual | ~PluginInterface2 ()
virtual void | OnAttach (void)
| Called when the interface is attached.
virtual void | OnDetach (void)
| Called when the interface is detached.
virtual void | OnRakPeerStartup (void)
| Called when RakPeer is initialized.
virtual void | OnRakPeerShutdown (void)
| Called when RakPeer is shutdown.
virtual void | OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
virtual bool | UsesReliabilityLayer (void) const
virtual void | OnDirectSocketSend (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnDirectSocketReceive (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnReliabilityLayerNotification (const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress, bool isError)
virtual void | OnInternalPacket (InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time, int isSend)
virtual void | OnAck (unsigned int messageNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time)
virtual void | OnPushBackPacket (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
RakPeerInterface * | GetRakPeerInterface (void) const
RakNetGUID | GetMyGUIDUnified (void) const
void | SetRakPeerInterface (RakPeerInterface *ptr)
void | SetTCPInterface (TCPInterface *ptr)

### Protected Member Functions

void | Clear (void)
void | DeallocateFilterSet (FilterSet *filterSet)
FilterSet * | GetFilterSetByID (int filterSetID)
void | OnInvalidMessage (FilterSet *filterSet, AddressOrGUID systemAddress, unsigned char messageID)
Protected Member Functions inherited from SLNet::PluginInterface2
void | SendUnified (const SLNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
void | SendUnified (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
bool | SendListUnified (const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
Packet * | AllocatePacketUnified (unsigned dataSize)
void | PushBackPacketUnified (Packet *packet, bool pushAtHead)
void | DeallocPacketUnified (Packet *packet)

### Protected Attributes

DataStructures::OrderedList < int, FilterSet *, FilterSetComp > | filterList
DataStructures::Hash < AddressOrGUID, FilteredSystem, 2048, AddressOrGUID::ToInteger > | systemList
int | autoAddNewConnectionsToFilter
SLNet::Time | whenLastTimeoutCheck
Protected Attributes inherited from SLNet::PluginInterface2
RakPeerInterface * | rakPeerInterface
TCPInterface * | tcpInterface

#### Constructor & Destructor Documentation

SLNet::MessageFilter::MessageFilter | ( |  | ) |

virtual SLNet::MessageFilter::~MessageFilter | ( |  | ) |

virtual

#### Member Function Documentation

void SLNet::MessageFilter::Clear | ( | void |  | ) |

protected

void SLNet::MessageFilter::DeallocateFilterSet | ( | FilterSet * | filterSet | ) |

protected

void SLNet::MessageFilter::DeleteFilterSet | ( | int | filterSetID | ) |

Delete a FilterSet. All systems formerly subscribed to this filter are now unrestricted.

Parameters

  [in] | filterSetID | The ID of the filter set to delete.

FilterSet* SLNet::MessageFilter::GetFilterSetByID | ( | int | filterSetID | ) |

protected

unsigned SLNet::MessageFilter::GetFilterSetCount | ( | void |  | ) | const

Returns the total number of filter sets.

Returns
  The total number of filter sets.

int SLNet::MessageFilter::GetFilterSetIDByIndex | ( | unsigned | index | ) |

Returns the ID of a filter set, by index

Parameters

  [in] | An | index between 0 and GetFilterSetCount()-1 inclusive

unsigned SLNet::MessageFilter::GetSystemCount | ( | int | filterSetID | ) | const

Returns the number of systems subscribed to a particular filter set Using anything other than -1 for filterSetID is slow, so you should store the returned value.

Parameters

  [in] | filterSetID | The filter set to limit to. Use -1 for none (just returns the total number of filter systems in that case).

int SLNet::MessageFilter::GetSystemFilterSet | ( | AddressOrGUID | addressOrGUID | ) |

Get the filterSetID a system is using. Returns -1 for none.

Parameters

  [in] | addressOrGUID | The system we are referring to

virtual void SLNet::MessageFilter::OnClosedConnection | ( | const SystemAddress & | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | PI2_LostConnectionReason | lostConnectionReason
| ) |  |

virtual

Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system

Parameters

  [in] | systemAddress | The system whose connection was closed
  [in] | rakNetGuid | The guid of the specified system
  [in] | lostConnectionReason | How the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from SLNet::PluginInterface2.

void SLNet::MessageFilter::OnInvalidMessage | ( | FilterSet * | filterSet,
|  | AddressOrGUID | systemAddress,
|  | unsigned char | messageID
| ) |  |

protected

virtual void SLNet::MessageFilter::OnNewConnection | ( | const SystemAddress & | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | bool | isIncoming
| ) |  |

virtual

Called when we got a new connection

Parameters

  [in] | systemAddress | Address of the new connection
  [in] | rakNetGuid | The guid of the specified system
  [in] | isIncoming | If true, this is ID_NEW_INCOMING_CONNECTION, or the equivalent

Reimplemented from SLNet::PluginInterface2.

virtual PluginReceiveResult SLNet::MessageFilter::OnReceive | ( | Packet * | packet | ) |

virtual

OnReceive is called for every packet.

Parameters

  [in] | packet | the packet that is being returned to the user

Returns
  True to allow the game and other plugins to get this message, false to absorb it

Reimplemented from SLNet::PluginInterface2.

void SLNet::MessageFilter::SetActionOnDisallowedMessage | ( | bool | kickOnDisallowed,
|  | bool | banOnDisallowed,
|  | SLNet::TimeMS | banTimeMS,
|  | int | filterSetID
| ) |  |

What action to take on a disallowed message. You can kick or not. You can add them to the ban list for some time By default no action is taken. The message is simply ignored. param[in] 0 for permanent ban, >0 for ban time in milliseconds.

Parameters

  [in] | kickOnDisallowed | kick the system that sent a disallowed message.
  [in] | banOnDisallowed | ban the system that sent a disallowed message. See banTimeMS for the ban duration
  [in] | banTimeMS | Passed to the milliseconds parameter of RakPeer::AddToBanList.
  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings.

void SLNet::MessageFilter::SetAllowMessageID | ( | bool | allow,
|  | int | messageIDStart,
|  | int | messageIDEnd,
|  | int | filterSetID
| ) |  |

Allow a range of message IDs Always allowed by default: ID_CONNECTION_REQUEST_ACCEPTED through ID_DOWNLOAD_PROGRESS Usually you specify a range to make it easier to add new enumerations without having to constantly refer back to this function.

Parameters

  [in] | allow | True to allow this message ID, false to disallow. By default, all messageIDs except the noted types are disallowed. This includes messages from other plugins!
  [in] | messageIDStart | The first ID_* message to allow in the range. Inclusive.
  [in] | messageIDEnd | The last ID_* message to allow in the range. Inclusive.
  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings.

void SLNet::MessageFilter::SetAllowRPC4 | ( | bool | allow,
|  | const char * | uniqueID,
|  | int | filterSetID
| ) |  |

Allow a specific RPC4 call

Precondition
  MessageFilter must be attached before RPC4

Parameters

  [in] | uniqueID | Identifier passed to RegisterFunction()
  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings.

void SLNet::MessageFilter::SetAutoAddNewConnectionsToFilter | ( | int | filterSetID | ) |

Automatically add all new systems to a particular filter Defaults to -1

Parameters

  [in] | filterSetID | Which filter to add new systems to. <0 for do not add.

void SLNet::MessageFilter::SetDisallowedMessageCallback | ( | int | filterSetID,
|  | void * | userData,
|  | void(*)(RakPeerInterface *peer, AddressOrGUID addressOrGUID, int filterSetID, void *userData, unsigned char messageID) | invalidMessageCallback
| ) |  |

Set a user callback to be called on an invalid message for a particular filterSet

Parameters

  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings.
  [in] | userData | A pointer passed with the callback
  [in] | invalidMessageCallback | A pointer to a C function to be called back with the specified parameters.

void SLNet::MessageFilter::SetFilterMaxTime | ( | int | allowedTimeMS,
|  | bool | banOnExceed,
|  | SLNet::TimeMS | banTimeMS,
|  | int | filterSetID
| ) |  |

Limit how long a connection can stay in a particular filterSetID. After this time, the connection is kicked and possibly banned. By default there is no limit to how long a connection can stay in a particular filter set.

Parameters

  [in] | allowedTimeMS | How many milliseconds to allow a connection to stay in this filter set.
  [in] | banOnExceed | True or false to ban the system, or not, when allowedTimeMS is exceeded
  [in] | banTimeMS | Passed to the milliseconds parameter of RakPeer::AddToBanList.
  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings.

void SLNet::MessageFilter::SetSystemFilterSet | ( | AddressOrGUID | addressOrGUID,
|  | int | filterSetID
| ) |  |

Assign a system to a filter set. Systems are automatically added to filter sets (or not) based on SetAutoAddNewConnectionsToFilter() This function is used to change the filter set a system is using, to add it to a new filter set, or to remove it from all existin filter sets.

Parameters

  [in] | addressOrGUID | The system we are referring to
  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings. If -1, the system will be removed from all filter sets.

void SLNet::MessageFilter::SetTimeoutCallback | ( | int | filterSetID,
|  | void * | userData,
|  | void(*)(RakPeerInterface *peer, AddressOrGUID addressOrGUID, int filterSetID, void *userData) | invalidMessageCallback
| ) |  |

Set a user callback to be called when a user is disconnected due to SetFilterMaxTime

Parameters

  [in] | filterSetID | A user defined ID to represent a filter set. If no filter with this ID exists, one will be created with default settings.
  [in] | userData | A pointer passed with the callback
  [in] | invalidMessageCallback | A pointer to a C function to be called back with the specified parameters.

virtual void SLNet::MessageFilter::Update | ( | void |  | ) |

virtual

Update is called every time a packet is checked for .

Reimplemented from SLNet::PluginInterface2.

#### Member Data Documentation

int SLNet::MessageFilter::autoAddNewConnectionsToFilter

protected

Definition at line 195 of file MessageFilter.h.

DataStructures::OrderedList<int, FilterSet*, FilterSetComp> SLNet::MessageFilter::filterList

protected

Definition at line 191 of file MessageFilter.h.

DataStructures::Hash<AddressOrGUID, FilteredSystem, 2048, AddressOrGUID::ToInteger> SLNet::MessageFilter::systemList

protected

Definition at line 193 of file MessageFilter.h.

SLNet::Time SLNet::MessageFilter::whenLastTimeoutCheck

protected

Definition at line 196 of file MessageFilter.h.