1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Provides the /shun command, which stops a user executing all commands except PING and PONG. */
19 class Shun : public XLine
22 std::string matchtext;
24 Shun(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char *shunmask) : XLine(Instance, s_time, d, src, re, "SHUN")
26 this->matchtext = shunmask;
39 if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext) || InspIRCd::Match(u->nick+"!"+u->ident+"@"+u->GetIPString(), matchtext))
45 bool Matches(const std::string &s)
59 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired shun %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, (long int)(ServerInstance->Time() - this->set_time));
62 const char* Displayable()
64 return matchtext.c_str();
68 /** An XLineFactory specialized to generate shun pointers
70 class ShunFactory : public XLineFactory
73 ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
77 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
79 return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
83 //typedef std::vector<Shun> shunlist;
85 class CommandShun : public Command
88 CommandShun(InspIRCd* Me) : Command(Me, "SHUN", "o", 1, 3)
90 this->source = "m_shun.so";
91 this->syntax = "<nick!user@hostmask> [<shun-duration>] :<reason>";
94 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
96 /* syntax: SHUN nick!user@host time :reason goes here */
97 /* 'time' is a human-readable timestring, like 2d3h2s. */
99 std::string target = parameters[0];
101 User *find = ServerInstance->FindNick(target.c_str());
103 target = std::string("*!*@") + find->GetIPString();
105 if (parameters.size() == 1)
107 if (ServerInstance->XLines->DelLine(target.c_str(), "SHUN", user))
109 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick.c_str(),target.c_str());
113 // XXX todo implement stats
114 user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats S.",user->nick.c_str(),target.c_str());
119 else if (parameters.size() >= 2)
121 // Adding - XXX todo make this respect <insane> tag perhaps..
124 if (parameters.size() > 2)
126 duration = ServerInstance->Duration(parameters[1]);
127 expr = parameters[2];
132 expr = parameters[1];
138 r = new Shun(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), expr.c_str(), target.c_str());
142 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
147 if (ServerInstance->XLines->AddLine(r, user))
151 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent shun for %s: %s",
152 user->nick.c_str(), target.c_str(), expr.c_str());
156 time_t c_requires_crap = duration + ServerInstance->Time();
157 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed shun for %s, expires on %s: %s",
158 user->nick.c_str(), target.c_str(), ServerInstance->TimeString(c_requires_crap).c_str(), expr.c_str());
161 ServerInstance->XLines->ApplyLines();
166 user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick.c_str(), expr.c_str());
175 class ModuleShun : public Module
177 CommandShun* mycommand;
179 std::set<std::string> ShunEnabledCommands;
184 ModuleShun(InspIRCd* Me) : Module(Me)
186 f = new ShunFactory(ServerInstance);
187 ServerInstance->XLines->RegisterFactory(f);
189 mycommand = new CommandShun(ServerInstance);
190 ServerInstance->AddCommand(mycommand);
192 Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect, I_OnRehash };
193 ServerInstance->Modules->Attach(eventlist, this, 4);
197 virtual ~ModuleShun()
199 ServerInstance->XLines->DelAll("SHUN");
200 ServerInstance->XLines->UnregisterFactory(f);
203 virtual int OnStats(char symbol, User* user, string_list& out)
208 ServerInstance->XLines->InvokeStats("SHUN", 223, user, out);
212 virtual void OnRehash(User* user)
214 ConfigReader MyConf(ServerInstance);
215 std::string cmds = MyConf.ReadValue("shun", "enabledcommands", 0);
218 cmds = "PING PONG QUIT";
220 ShunEnabledCommands.clear();
224 std::stringstream dcmds(cmds);
227 while (dcmds >> thiscmd)
229 ShunEnabledCommands.insert(thiscmd);
232 NotifyOfShun = MyConf.ReadFlag("shun", "notifyuser", "yes", 0);
233 affectopers = MyConf.ReadFlag("shun", "affectopers", "no", 0);
236 virtual void OnUserConnect(User* user)
241 // Apply lines on user connect
242 XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
251 virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
256 if (!ServerInstance->XLines->MatchesLine("SHUN", user))
258 /* Not shunned, don't touch. */
262 if (!affectopers && IS_OPER(user))
264 /* Don't do anything if the user is an operator and affectopers isn't set */
268 std::set<std::string>::iterator i = ShunEnabledCommands.find(command);
270 if (i == ShunEnabledCommands.end())
273 user->WriteServ("NOTICE %s :*** Command %s not processed, as you have been blocked from issuing commands (SHUN)", user->nick.c_str(), command.c_str());
277 if (command == "QUIT")
279 /* Allow QUIT but dont show any quit message */
282 else if (command == "PART")
288 /* if we're here, allow the command. */
292 virtual Version GetVersion()
294 return Version("$Id$",VF_VENDOR|VF_COMMON,API_VERSION);
298 MODULE_INIT(ModuleShun)