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, std::string src, std::string re, std::string shunmask)
25 : XLine(Instance, s_time, d, src, re, "SHUN")
27 this->matchtext = shunmask;
40 if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext) || InspIRCd::Match(u->nick+"!"+u->ident+"@"+u->GetIPString(), matchtext))
46 bool Matches(const std::string &s)
60 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired shun %s (set by %s %ld seconds ago)",
61 this->matchtext.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
64 const char* Displayable()
66 return matchtext.c_str();
70 /** An XLineFactory specialized to generate shun pointers
72 class ShunFactory : public XLineFactory
75 ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
79 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
81 return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
85 //typedef std::vector<Shun> shunlist;
87 class CommandShun : public Command
90 CommandShun(InspIRCd* Me, Module* Creator) : Command(Me, Creator, "SHUN", "o", 1, 3)
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 std::string target = parameters[0];
102 User *find = ServerInstance->FindNick(target.c_str());
104 target = std::string("*!*@") + find->GetIPString();
106 if (parameters.size() == 1)
108 if (ServerInstance->XLines->DelLine(target.c_str(), "SHUN", user))
110 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick.c_str(),target.c_str());
114 // XXX todo implement stats
115 user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats S.",user->nick.c_str(),target.c_str());
120 else if (parameters.size() >= 2)
122 // Adding - XXX todo make this respect <insane> tag perhaps..
125 if (parameters.size() > 2)
127 duration = ServerInstance->Duration(parameters[1]);
128 expr = parameters[2];
133 expr = parameters[1];
139 r = new Shun(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), expr.c_str(), target.c_str());
143 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
148 if (ServerInstance->XLines->AddLine(r, user))
152 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent shun for %s: %s",
153 user->nick.c_str(), target.c_str(), expr.c_str());
157 time_t c_requires_crap = duration + ServerInstance->Time();
158 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed shun for %s, expires on %s: %s",
159 user->nick.c_str(), target.c_str(), ServerInstance->TimeString(c_requires_crap).c_str(), expr.c_str());
162 ServerInstance->XLines->ApplyLines();
167 user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick.c_str(), expr.c_str());
175 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
177 return ROUTE_BROADCAST;
181 class ModuleShun : public Module
185 std::set<std::string> ShunEnabledCommands;
190 ModuleShun(InspIRCd* Me) : Module(Me), cmd(Me, this), f(Me)
192 ServerInstance->XLines->RegisterFactory(&f);
193 ServerInstance->AddCommand(&cmd);
195 Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect, I_OnRehash };
196 ServerInstance->Modules->Attach(eventlist, this, 4);
200 virtual ~ModuleShun()
202 ServerInstance->XLines->DelAll("SHUN");
203 ServerInstance->XLines->UnregisterFactory(&f);
206 virtual ModResult OnStats(char symbol, User* user, string_list& out)
209 return MOD_RES_PASSTHRU;
211 ServerInstance->XLines->InvokeStats("SHUN", 223, user, out);
215 virtual void OnRehash(User* user)
217 ConfigReader MyConf(ServerInstance);
218 std::string cmds = MyConf.ReadValue("shun", "enabledcommands", 0);
221 cmds = "PING PONG QUIT";
223 ShunEnabledCommands.clear();
227 std::stringstream dcmds(cmds);
230 while (dcmds >> thiscmd)
232 ShunEnabledCommands.insert(thiscmd);
235 NotifyOfShun = MyConf.ReadFlag("shun", "notifyuser", "yes", 0);
236 affectopers = MyConf.ReadFlag("shun", "affectopers", "no", 0);
239 virtual void OnUserConnect(User* user)
244 // Apply lines on user connect
245 XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
254 virtual ModResult OnPreCommand(std::string &command, std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
257 return MOD_RES_PASSTHRU;
259 if (!ServerInstance->XLines->MatchesLine("SHUN", user))
261 /* Not shunned, don't touch. */
262 return MOD_RES_PASSTHRU;
265 if (!affectopers && IS_OPER(user))
267 /* Don't do anything if the user is an operator and affectopers isn't set */
268 return MOD_RES_PASSTHRU;
271 std::set<std::string>::iterator i = ShunEnabledCommands.find(command);
273 if (i == ShunEnabledCommands.end())
276 user->WriteServ("NOTICE %s :*** Command %s not processed, as you have been blocked from issuing commands (SHUN)", user->nick.c_str(), command.c_str());
280 if (command == "QUIT")
282 /* Allow QUIT but dont show any quit message */
285 else if (command == "PART")
291 /* if we're here, allow the command. */
292 return MOD_RES_PASSTHRU;
295 virtual Version GetVersion()
297 return Version("$Id$",VF_VENDOR|VF_COMMON,API_VERSION);
301 MODULE_INIT(ModuleShun)