1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 * ---------------------------------------------------
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;
35 if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext))
41 bool Matches(const std::string &s)
50 if (!u->GetExt("shunned"))
57 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));
60 const char* Displayable()
62 return matchtext.c_str();
66 /** An XLineFactory specialized to generate shun pointers
68 class ShunFactory : public XLineFactory
71 ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
75 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
77 return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
81 //typedef std::vector<Shun> shunlist;
83 class CommandShun : public Command
89 CommandShun(InspIRCd* Me) : Command(Me, "SHUN", "o", 1, 3), Srv(Me)
91 this->source = "m_shun.so";
92 this->syntax = "<nick!user@hostmask> [<shun-duration>] :<reason>";
95 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
97 /* syntax: SHUN nick!user@host time :reason goes here */
98 /* 'time' is a human-readable timestring, like 2d3h2s. */
100 if (parameters.size() == 1)
102 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SHUN", user))
104 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick.c_str(),parameters[0].c_str());
108 // XXX todo implement stats
109 user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats S.",user->nick.c_str(),parameters[0].c_str());
114 else if (parameters.size() >= 2)
116 // Adding - XXX todo make this respect <insane> tag perhaps..
119 if (parameters.size() > 2)
121 duration = ServerInstance->Duration(parameters[1]);
122 expr = parameters[2];
127 expr = parameters[1];
133 r = new Shun(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), expr.c_str(), parameters[0].c_str());
137 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
142 if (ServerInstance->XLines->AddLine(r, user))
146 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent shun for %s: %s",
147 user->nick.c_str(), parameters[0].c_str(), expr.c_str());
151 time_t c_requires_crap = duration + ServerInstance->Time();
152 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed shun for %s, expires on %s: %s",
153 user->nick.c_str(), parameters[0].c_str(), ServerInstance->TimeString(c_requires_crap).c_str(), expr.c_str());
156 ServerInstance->XLines->ApplyLines();
161 user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick.c_str(), expr.c_str());
170 class ModuleShun : public Module
172 CommandShun* mycommand;
174 std::set<std::string> ShunEnabledCommands;
179 ModuleShun(InspIRCd* Me) : Module(Me)
181 f = new ShunFactory(ServerInstance);
182 ServerInstance->XLines->RegisterFactory(f);
184 mycommand = new CommandShun(ServerInstance);
185 ServerInstance->AddCommand(mycommand);
187 Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect, I_OnRehash };
188 ServerInstance->Modules->Attach(eventlist, this, 4);
192 virtual ~ModuleShun()
194 ServerInstance->XLines->DelAll("SHUN");
195 ServerInstance->XLines->UnregisterFactory(f);
198 virtual int OnStats(char symbol, User* user, string_list& out)
203 ServerInstance->XLines->InvokeStats("SHUN", 223, user, out);
207 virtual void OnRehash(User* user, const std::string ¶meter)
209 ConfigReader MyConf(ServerInstance);
210 std::string cmds = MyConf.ReadValue("shun", "enabledcommands", 0);
213 cmds = "PING PONG QUIT";
215 ShunEnabledCommands.clear();
219 std::stringstream dcmds(cmds);
222 while (dcmds >> thiscmd)
224 ShunEnabledCommands.insert(thiscmd);
227 NotifyOfShun = MyConf.ReadFlag("shun", "notifyuser", "yes", 0);
228 affectopers = MyConf.ReadFlag("shun", "affectopers", "no", 0);
231 virtual void OnUserConnect(User* user)
236 // Apply lines on user connect
237 XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
246 virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
248 if (validated || !user->GetExt("shunned"))
251 if (!ServerInstance->XLines->MatchesLine("SHUN", user))
253 /* The shun previously set on this user has expired or been removed */
254 user->Shrink("shunned");
258 if (!affectopers && IS_OPER(user))
260 /* Don't do anything if the user is an operator and affectopers isn't set */
264 std::set<std::string>::iterator i = ShunEnabledCommands.find(command);
266 if (i == ShunEnabledCommands.end())
269 user->WriteServ("NOTICE %s :*** Command %s not processed, as you have been blocked from issuing commands (SHUN)", user->nick.c_str(), command.c_str());
273 if (command == "QUIT")
275 /* Allow QUIT but dont show any quit message */
278 else if (command == "PART")
287 virtual Version GetVersion()
289 return Version("$Id$",VF_VENDOR|VF_COMMON,API_VERSION);
293 MODULE_INIT(ModuleShun)