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(InspIRCd* Instance, time_t s_time, long d, std::string src, std::string re, std::string ch)
27 : XLine(Instance, 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));
53 ServerInstance->PI->SendSNONotice("x", "Removing expired CBan " + assign(this->matchtext) + " (set by " + this->source + " " + ConvToStr(ServerInstance->Time() - this->set_time) + " seconds ago)");
56 const char* Displayable()
58 return matchtext.c_str();
62 /** An XLineFactory specialized to generate cban pointers
64 class CBanFactory : public XLineFactory
67 CBanFactory(InspIRCd* Instance) : XLineFactory(Instance, "CBAN") { }
71 XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
73 return new CBan(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
76 bool AutoApplyToUserList(XLine *x)
78 return false; // No, we apply to channels.
84 class CommandCBan : public Command
87 CommandCBan(InspIRCd* Me, Module* Creator) : Command(Me, Creator, "CBAN", "o", 1, 3)
89 this->syntax = "<channel> [<duration> :<reason>]";
90 TRANSLATE4(TR_TEXT,TR_TEXT,TR_TEXT,TR_END);
93 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
95 /* syntax: CBAN #channel time :reason goes here */
96 /* 'time' is a human-readable timestring, like 2d3h2s. */
98 if (parameters.size() == 1)
100 if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "CBAN", user))
102 ServerInstance->SNO->WriteToSnoMask('x',"%s removed CBan on %s.",user->nick.c_str(),parameters[0].c_str());
103 ServerInstance->PI->SendSNONotice("x", user->nick + " removed CBan on " + parameters[0]);
107 user->WriteServ("NOTICE %s :*** CBan %s not found in list, try /stats C.",user->nick.c_str(),parameters[0].c_str());
112 else if (parameters.size() >= 2)
114 // Adding - XXX todo make this respect <insane> tag perhaps..
115 long duration = ServerInstance->Duration(parameters[1]);
117 const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied";
121 r = new CBan(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str());
125 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
130 if (ServerInstance->XLines->AddLine(r, user))
134 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent CBan for %s: %s", user->nick.c_str(), parameters[0].c_str(), reason);
135 ServerInstance->PI->SendSNONotice("x", user->nick + " added permenant CBan for " + parameters[0] + ": " + std::string(reason));
139 time_t c_requires_crap = duration + ServerInstance->Time();
140 ServerInstance->SNO->WriteToSnoMask('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);
141 ServerInstance->PI->SendSNONotice("x", user->nick + " added timed CBan for " + parameters[0] + ", expires on " + ServerInstance->TimeString(c_requires_crap) + ": " + std::string(reason));
144 ServerInstance->XLines->ApplyLines();
149 user->WriteServ("NOTICE %s :*** CBan for %s already exists", user->nick.c_str(), parameters[0].c_str());
157 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
159 return ROUTE_BROADCAST;
163 class ModuleCBan : public Module
165 CommandCBan mycommand;
169 ModuleCBan(InspIRCd* Me) : Module(Me), mycommand(Me, this), f(Me)
171 ServerInstance->XLines->RegisterFactory(&f);
173 ServerInstance->AddCommand(&mycommand);
174 Implementation eventlist[] = { I_OnUserPreJoin, I_OnStats };
175 ServerInstance->Modules->Attach(eventlist, this, 2);
178 virtual ~ModuleCBan()
180 ServerInstance->XLines->DelAll("CBAN");
181 ServerInstance->XLines->UnregisterFactory(&f);
184 virtual ModResult OnStats(char symbol, User* user, string_list &out)
187 return MOD_RES_PASSTHRU;
189 ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
193 virtual ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
195 XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
199 // Channel is banned.
200 user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname, rl->reason.c_str());
201 ServerInstance->SNO->WriteToSnoMask('a', "%s tried to join %s which is CBANed (%s)",
202 user->nick.c_str(), cname, rl->reason.c_str());
203 ServerInstance->PI->SendSNONotice("A", user->nick + " tried to join " + std::string(cname) + " which is CBANed (" + rl->reason + ")");
207 return MOD_RES_PASSTHRU;
210 virtual Version GetVersion()
212 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
216 MODULE_INIT(ModuleCBan)