From 454c8d374955d2ffb3ec1fca39a6efc32032c649 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 7 Apr 2018 15:07:24 +0100 Subject: Move OnStats from the core to a cross-module event. Some core code still exists in the XLine system but this will be replaced when the XLine system is replaced later. --- include/inspircd.h | 1 - include/modules.h | 9 +-------- include/modules/stats.h | 18 ++++++++++++++++++ src/coremods/core_stats.cpp | 14 ++++++++++++-- src/coremods/core_whowas.cpp | 7 +++++-- src/modules.cpp | 1 - src/modules/extra/m_geoip.cpp | 6 ++++-- src/modules/m_cban.cpp | 7 +++++-- src/modules/m_dnsbl.cpp | 6 ++++-- src/modules/m_filter.cpp | 4 +++- src/modules/m_hideoper.cpp | 6 ++++-- src/modules/m_rline.cpp | 8 ++++++-- src/modules/m_shun.cpp | 7 +++++-- src/modules/m_spanningtree/main.cpp | 5 ++++- src/modules/m_spanningtree/main.h | 3 ++- src/modules/m_svshold.cpp | 7 +++++-- src/xline.cpp | 1 + 17 files changed, 79 insertions(+), 31 deletions(-) diff --git a/include/inspircd.h b/include/inspircd.h index 95da70e54..0f73f192f 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -578,4 +578,3 @@ inline void stdalgo::culldeleter::operator()(classbase* item) #include "numericbuilder.h" #include "modules/whois.h" -#include "modules/stats.h" diff --git a/include/modules.h b/include/modules.h index a5e546149..72aa7b4d7 100644 --- a/include/modules.h +++ b/include/modules.h @@ -220,7 +220,7 @@ enum Implementation I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnLoadModule, I_OnUnloadModule, I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite, I_OnRawMode, I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnCheckChannelBan, I_OnExtBanCheck, - I_OnStats, I_OnChangeLocalUserHost, I_OnPreTopicChange, + I_OnChangeLocalUserHost, I_OnPreTopicChange, I_OnPostTopicChange, I_OnPostConnect, I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSetAway, I_OnPostCommand, I_OnPostJoin, @@ -815,13 +815,6 @@ class CoreExport Module : public classbase, public usecountbase */ virtual ModResult OnExtBanCheck(User* user, Channel* chan, char type); - /** Called on all /STATS commands - * This method is triggered for all /STATS use, including stats symbols handled by the core. - * @param stats Context of the /STATS request, contains requesting user, list of answer rows etc. - * @return 1 to block the /STATS from being processed by the core, 0 to allow it - */ - virtual ModResult OnStats(Stats::Context& stats); - /** Called whenever a change of a local users displayed host is attempted. * Return 1 to deny the host change, or 0 to allow it. * @param user The user whos host will be changed diff --git a/include/modules/stats.h b/include/modules/stats.h index d2f6eabbb..e69070c9f 100644 --- a/include/modules/stats.h +++ b/include/modules/stats.h @@ -19,12 +19,30 @@ #pragma once +#include "event.h" + namespace Stats { class Context; + class EventListener; class Row; } +class Stats::EventListener : public Events::ModuleEventListener +{ + public: + EventListener(Module* mod) + : ModuleEventListener(mod, "event/stats") + { + } + + /** Called when the STATS command is executed. + * @param stats Context of the /STATS request, contains requesting user, list of answer rows etc. + * @return MOD_RES_DENY if the stats request has been fulfilled. Otherwise, MOD_RES_PASSTHRU. + */ + virtual ModResult OnStats(Stats::Context& stats) = 0; +}; + class Stats::Row : public Numeric::Numeric { public: diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index d14aef154..5642cd52e 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -21,6 +21,7 @@ #include "inspircd.h" #include "xline.h" +#include "modules/stats.h" #ifdef _WIN32 #include @@ -31,11 +32,20 @@ */ class CommandStats : public Command { + Events::ModuleEventProvider statsevprov; void DoStats(Stats::Context& stats); + public: /** Constructor for stats. */ - CommandStats ( Module* parent) : Command(parent,"STATS",1,2) { allow_empty_last_param = false; syntax = " []"; } + CommandStats(Module* Creator) + : Command(Creator, "STATS", 1, 2) + , statsevprov(Creator, "event/stats") + { + allow_empty_last_param = false; + syntax = " []"; + } + /** Handle command. * @param parameters The parameters to the command * @param user The user issuing the command @@ -82,7 +92,7 @@ void CommandStats::DoStats(Stats::Context& stats) } ModResult MOD_RESULT; - FIRST_MOD_RESULT(OnStats, MOD_RESULT, (stats)); + FIRST_MOD_RESULT_CUSTOM(statsevprov, Stats::EventListener, OnStats, MOD_RESULT, (stats)); if (MOD_RESULT == MOD_RES_DENY) { stats.AddRow(219, statschar, "End of /STATS report"); diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index f456a57db..689340a8d 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "commands/cmd_whowas.h" +#include "modules/stats.h" enum { @@ -260,12 +261,14 @@ WhoWas::Nick::~Nick() stdalgo::delete_all(entries); } -class ModuleWhoWas : public Module +class ModuleWhoWas : public Module, public Stats::EventListener { CommandWhowas cmd; public: - ModuleWhoWas() : cmd(this) + ModuleWhoWas() + : Stats::EventListener(this) + , cmd(this) { } diff --git a/src/modules.cpp b/src/modules.cpp index ec793c64f..5f8439c44 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -107,7 +107,6 @@ ModResult Module::OnCheckLimit(User*, Channel*) { DetachEvent(I_OnCheckLimit); r ModResult Module::OnCheckChannelBan(User*, Channel*) { DetachEvent(I_OnCheckChannelBan); return MOD_RES_PASSTHRU; } ModResult Module::OnCheckBan(User*, Channel*, const std::string&) { DetachEvent(I_OnCheckBan); return MOD_RES_PASSTHRU; } ModResult Module::OnExtBanCheck(User*, Channel*, char) { DetachEvent(I_OnExtBanCheck); return MOD_RES_PASSTHRU; } -ModResult Module::OnStats(Stats::Context&) { DetachEvent(I_OnStats); return MOD_RES_PASSTHRU; } ModResult Module::OnChangeLocalUserHost(LocalUser*, const std::string&) { DetachEvent(I_OnChangeLocalUserHost); return MOD_RES_PASSTHRU; } ModResult Module::OnChangeLocalUserGECOS(LocalUser*, const std::string&) { DetachEvent(I_OnChangeLocalUserGECOS); return MOD_RES_PASSTHRU; } ModResult Module::OnPreTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPreTopicChange); return MOD_RES_PASSTHRU; } diff --git a/src/modules/extra/m_geoip.cpp b/src/modules/extra/m_geoip.cpp index 35efc8d70..b6b0c3fa1 100644 --- a/src/modules/extra/m_geoip.cpp +++ b/src/modules/extra/m_geoip.cpp @@ -27,6 +27,7 @@ #include "inspircd.h" #include "xline.h" +#include "modules/stats.h" // Fix warnings about the use of commas at end of enumerator lists on C++03. #if defined __clang__ @@ -47,7 +48,7 @@ enum RPL_WHOISCOUNTRY = 344 }; -class ModuleGeoIP : public Module, public Whois::EventListener +class ModuleGeoIP : public Module, public Stats::EventListener, public Whois::EventListener { StringExtItem ext; bool extban; @@ -65,7 +66,8 @@ class ModuleGeoIP : public Module, public Whois::EventListener public: ModuleGeoIP() - : Whois::EventListener(this) + : Stats::EventListener(this) + , Whois::EventListener(this) , ext("geoip_cc", ExtensionItem::EXT_USER, this) , extban(true) , gi(NULL) diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp index 54b1e39ee..7235a8bef 100644 --- a/src/modules/m_cban.cpp +++ b/src/modules/m_cban.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "xline.h" +#include "modules/stats.h" /** Holds a CBAN item */ @@ -140,13 +141,15 @@ class CommandCBan : public Command } }; -class ModuleCBan : public Module +class ModuleCBan : public Module, public Stats::EventListener { CommandCBan mycommand; CBanFactory f; public: - ModuleCBan() : mycommand(this) + ModuleCBan() + : Stats::EventListener(this) + , mycommand(this) { } diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index 732717ff3..ab24873ce 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -24,6 +24,7 @@ #include "inspircd.h" #include "xline.h" #include "modules/dns.h" +#include "modules/stats.h" /* Class holding data for a single entry */ class DNSBLConfEntry : public refcountbase @@ -220,7 +221,7 @@ class DNSBLResolver : public DNS::Request } }; -class ModuleDNSBL : public Module +class ModuleDNSBL : public Module, public Stats::EventListener { std::vector > DNSBLConfEntries; dynamic_reference DNS; @@ -247,7 +248,8 @@ class ModuleDNSBL : public Module } public: ModuleDNSBL() - : DNS(this, "DNS") + : Stats::EventListener(this) + , DNS(this, "DNS") , nameExt("dnsbl_match", ExtensionItem::EXT_USER, this) , countExt("dnsbl_pending", ExtensionItem::EXT_USER, this) { diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 8ad692971..d3d3ef218 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -25,6 +25,7 @@ #include "modules/regex.h" #include "modules/server.h" #include "modules/shun.h" +#include "modules/stats.h" enum FilterFlags { @@ -160,7 +161,7 @@ class CommandFilter : public Command } }; -class ModuleFilter : public Module, public ServerEventListener +class ModuleFilter : public Module, public ServerEventListener, public Stats::EventListener { typedef insp::flat_set ExemptTargetSet; @@ -302,6 +303,7 @@ bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags) ModuleFilter::ModuleFilter() : ServerEventListener(this) + , Stats::EventListener(this) , initing(true) , filtcommand(this) , RegexEngine(this, "regex") diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp index 2e0b388cf..6ecfc6074 100644 --- a/src/modules/m_hideoper.cpp +++ b/src/modules/m_hideoper.cpp @@ -20,6 +20,7 @@ #include "inspircd.h" +#include "modules/stats.h" /** Handles user mode +H */ @@ -48,13 +49,14 @@ class HideOper : public SimpleUserModeHandler } }; -class ModuleHideOper : public Module, public Whois::LineEventListener +class ModuleHideOper : public Module, public Stats::EventListener, public Whois::LineEventListener { HideOper hm; bool active; public: ModuleHideOper() - : Whois::LineEventListener(this) + : Stats::EventListener(this) + , Whois::LineEventListener(this) , hm(this) , active(false) { diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index 9bb1167f5..e3a84397f 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "modules/regex.h" +#include "modules/stats.h" #include "xline.h" static bool ZlineOnMatch = false; @@ -206,7 +207,7 @@ class CommandRLine : public Command } }; -class ModuleRLine : public Module +class ModuleRLine : public Module, public Stats::EventListener { dynamic_reference rxfactory; RLineFactory f; @@ -217,7 +218,10 @@ class ModuleRLine : public Module public: ModuleRLine() - : rxfactory(this, "regex"), f(rxfactory), r(this, f) + : Stats::EventListener(this) + , rxfactory(this, "regex") + , f(rxfactory) + , r(this, f) , initing(true) { } diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp index 5b0b42cae..92c0b0bd0 100644 --- a/src/modules/m_shun.cpp +++ b/src/modules/m_shun.cpp @@ -23,6 +23,7 @@ #include "inspircd.h" #include "xline.h" #include "modules/shun.h" +#include "modules/stats.h" /** An XLineFactory specialized to generate shun pointers @@ -133,7 +134,7 @@ class CommandShun : public Command } }; -class ModuleShun : public Module +class ModuleShun : public Module, public Stats::EventListener { CommandShun cmd; ShunFactory f; @@ -142,7 +143,9 @@ class ModuleShun : public Module bool affectopers; public: - ModuleShun() : cmd(this) + ModuleShun() + : Stats::EventListener(this) + , cmd(this) { } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 1a77237bd..2fd578698 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -37,7 +37,10 @@ #include "translate.h" ModuleSpanningTree::ModuleSpanningTree() - : rconnect(this), rsquit(this), map(this) + : Stats::EventListener(this) + , rconnect(this) + , rsquit(this) + , map(this) , commands(this) , currmembid(0) , eventprov(this, "event/server") diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 4eefb01a0..5add15e8a 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -26,6 +26,7 @@ #include "inspircd.h" #include "event.h" #include "modules/dns.h" +#include "modules/stats.h" #include "servercommand.h" #include "commands.h" #include "protocolinterface.h" @@ -52,7 +53,7 @@ class Autoconnect; /** This is the main class for the spanningtree module */ -class ModuleSpanningTree : public Module +class ModuleSpanningTree : public Module, public Stats::EventListener { /** Client to server commands, registered in the core */ diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp index 1ba16f3f4..481a1aaba 100644 --- a/src/modules/m_svshold.cpp +++ b/src/modules/m_svshold.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "xline.h" +#include "modules/stats.h" namespace { @@ -161,14 +162,16 @@ class CommandSvshold : public Command } }; -class ModuleSVSHold : public Module +class ModuleSVSHold : public Module, public Stats::EventListener { CommandSvshold cmd; SVSHoldFactory s; public: - ModuleSVSHold() : cmd(this) + ModuleSVSHold() + : Stats::EventListener(this) + , cmd(this) { } diff --git a/src/xline.cpp b/src/xline.cpp index 8d4c822aa..dfd7e2903 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -23,6 +23,7 @@ #include "inspircd.h" #include "xline.h" +#include "modules/stats.h" /** An XLineFactory specialized to generate GLine* pointers */ -- cgit v1.2.3