X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_rline.cpp;h=9bb1167f51810caad7d410989dc97e616a794d79;hb=9c4cc196c073145d4ad2ae92fb2be2194cf621f4;hp=aa96d4951d73433f818302103b87690385cc86ed;hpb=b36ce84c7da93f680fc397bcb4c877abe063eaaa;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index aa96d4951..9bb1167f5 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -20,8 +20,6 @@ */ -/* $ModDesc: RLINE: Regexp user banning. */ - #include "inspircd.h" #include "modules/regex.h" #include "xline.h" @@ -41,11 +39,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 */ @@ -59,29 +56,30 @@ class RLine : public XLine delete regex; } - bool Matches(User *u) + bool Matches(User* u) CXX11_OVERRIDE { LocalUser* lu = IS_LOCAL(u); if (lu && lu->exempt) return false; - std::string compare = u->nick + "!" + u->ident + "@" + u->host + " " + u->fullname; - return regex->Matches(compare); + const std::string host = u->nick + "!" + u->ident + "@" + u->GetRealHost() + " " + u->fullname; + const std::string ip = u->nick + "!" + u->ident + "@" + u->GetIPString() + " " + u->fullname; + return (regex->Matches(host) || regex->Matches(ip)); } - bool Matches(const std::string &compare) + bool Matches(const std::string& compare) CXX11_OVERRIDE { return regex->Matches(compare); } - void Apply(User* u) + void Apply(User* u) CXX11_OVERRIDE { if (ZlineOnMatch) { ZLine* zl = new ZLine(ServerInstance->Time(), duration ? expiry - ServerInstance->Time() : 0, ServerInstance->Config->ServerName.c_str(), reason.c_str(), u->GetIPString()); if (ServerInstance->XLines->AddLine(zl, NULL)) { - std::string timestr = ServerInstance->TimeString(zl->expiry); + std::string timestr = InspIRCd::TimeString(zl->expiry); ServerInstance->SNO->WriteToSnoMask('x', "Z-line added due to R-line match on *@%s%s%s: %s", zl->ipaddr.c_str(), zl->duration ? " to expire on " : "", zl->duration ? timestr.c_str() : "", zl->reason.c_str()); added_zline = true; @@ -92,7 +90,7 @@ class RLine : public XLine DefaultApply(u, "R", false); } - const std::string& Displayable() + const std::string& Displayable() CXX11_OVERRIDE { return matchtext; } @@ -115,7 +113,7 @@ class RLineFactory : public XLineFactory /** Generate a RLine */ - XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) CXX11_OVERRIDE { if (!rxfactory) { @@ -141,7 +139,7 @@ class CommandRLine : public Command flags_needed = 'o'; this->syntax = " [] :"; } - CmdResult Handle (const std::vector& parameters, User *user) + CmdResult Handle(const std::vector& parameters, User* user) CXX11_OVERRIDE { if (parameters.size() >= 3) @@ -157,7 +155,7 @@ class CommandRLine : public Command } catch (ModuleException &e) { - ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: %s", e.GetReason()); + ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: " + e.GetReason()); } if (r) @@ -171,7 +169,7 @@ class CommandRLine : public Command else { time_t c_requires_crap = duration + ServerInstance->Time(); - std::string timestr = ServerInstance->TimeString(c_requires_crap); + std::string timestr = InspIRCd::TimeString(c_requires_crap); ServerInstance->SNO->WriteToSnoMask('x', "%s added timed R-line for %s to expire on %s: %s", user->nick.c_str(), parameters[0].c_str(), timestr.c_str(), parameters[2].c_str()); } @@ -199,7 +197,7 @@ class CommandRLine : public Command return CMD_SUCCESS; } - RouteDescriptor GetRouting(User* user, const std::vector& parameters) + RouteDescriptor GetRouting(User* user, const std::vector& parameters) CXX11_OVERRIDE { if (IS_LOCAL(user)) return ROUTE_LOCALONLY; // spanningtree will send ADDLINE @@ -226,13 +224,7 @@ class ModuleRLine : public Module void init() CXX11_OVERRIDE { - OnRehash(NULL); - - ServerInstance->Modules->AddService(r); ServerInstance->XLines->RegisterFactory(&f); - - Implementation eventlist[] = { I_OnUserRegister, I_OnRehash, I_OnUserPostNick, I_OnStats, I_OnBackgroundTimer, I_OnUnloadModule }; - ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } ~ModuleRLine() @@ -260,7 +252,7 @@ class ModuleRLine : public Module return MOD_RES_PASSTHRU; } - void OnRehash(User *user) CXX11_OVERRIDE + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* tag = ServerInstance->Config->ConfValue("rline"); @@ -293,12 +285,12 @@ class ModuleRLine : public Module initing = false; } - ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE + ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE { - if (symbol != 'R') + if (stats.GetSymbol() != 'R') return MOD_RES_PASSTHRU; - ServerInstance->XLines->InvokeStats("R", 223, user, results); + ServerInstance->XLines->InvokeStats("R", 223, stats); return MOD_RES_DENY; } @@ -342,7 +334,7 @@ class ModuleRLine : public Module } } - void Prioritize() + void Prioritize() CXX11_OVERRIDE { Module* mod = ServerInstance->Modules->Find("m_cgiirc.so"); ServerInstance->Modules->SetPriority(this, I_OnUserRegister, PRIORITY_AFTER, mod);