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 if (!u->GetExt("shunned"))
51 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed shun %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, this->duration);
54 const char* Displayable()
56 return matchtext.c_str();
60 /** An XLineFactory specialized to generate shun pointers
62 class ShunFactory : public XLineFactory
65 ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
69 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
71 return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
75 //typedef std::vector<Shun> shunlist;
77 class cmd_shun : public Command
83 cmd_shun(InspIRCd* Me) : Command(Me, "SHUN", "o", 1), Srv(Me)
85 this->source = "m_shun.so";
88 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
90 /* syntax: SHUN nick!user@host time :reason goes here */
91 /* 'time' is a human-readable timestring, like 2d3h2s. */
93 if (parameters.size() == 1)
95 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SHUN", user))
97 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick,parameters[0].c_str());
101 // XXX todo implement stats
102 user->WriteServ("NOTICE %s :*** Shun %s not found in list, try /stats s.",user->nick,parameters[0].c_str());
107 else if (parameters.size() >= 2)
109 // Adding - XXX todo make this respect <insane> tag perhaps..
110 long duration = ServerInstance->Duration(parameters[1]);
115 r = new Shun(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2].c_str(), parameters[0].c_str());
119 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
124 if (ServerInstance->XLines->AddLine(r, user))
128 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent shun for %s.", user->nick, parameters[0].c_str());
132 time_t c_requires_crap = duration + ServerInstance->Time();
133 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed shun for %s, expires on %s", user->nick, parameters[0].c_str(),
134 ServerInstance->TimeString(c_requires_crap).c_str());
137 ServerInstance->XLines->ApplyLines();
142 user->WriteServ("NOTICE %s :*** Shun for %s already exists", user->nick, parameters[0].c_str());
151 class ModuleShun : public Module
157 ModuleShun(InspIRCd* Me) : Module(Me)
159 f = new ShunFactory(ServerInstance);
160 ServerInstance->XLines->RegisterFactory(f);
162 mycommand = new cmd_shun(ServerInstance);
163 ServerInstance->AddCommand(mycommand);
165 Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect };
166 ServerInstance->Modules->Attach(eventlist, this, 3);
169 virtual ~ModuleShun()
171 ServerInstance->XLines->UnregisterFactory(f);
174 virtual int OnStats(char symbol, User* user, string_list& out)
177 //format << Srv->Config->ServerName << " 223 " << user->nick << " :" << iter->banmask << " " << iter->set_on << " " << iter->length << " " <<
178 //iter->set_by << " " << iter->reason;
183 virtual void OnUserConnect(User* user)
188 // Apply lines on user connect
189 XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
198 virtual int OnPreCommand(const std::string &command, const std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
200 if((command != "PONG") && (command != "PING"))
202 if (user->GetExt("shunned"))
209 virtual Version GetVersion()
211 return Version(1,0,0,0,0,API_VERSION);
215 MODULE_INIT(ModuleShun)