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: Gives /cban, aka C:lines. Think Q:lines, for channels. */
21 class CBan : public XLine
24 irc::string matchtext;
26 CBan(time_t s_time, long d, std::string src, std::string re, std::string ch)
27 : XLine(s_time, d, src, re, "CBAN")
29 this->matchtext = ch.c_str();
36 // XXX I shouldn't have to define this
42 bool Matches(const std::string &s)
51 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired CBan %s (set by %s %ld seconds ago)",
52 this->matchtext.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
55 const char* Displayable()
57 return matchtext.c_str();
61 /** An XLineFactory specialized to generate cban pointers
63 class CBanFactory : public XLineFactory
66 CBanFactory() : XLineFactory("CBAN") { }
70 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
72 return new CBan(set_time, duration, source, reason, xline_specific_mask);
75 bool AutoApplyToUserList(XLine *x)
77 return false; // No, we apply to channels.
83 class CommandCBan : public Command
86 CommandCBan(Module* Creator) : Command(Creator, "CBAN", 1, 3)
88 flags_needed = 'o'; this->syntax = "<channel> [<duration> :<reason>]";
89 TRANSLATE4(TR_TEXT,TR_TEXT,TR_TEXT,TR_END);
92 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
94 /* syntax: CBAN #channel time :reason goes here */
95 /* 'time' is a human-readable timestring, like 2d3h2s. */
97 if (parameters.size() == 1)
99 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "CBAN", user))
101 ServerInstance->SNO->WriteGlobalSno('x', "%s removed CBan on %s.",user->nick.c_str(),parameters[0].c_str());
105 user->WriteServ("NOTICE %s :*** CBan %s not found in list, try /stats C.",user->nick.c_str(),parameters[0].c_str());
110 else if (parameters.size() >= 2)
112 // Adding - XXX todo make this respect <insane> tag perhaps..
113 long duration = ServerInstance->Duration(parameters[1]);
115 const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied";
119 r = new CBan(ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str());
123 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
128 if (ServerInstance->XLines->AddLine(r, user))
132 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent CBan for %s: %s", user->nick.c_str(), parameters[0].c_str(), reason);
136 time_t c_requires_crap = duration + ServerInstance->Time();
137 ServerInstance->SNO->WriteGlobalSno('x', "%s added timed CBan for %s, expires on %s: %s", user->nick.c_str(), parameters[0].c_str(), ServerInstance->TimeString(c_requires_crap).c_str(), reason);
140 ServerInstance->XLines->ApplyLines();
145 user->WriteServ("NOTICE %s :*** CBan for %s already exists", user->nick.c_str(), parameters[0].c_str());
153 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
155 return ROUTE_BROADCAST;
159 class ModuleCBan : public Module
161 CommandCBan mycommand;
165 ModuleCBan() : mycommand(this)
167 ServerInstance->XLines->RegisterFactory(&f);
169 ServerInstance->AddCommand(&mycommand);
170 Implementation eventlist[] = { I_OnUserPreJoin, I_OnStats };
171 ServerInstance->Modules->Attach(eventlist, this, 2);
174 virtual ~ModuleCBan()
176 ServerInstance->XLines->DelAll("CBAN");
177 ServerInstance->XLines->UnregisterFactory(&f);
180 virtual ModResult OnStats(char symbol, User* user, string_list &out)
183 return MOD_RES_PASSTHRU;
185 ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
189 virtual ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
191 XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
195 // Channel is banned.
196 user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname, rl->reason.c_str());
197 ServerInstance->SNO->WriteToSnoMask('a', "%s tried to join %s which is CBANed (%s)",
198 user->nick.c_str(), cname, rl->reason.c_str());
199 ServerInstance->PI->SendSNONotice("A", user->nick + " tried to join " + std::string(cname) + " which is CBANed (" + rl->reason + ")");
203 return MOD_RES_PASSTHRU;
206 virtual Version GetVersion()
208 return Version("Gives /cban, aka C:lines. Think Q:lines, for channels.", VF_COMMON | VF_VENDOR);
212 MODULE_INIT(ModuleCBan)