8 #include "configreader.h"
11 /* $ModDesc: Provides the /shun command, which stops a user executing all commands except PING and PONG. */
13 class Shun : public XLine
16 std::string matchtext;
18 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")
20 this->matchtext = shunmask;
29 if (ServerInstance->MatchText(u->GetFullHost(), matchtext) || ServerInstance->MatchText(u->GetFullRealHost(), matchtext))
35 bool Matches(const std::string &s)
44 // Application is done by the module.
50 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed shun %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, this->duration);
53 const char* Displayable()
55 return matchtext.c_str();
59 /** An XLineFactory specialized to generate shun pointers
61 class ShunFactory : public XLineFactory
64 ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
68 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
70 return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
73 virtual bool AutoApplyToUserList(XLine*)
75 // No, we don't want to be applied to users automagically.
80 //typedef std::vector<Shun> shunlist;
82 class cmd_shun : public Command
88 cmd_shun(InspIRCd* Me) : Command(Me, "SHUN", "o", 1), Srv(Me)
90 this->source = "m_shun.so";
93 CmdResult Handle(const char* const*parameters, int pcnt, User *user)
95 /* syntax: SHUN nick!user@host time :reason goes here */
96 /* 'time' is a human-readable timestring, like 2d3h2s. */
100 if (ServerInstance->XLines->DelLine(parameters[0], "S", user))
102 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick,parameters[0]);
106 // XXX todo implement stats
107 user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats s.",user->nick,parameters[0]);
114 // Adding - XXX todo make this respect <insane> tag perhaps..
115 long duration = ServerInstance->Duration(parameters[1]);
120 r = new Shun(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], parameters[0]);
124 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
129 if (ServerInstance->XLines->AddLine(r, user))
133 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent shun for %s.", user->nick, parameters[0]);
137 time_t c_requires_crap = duration + ServerInstance->Time();
138 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed shun for %s, expires on %s", user->nick, parameters[0],
139 ServerInstance->TimeString(c_requires_crap).c_str());
142 ServerInstance->XLines->ApplyLines();
147 user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick, parameters[0]);
156 class ModuleShun : public Module
162 ModuleShun(InspIRCd* Me) : Module(Me)
164 f = new ShunFactory(ServerInstance);
165 ServerInstance->XLines->RegisterFactory(f);
167 mycommand = new cmd_shun(ServerInstance);
168 ServerInstance->AddCommand(mycommand);
171 virtual ~ModuleShun()
173 ServerInstance->XLines->UnregisterFactory(f);
176 void Implements(char* List)
178 List[I_OnPreCommand] = List[I_OnStats] = 1;
181 virtual int OnStats(char symbol, User* user, string_list& out)
184 //format << Srv->Config->ServerName << " 223 " << user->nick << " :" << iter->banmask << " " << iter->set_on << " " << iter->length << " " <<
185 //iter->set_by << " " << iter->reason;
190 virtual int OnPreCommand(const std::string &command, const char* const*parameters, int pcnt, User* user, bool validated, const std::string &original_line)
192 if (user->registered != REG_ALL)
195 if((command != "PONG") && (command != "PING"))
197 // Don't let them issue cmd if they are shunned..
198 XLine *rl = ServerInstance->XLines->MatchesLine("S", user);
209 virtual Version GetVersion()
211 return Version(1,0,0,0,0,API_VERSION);
215 MODULE_INIT(ModuleShun)