X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_rline.cpp;h=d1ab5d9ba42cc35645ca77b54170a315f4319046;hb=a785f350fd584d87f3b84bbaff569ecb59c29f04;hp=551156732dc9838cdd81e7b1fc7631d94e864110;hpb=02859be56d43bcece02aab350e02bc95ed1bf446;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index 551156732..d1ab5d9ba 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -41,11 +41,10 @@ class RLine : public XLine * @param regex Pattern to match with * @ */ - RLine(time_t s_time, long d, std::string src, std::string re, std::string regexs, dynamic_reference& rxfactory) + RLine(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& regexs, dynamic_reference& rxfactory) : XLine(s_time, d, src, re, "R") + , matchtext(regexs) { - matchtext = regexs; - /* This can throw on failure, but if it does we DONT catch it here, we catch it and display it * where the object is created, we might not ALWAYS want it to output stuff to snomask x all the time */ @@ -210,7 +209,10 @@ class CommandRLine : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - return ROUTE_LOCALONLY; + if (IS_LOCAL(user)) + return ROUTE_LOCALONLY; // spanningtree will send ADDLINE + + return ROUTE_BROADCAST; } }; @@ -221,9 +223,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 +237,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 +255,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,25 +264,42 @@ class ModuleRLine : public Module { // Bang. :P rl->Apply(user); + return MOD_RES_DENY; } + return MOD_RES_PASSTHRU; } virtual void OnRehash(User *user) { - ConfigReader Conf; + ConfigTag* tag = ServerInstance->Config->ConfValue("rline"); + + MatchOnNickChange = tag->getBool("matchonnickchange"); + ZlineOnMatch = tag->getBool("zlineonmatch"); + std::string newrxengine = tag->getString("engine"); - MatchOnNickChange = Conf.ReadFlag("rline", "matchonnickchange", 0); - ZlineOnMatch = Conf.ReadFlag("rline", "zlineonmatch", 0); - std::string newrxengine = Conf.ReadValue("rline", "engine", 0); + 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 +337,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)