X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_rline.cpp;h=160092a63317772e7262943e07b0d9930c8cc930;hb=dc4c8c85f383567aef9325a08515c9890bd89ab8;hp=43cd31a2d993ea103251b53d0b7432dc82dac447;hpb=a4db7bf9af00b32d4f5c1922997d02b0b8be59e5;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index 43cd31a2d..160092a63 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -210,6 +210,9 @@ class CommandRLine : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { + if (IS_LOCAL(user)) + return ROUTE_LOCALONLY; // spanningtree will send ADDLINE + return ROUTE_BROADCAST; } }; @@ -221,9 +224,13 @@ class ModuleRLine : public Module RLineFactory f; CommandRLine r; bool MatchOnNickChange; + bool initing; + RegexFactory* factory; public: - ModuleRLine() : rxfactory(this, "regex"), f(rxfactory), r(this, f) + ModuleRLine() + : rxfactory(this, "regex"), f(rxfactory), r(this, f) + , initing(true) { } @@ -231,11 +238,11 @@ class ModuleRLine : public Module { OnRehash(NULL); - ServerInstance->AddCommand(&r); + ServerInstance->Modules->AddService(r); ServerInstance->XLines->RegisterFactory(&f); - Implementation eventlist[] = { I_OnUserConnect, I_OnRehash, I_OnUserPostNick, I_OnStats, I_OnBackgroundTimer }; - ServerInstance->Modules->Attach(eventlist, this, 5); + Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnUserPostNick, I_OnStats, I_OnBackgroundTimer, I_OnUnloadModule }; + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } virtual ~ModuleRLine() @@ -249,7 +256,7 @@ class ModuleRLine : public Module return Version("RLINE: Regexp user banning.", VF_COMMON | VF_VENDOR, rxfactory ? rxfactory->name : ""); } - virtual void OnUserConnect(LocalUser* user) + ModResult OnUserRegister(LocalUser* user) { // Apply lines on user connect XLine *rl = ServerInstance->XLines->MatchesLine("R", user); @@ -258,7 +265,9 @@ class ModuleRLine : public Module { // Bang. :P rl->Apply(user); + return MOD_RES_DENY; } + return MOD_RES_PASSTHRU; } virtual void OnRehash(User *user) @@ -269,14 +278,29 @@ class ModuleRLine : public Module ZlineOnMatch = tag->getBool("zlineonmatch"); std::string newrxengine = tag->getString("engine"); + factory = rxfactory ? (rxfactory.operator->()) : NULL; + if (newrxengine.empty()) rxfactory.SetProvider("regex"); else rxfactory.SetProvider("regex/" + newrxengine); + if (!rxfactory) { - ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", newrxengine.c_str()); + if (newrxengine.empty()) + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: No regex engine loaded - R-Line functionality disabled until this is corrected."); + else + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", newrxengine.c_str()); + + ServerInstance->XLines->DelAll(f.GetType()); } + else if ((!initing) && (rxfactory.operator->() != factory)) + { + ServerInstance->SNO->WriteToSnoMask('a', "Regex engine has changed, removing all R-Lines"); + ServerInstance->XLines->DelAll(f.GetType()); + } + + initing = false; } virtual ModResult OnStats(char symbol, User* user, string_list &results) @@ -314,6 +338,25 @@ class ModuleRLine : public Module } } + void OnUnloadModule(Module* mod) + { + // If the regex engine became unavailable or has changed, remove all rlines + if (!rxfactory) + { + ServerInstance->XLines->DelAll(f.GetType()); + } + else if (rxfactory.operator->() != factory) + { + factory = rxfactory.operator->(); + ServerInstance->XLines->DelAll(f.GetType()); + } + } + + void Prioritize() + { + Module* mod = ServerInstance->Modules->Find("m_cgiirc.so"); + ServerInstance->Modules->SetPriority(this, I_OnUserRegister, PRIORITY_AFTER, mod); + } }; MODULE_INIT(ModuleRLine)