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/>.
25 #include "modules/stats.h"
35 class CBan : public XLine
38 std::string matchtext;
41 CBan(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ch)
42 : XLine(s_time, d, src, re, "CBAN")
47 // XXX I shouldn't have to define this
48 bool Matches(User* u) CXX11_OVERRIDE
53 bool Matches(const std::string& s) CXX11_OVERRIDE
55 return irc::equals(matchtext, s);
58 const std::string& Displayable() CXX11_OVERRIDE
64 /** An XLineFactory specialized to generate cban pointers
66 class CBanFactory : public XLineFactory
69 CBanFactory() : XLineFactory("CBAN") { }
73 XLine* Generate(time_t set_time, unsigned long duration, const std::string& source, const std::string& reason, const std::string& xline_specific_mask) CXX11_OVERRIDE
75 return new CBan(set_time, duration, source, reason, xline_specific_mask);
78 bool AutoApplyToUserList(XLine* x) CXX11_OVERRIDE
80 return false; // No, we apply to channels.
86 class CommandCBan : public Command
89 CommandCBan(Module* Creator) : Command(Creator, "CBAN", 1, 3)
91 flags_needed = 'o'; this->syntax = "<channel> [<duration> :<reason>]";
94 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
96 /* syntax: CBAN #channel time :reason goes here */
97 /* 'time' is a human-readable timestring, like 2d3h2s. */
99 if (parameters.size() == 1)
101 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "CBAN", user))
103 ServerInstance->SNO->WriteGlobalSno('x', "%s removed CBan on %s.",user->nick.c_str(),parameters[0].c_str());
107 user->WriteNotice("*** CBan " + parameters[0] + " not found in list, try /stats C.");
113 // Adding - XXX todo make this respect <insane> tag perhaps..
114 unsigned long duration;
115 if (!InspIRCd::Duration(parameters[1], duration))
117 user->WriteNotice("*** Invalid duration for CBan.");
120 const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied";
121 CBan* r = new CBan(ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str());
123 if (ServerInstance->XLines->AddLine(r, user))
127 ServerInstance->SNO->WriteGlobalSno('x', "%s added permanent CBan for %s: %s", user->nick.c_str(), parameters[0].c_str(), reason);
131 time_t c_requires_crap = duration + ServerInstance->Time();
132 std::string timestr = InspIRCd::TimeString(c_requires_crap);
133 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);
139 user->WriteNotice("*** CBan for " + parameters[0] + " already exists");
146 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
149 return ROUTE_LOCALONLY; // spanningtree will send ADDLINE
151 return ROUTE_BROADCAST;
155 class ModuleCBan : public Module, public Stats::EventListener
157 CommandCBan mycommand;
162 : Stats::EventListener(this)
167 void init() CXX11_OVERRIDE
169 ServerInstance->XLines->RegisterFactory(&f);
174 ServerInstance->XLines->DelAll("CBAN");
175 ServerInstance->XLines->UnregisterFactory(&f);
178 ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
180 if (stats.GetSymbol() != 'C')
181 return MOD_RES_PASSTHRU;
183 ServerInstance->XLines->InvokeStats("CBAN", 210, stats);
187 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
189 XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
193 // Channel is banned.
194 user->WriteNumeric(ERR_BADCHANNEL, cname, InspIRCd::Format("Channel %s is CBANed: %s", cname.c_str(), rl->reason.c_str()));
195 ServerInstance->SNO->WriteGlobalSno('a', "%s tried to join %s which is CBANed (%s)",
196 user->nick.c_str(), cname.c_str(), rl->reason.c_str());
200 return MOD_RES_PASSTHRU;
203 Version GetVersion() CXX11_OVERRIDE
205 return Version("Gives /cban, aka C-lines. Think Q-lines, for channels.", VF_COMMON | VF_VENDOR);
209 MODULE_INIT(ModuleCBan)