- PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat, const std::string &flags)
- : FilterResult(pat, rea, act, gline_time, flags), regexp(r)
- {
- }
+ /** Create a R-line.
+ * @param s_time The set time
+ * @param d The duration of the xline
+ * @param src The sender of the xline
+ * @param re The reason of the xline
+ * @param regex Pattern to match with
+ * @
+ */
+ RLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& regexs, dynamic_reference<RegexFactory>& rxfactory)
+ : XLine(s_time, d, src, re, "R")
+ , 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
+ */
+ regex = rxfactory->Create(regexs);
+ }
+
+ /** Destructor
+ */
+ ~RLine()
+ {
+ delete regex;
+ }
+
+ bool Matches(User* u) CXX11_OVERRIDE
+ {
+ LocalUser* lu = IS_LOCAL(u);
+ if (lu && lu->exempt)
+ return false;
+
+ const std::string host = u->nick + "!" + u->ident + "@" + u->GetRealHost() + " " + u->GetRealName();
+ const std::string ip = u->nick + "!" + u->ident + "@" + u->GetIPString() + " " + u->GetRealName();
+ return (regex->Matches(host) || regex->Matches(ip));
+ }
+
+ bool Matches(const std::string& compare) CXX11_OVERRIDE
+ {
+ return regex->Matches(compare);
+ }
+
+ 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 expirystr = zl->duration ? InspIRCd::Format(" to expire in %s (on %s)", InspIRCd::DurationString(zl->duration).c_str(), InspIRCd::TimeString(zl->expiry).c_str()) : "";
+ ServerInstance->SNO->WriteToSnoMask('x', "Z-line added due to R-line match on %s%s: %s",
+ zl->ipaddr.c_str(), expirystr.c_str(), zl->reason.c_str());
+ added_zline = true;
+ }
+ else
+ delete zl;
+ }
+ DefaultApply(u, "R", false);
+ }
+
+ const std::string& Displayable() CXX11_OVERRIDE
+ {
+ return matchtext;
+ }