4 /* $ModDesc: Provides the /shun command, which stops a user executing all commands except PING and PONG. */
6 class Shun : public XLine
11 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")
13 this->matchtext = shunmask;
22 if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext))
28 bool Matches(const std::string &s)
37 if (!u->GetExt("shunned"))
44 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed shun %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, this->duration);
47 const char* Displayable()
49 return matchtext.c_str();
53 /** An XLineFactory specialized to generate shun pointers
55 class ShunFactory : public XLineFactory
58 ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
62 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
64 return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
68 //typedef std::vector<Shun> shunlist;
70 class cmd_shun : public Command
76 cmd_shun(InspIRCd* Me) : Command(Me, "SHUN", "o", 1), Srv(Me)
78 this->source = "m_shun.so";
81 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
83 /* syntax: SHUN nick!user@host time :reason goes here */
84 /* 'time' is a human-readable timestring, like 2d3h2s. */
86 if (parameters.size() == 1)
88 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SHUN", user))
90 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick.c_str(),parameters[0].c_str());
94 // XXX todo implement stats
95 user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats s.",user->nick.c_str(),parameters[0].c_str());
100 else if (parameters.size() >= 2)
102 // Adding - XXX todo make this respect <insane> tag perhaps..
103 long duration = ServerInstance->Duration(parameters[1]);
108 r = new Shun(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
112 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
117 if (ServerInstance->XLines->AddLine(r, user))
121 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent shun for %s.", user->nick.c_str(), parameters[0].c_str());
125 time_t c_requires_crap = duration + ServerInstance->Time();
126 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed shun for %s, expires on %s", user->nick.c_str(), parameters[0].c_str(),
127 ServerInstance->TimeString(c_requires_crap).c_str());
130 ServerInstance->XLines->ApplyLines();
135 user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick.c_str(), parameters[0].c_str());
144 class ModuleShun : public Module
150 ModuleShun(InspIRCd* Me) : Module(Me)
152 f = new ShunFactory(ServerInstance);
153 ServerInstance->XLines->RegisterFactory(f);
155 mycommand = new cmd_shun(ServerInstance);
156 ServerInstance->AddCommand(mycommand);
158 Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect };
159 ServerInstance->Modules->Attach(eventlist, this, 3);
162 virtual ~ModuleShun()
164 ServerInstance->XLines->DelAll("SHUN");
165 ServerInstance->XLines->UnregisterFactory(f);
168 virtual int OnStats(char symbol, User* user, string_list& out)
173 ServerInstance->XLines->InvokeStats("SHUN", 223, user, out);
177 virtual void OnUserConnect(User* user)
182 // Apply lines on user connect
183 XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
192 virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
194 if (validated || !user->GetExt("shunned"))
197 if (!ServerInstance->XLines->MatchesLine("SHUN", user))
199 /* The shun previously set on this user has expired or been removed */
200 user->Shrink("shunned");
204 if (command == "QUIT")
206 /* Allow QUIT but dont show any quit message */
211 /* Always allow PONG and PING */
212 if (command == "PONG" || command == "PING")
218 virtual Version GetVersion()
220 return Version(1,2,0,0,VF_VENDOR|VF_COMMON,API_VERSION);
224 MODULE_INIT(ModuleShun)