SLikeNet 0.1.3

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MessageFilter.h
Go to the documentation of this file.
1 /*
2 * Original work: 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 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20 #include "NativeFeatureIncludes.h"
21 #if _RAKNET_SUPPORT_MessageFilter==1
22
23 #ifndef __MESSAGE_FILTER_PLUGIN_H
24 #define __MESSAGE_FILTER_PLUGIN_H
25
26 #include "types.h"
27 #include "PluginInterface2.h"
28 #include "DS_OrderedList.h"
29 #include "DS_Hash.h"
30 #include "Export.h"
31
33 #define MESSAGE_FILTER_MAX_MESSAGE_ID 256
34
35 namespace SLNet
36 {
38 class RakPeerInterface;
39
41 int RAK_DLL_EXPORT MessageFilterStrComp( char *const &key,char *const &data );
42
44 struct FilterSet
45 {
46 bool banOnFilterTimeExceed;
47 bool kickOnDisallowedMessage;
48 bool banOnDisallowedMessage;
49 SLNet::TimeMS disallowedMessageBanTimeMS;
50 SLNet::TimeMS timeExceedBanTimeMS;
51 SLNet::TimeMS maxMemberTimeMS;
52 void (*invalidMessageCallback)(RakPeerInterface *peer, AddressOrGUID systemAddress, int filterSetID, void *userData, unsigned char messageID);
53 void *disallowedCallbackUserData;
54 void (*timeoutCallback)(RakPeerInterface *peer, AddressOrGUID systemAddress, int filterSetID, void *userData);
55 void *timeoutUserData;
56 int filterSetID;
57 bool allowedIDs[MESSAGE_FILTER_MAX_MESSAGE_ID];
58 DataStructures::OrderedList<SLNet::RakString, SLNet::RakString> allowedRPC4;
59 };
60
62 int RAK_DLL_EXPORT FilterSetComp( const int &key, FilterSet * const &data );
63
65 struct FilteredSystem
66 {
67 FilterSet *filter;
68 SLNet::TimeMS timeEnteredThisSet;
69 };
70
75
85 class RAK_DLL_EXPORT MessageFilter : public PluginInterface2
86 {
87 public:
88
89 // GetInstance() and DestroyInstance(instance*)
90 STATIC_FACTORY_DECLARATIONS(MessageFilter)
91
92 MessageFilter();
93 virtual ~MessageFilter();
94
95 // --------------------------------------------------------------------------------------------
96 // User functions
97 // --------------------------------------------------------------------------------------------
98
102 void SetAutoAddNewConnectionsToFilter(int filterSetID);
103
111 void SetAllowMessageID(bool allow, int messageIDStart, int messageIDEnd,int filterSetID);
112
117 void SetAllowRPC4(bool allow, const char* uniqueID, int filterSetID);
118
126 void SetActionOnDisallowedMessage(bool kickOnDisallowed, bool banOnDisallowed, SLNet::TimeMS banTimeMS, int filterSetID);
127
132 void SetDisallowedMessageCallback(int filterSetID, void *userData, void (*invalidMessageCallback)(RakPeerInterface *peer, AddressOrGUID addressOrGUID, int filterSetID, void *userData, unsigned char messageID));
133
138 void SetTimeoutCallback(int filterSetID, void *userData, void (*invalidMessageCallback)(RakPeerInterface *peer, AddressOrGUID addressOrGUID, int filterSetID, void *userData));
139
146 void SetFilterMaxTime(int allowedTimeMS, bool banOnExceed, SLNet::TimeMS banTimeMS, int filterSetID);
147
150 int GetSystemFilterSet(AddressOrGUID addressOrGUID);
151
157 void SetSystemFilterSet(AddressOrGUID addressOrGUID, int filterSetID);
158
162 unsigned GetSystemCount(int filterSetID) const;
163
166 unsigned GetFilterSetCount(void) const;
167
170 int GetFilterSetIDByIndex(unsigned index);
171
174 void DeleteFilterSet(int filterSetID);
175
176 // --------------------------------------------------------------------------------------------
177 // Packet handling functions
178 // --------------------------------------------------------------------------------------------
179 virtual void Update(void);
180 virtual PluginReceiveResult OnReceive(Packet *packet);
181 virtual void OnNewConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming);
182 virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
183
184 protected:
185
186 void Clear(void);
187 void DeallocateFilterSet(FilterSet *filterSet);
188 FilterSet* GetFilterSetByID(int filterSetID);
189 void OnInvalidMessage(FilterSet *filterSet, AddressOrGUID systemAddress, unsigned char messageID);
190
191 DataStructures::OrderedList<int, FilterSet*, FilterSetComp> filterList;
192 // Change to guid
193 DataStructures::Hash<AddressOrGUID, FilteredSystem, 2048, AddressOrGUID::ToInteger> systemList;
194
195 int autoAddNewConnectionsToFilter;
196 SLNet::Time whenLastTimeoutCheck;
197 };
198
199 } // namespace SLNet
200
201 #endif
202
203 #endif // _RAKNET_SUPPORT_*