{"id":2304,"date":"2023-01-26T10:27:22","date_gmt":"2023-01-26T10:27:22","guid":{"rendered":"https:\/\/smartfoxserver.com\/blog\/?p=2304"},"modified":"2024-04-19T14:57:17","modified_gmt":"2024-04-19T14:57:17","slug":"new-in-2-19-extension-flood-filter","status":"publish","type":"post","link":"https:\/\/smartfoxserver.com\/blog\/new-in-2-19-extension-flood-filter\/","title":{"rendered":"New in 2.19: Extension Flood Filter"},"content":{"rendered":"\n<p>With the release of <strong>SmartFoxServer 2.19.0<\/strong> we have introduced a new <strong>Extension Flood Filter<\/strong> that provides fine grained control over the packet rate of Extension requests: it can be used to limit the number of calls per second for specific requests and automatically set rules for warning and banning the offending client(s).<\/p>\n\n\n\n<p>It also includes the ability to catch <strong>unknown Extension calls<\/strong> (i.e. requests for which there doesn&#8217;t exist a request handler) and apply auto-ban rules as well.<\/p>\n\n\n\n<p>Under normal circumstances, e.g. users playing with the official client app, there shouldn&#8217;t be a concern about request spam: limitations can be easily coded in the client itself. However it&#8217;s also relatively easy for malicious users to reverse engineer a client made in Javascript, Unity or Java and bypass such limitations.<\/p>\n\n\n\n<h2 id=\"overview\">Overview<\/h2>\n\n\n\n<p>In the diagram below we show a bird&#8217;s eye view of the filter and its position in the Extension invocation chain. For each request handler defined in our Extension code (via the&nbsp;<em>addRequestHandler<\/em>&nbsp;methods) we can set a limit expressed in number of&nbsp;<strong>calls per second<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image noShadow\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter.jpg\"><img loading=\"lazy\" src=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter-1024x759.jpg\" alt=\"Extension Flood Filter\" class=\"wp-image-2306\" width=\"715\" height=\"529\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter-1024x759.jpg 1024w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter-300x222.jpg 300w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter-768x569.jpg 768w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter-1536x1138.jpg 1536w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter-624x462.jpg 624w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2023\/01\/extFloodFilter.jpg 1798w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>In this example we have defined a&nbsp;<strong>playerShoot<\/strong>&nbsp;request handler and we&#8217;ve also set a limit of 4 requests\/sec. If a client sends 20 calls in one second only the&nbsp;<strong>first 4 will be passed to the Extension<\/strong>&nbsp;and processed, while the rest will be discarded. Additionally, based on the auto-ban rules, the sender will either be warned or banned.<\/p>\n\n\n\n<h2 id=\"usage\">Usage<\/h2>\n\n\n\n<p>The Extension Flood Filter is&nbsp;<strong>inactive by default<\/strong>. To activate it we need to call the&nbsp;<strong>initFloodFilter(&#8230;)<\/strong>&nbsp;method available from the parent&nbsp;<strong>SFSExtension<\/strong>&nbsp;class.<\/p>\n\n\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class AntiFloodTestExtension extends SFSExtension\n{\n    static final String PLAYER_SHOOT = &quot;pShoot&quot;;\n    static final String PLAYER_MOVE = &quot;pMove&quot;;\n \n    @Override\n    public void init()\n    {\n        ExtensionFloodFilterConfig cfg = new ExtensionFloodFilterConfig();\n        cfg.banDurationMinutes = 120;\n        cfg.maxFloodingAttempts = 3;\n        cfg.secondsBeforeBan = 2;\n        cfg.banMessage = &quot;You are now banned. Reason: request flooding.&quot;;\n        cfg.filterRules = Map.of\n                        (\n                            PLAYER_SHOOT, 4, \n                            PLAYER_MOVE, 15\n                        );\n     \n        initFloodFilter(cfg);\n     \n        addRequestHandler(PLAYER_SHOOT, (sender, param) -&amp;gt; {\n         \n            trace(&quot;Shooting&quot;);\n     \n        });\n     \n        addRequestHandler(PLAYER_MOVE, (sender, param) -&amp;gt; {\n         \n            trace(&quot;Moving&quot;);\n     \n        });\n    }\n}\n<\/pre>\n\n\n\n<p>The initializer method takes a&nbsp;<strong>ExtensionFloodFilterConfig<\/strong>&nbsp;object with with a number of properties for warning and banning clients.<\/p>\n\n\n\n<p>For more details on each setting, default values and further details please check our <a href=\"http:\/\/docs2x.smartfoxserver.com\/AdvancedTopics\/extension-flood-filter\" target=\"_blank\" rel=\"noreferrer noopener\">documentation website here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the release of SmartFoxServer 2.19.0 we have introduced a new Extension Flood Filter that provides fine grained control over the packet rate of Extension requests: it can be used to limit the number of calls per second for specific requests and automatically set rules for warning and banning the offending client(s). It also includes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[159,156,157,158,31,154,46,155],"_links":{"self":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/2304"}],"collection":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/comments?post=2304"}],"version-history":[{"count":10,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/2304\/revisions"}],"predecessor-version":[{"id":2387,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/2304\/revisions\/2387"}],"wp:attachment":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/media?parent=2304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/categories?post=2304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/tags?post=2304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}