2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2005-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2005-2006 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /* $ModDesc: Gives /cban, aka C:lines. Think Q:lines, for channels. */
30 class CBan : public XLine
33 irc::string matchtext;
35 CBan(time_t s_time, long d, std::string src, std::string re, std::string ch)
36 : XLine(s_time, d, src, re, "CBAN")
38 this->matchtext = ch.c_str();
41 // XXX I shouldn't have to define this
47 bool Matches(const std::string &s)
54 const char* Displayable()
56 return matchtext.c_str();
60 /** An XLineFactory specialized to generate cban pointers
62 class CBanFactory : public XLineFactory
65 CBanFactory() : XLineFactory("CBAN") { }
69 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
71 return new CBan(set_time, duration, source, reason, xline_specific_mask);
74 bool AutoApplyToUserList(XLine *x)
76 return false; // No, we apply to channels.
82 class CommandCBan : public Command
85 CommandCBan(Module* Creator) : Command(Creator, "CBAN", 1, 3)
87 flags_needed = 'o'; this->syntax = "<channel> [<duration> :<reason>]";
88 TRANSLATE4(TR_TEXT,TR_TEXT,TR_TEXT,TR_END);
91 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
93 /* syntax: CBAN #channel time :reason goes here */
94 /* 'time' is a human-readable timestring, like 2d3h2s. */
96 if (parameters.size() == 1)
98 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "CBAN", user))
100 ServerInstance->SNO->WriteGlobalSno('x', "%s removed CBan on %s.",user->nick.c_str(),parameters[0].c_str());
104 user->WriteNotice("*** CBan " + parameters[0] + " not found in list, try /stats C.");
110 // Adding - XXX todo make this respect <insane> tag perhaps..
111 unsigned long duration = InspIRCd::Duration(parameters[1]);
112 const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied";
113 CBan* r = new CBan(ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str());
115 if (ServerInstance->XLines->AddLine(r, user))
119 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent CBan for %s: %s", user->nick.c_str(), parameters[0].c_str(), reason);
123 time_t c_requires_crap = duration + ServerInstance->Time();
124 std::string timestr = ServerInstance->TimeString(c_requires_crap);
125 ServerInstance->SNO->WriteGlobalSno('x', "%s added timed CBan for %s, expires on %s: %s", user->nick.c_str(), parameters[0].c_str(), timestr.c_str(), reason);
131 user->WriteNotice("*** CBan for " + parameters[0] + " already exists");
138 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
141 return ROUTE_LOCALONLY; // spanningtree will send ADDLINE
143 return ROUTE_BROADCAST;
147 class ModuleCBan : public Module
149 CommandCBan mycommand;
153 ModuleCBan() : mycommand(this)
159 ServerInstance->XLines->RegisterFactory(&f);
161 ServerInstance->Modules->AddService(mycommand);
162 Implementation eventlist[] = { I_OnUserPreJoin, I_OnStats };
163 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
166 virtual ~ModuleCBan()
168 ServerInstance->XLines->DelAll("CBAN");
169 ServerInstance->XLines->UnregisterFactory(&f);
172 virtual ModResult OnStats(char symbol, User* user, string_list &out)
175 return MOD_RES_PASSTHRU;
177 ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
181 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven)
183 XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
187 // Channel is banned.
188 user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname.c_str(), rl->reason.c_str());
189 ServerInstance->SNO->WriteGlobalSno('a', "%s tried to join %s which is CBANed (%s)",
190 user->nick.c_str(), cname.c_str(), rl->reason.c_str());
194 return MOD_RES_PASSTHRU;
197 virtual Version GetVersion()
199 return Version("Gives /cban, aka C:lines. Think Q:lines, for channels.", VF_COMMON | VF_VENDOR);
203 MODULE_INIT(ModuleCBan)