diff --git a/inc/Controller/FloodManager.php b/inc/Controller/FloodManager.php new file mode 100644 index 00000000..c3231f33 --- /dev/null +++ b/inc/Controller/FloodManager.php @@ -0,0 +1,92 @@ +filterService = $filterService; + $this->floodService = $floodService; + $this->notes = $notes; + $this->logger = $logger; + } + + /** + * Processes an incoming post through the filter and flood system. + * + * Applies filters first. If a filter matches, returns the filter result + * If no filter matches, records a flood entry, purges old entries, and returns null. + * Handles critical errors internally. + * + * @param array $post The post data array. + * @return array|null The matching filter configuration if found, otherwise null. + * Returns null also if a critical error occurs during processing. + */ + public function processPost(array $post): ?array { + try { + $filterResult = $this->filterService->applyFilters($post); + + if ($filterResult !== null) { + if (isset($filterResult['add_note']) && $filterResult['add_note']) { + $this->notes->add( + $post['ip'], -1, 'Autoban message: ' . $post['body'] + ); + } + return $filterResult; + } + + $this->floodService->recordFloodEntry($post); + + $this->floodService->purgeOldEntries(); + + return null; + } catch (\Throwable $e) { + $this->logger->log( + LogDriver::ERROR, + "Critical error in flood filtering system: " . $e->getMessage() + ); + return null; + } + } +}