1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 /* $ModDesc: RLINE: Regexp user banning. */
19 /* $CompileFlags: exec("pcre-config --cflags") */
20 /* $LinkerFlags: exec("pcre-config --libs") rpath("pcre-config --libs") -lpcre */
23 #pragma comment(lib, "pcre.lib")
26 class CoreExport RLine : public XLine
31 * @param s_time The set time
32 * @param d The duration of the xline
33 * @param src The sender of the xline
34 * @param re The reason of the xline
35 * @param regex Pattern to match with
38 RLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* regexs) : XLine(Instance, s_time, d, src, re, "K")
45 regex = pcre_compile(regexs, 0, &error, &erroffset, NULL);
49 ServerInstance->SNO->WriteToSnoMask('x',"Error in regular expression: %s at offset %d: %s\n", regexs, erroffset, error);
50 throw CoreException("Bad regex pattern.");
61 virtual bool Matches(User *u)
63 std::string compare = compare.assign(u->nick) + "!" + u->ident + "@" + u->host + " " + u->fullname;
65 ServerInstance->Log(DEBUG, "Matching " + matchtext + " against string " + compare);
67 if (pcre_exec(regex, NULL, compare.c_str(), compare.length(), 0, 0, NULL, 0) > -1)
76 virtual bool Matches(const std::string&); // Ignored for us
78 virtual void Apply(User* u)
80 DefaultApply(u, "R", true);
83 virtual void DisplayExpiry()
85 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed R-Line %s (set by %s %d seconds ago)", this->matchtext.c_str(), this->source, this->duration);
88 virtual const char* Displayable()
90 return matchtext.c_str();
93 std::string matchtext;
99 /** An XLineFactory specialized to generate RLine* pointers
101 class CoreExport RLineFactory : public XLineFactory
104 RLineFactory(InspIRCd* Instance) : XLineFactory(Instance, "R") { }
108 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
110 return new RLine(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
115 * Syntax is same as other lines: RLINE regex_goes_here 1d :reason
117 class CommandRLine : public Command
120 CommandRLine (InspIRCd* Instance) : Command(Instance,"DALINFO", 1, 'o')
122 this->source = "m_rline.so";
125 CmdResult Handle (const char** parameters, int pcnt, User *user)
129 // Adding - XXX todo make this respect <insane> tag perhaps..
131 long duration = ServerInstance->Duration(parameters[1]);
136 r = new RLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], parameters[0]);
140 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
145 if (ServerInstance->XLines->AddLine(r, user))
149 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent R-Line for %s.", user->nick, parameters[0]);
153 time_t c_requires_crap = duration + ServerInstance->Time();
154 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed R-Line for %s, expires on %s", user->nick, parameters[0],
155 ServerInstance->TimeString(c_requires_crap).c_str());
158 ServerInstance->XLines->ApplyLines();
163 user->WriteServ("NOTICE %s :*** R-Line for %s already exists", user->nick, parameters[0]);
169 if (ServerInstance->XLines->DelLine(parameters[0],"G",user))
171 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed G-line on %s.",user->nick,parameters[0]);
175 user->WriteServ("NOTICE %s :*** G-line %s not found in list, try /stats g.",user->nick,parameters[0]);
183 class ModuleRLine : public Module
188 ModuleRLine(InspIRCd* Me) : Module(Me)
190 // Create a new command
191 r = new CommandRLine(ServerInstance);
192 ServerInstance->AddCommand(r);
195 virtual ~ModuleRLine()
200 MODULE_INIT(ModuleRLine)