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, const char* src, const char* re, const char *ch) : XLine(Instance, s_time, d, src, re, "CBAN")
35 // XXX I shouldn't have to define this
41 bool Matches(const std::string &s)
50 ServerInstance->SNO->WriteToSnoMask('x',"Removing expired CBan %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, (long int)(ServerInstance->Time() - this->set_time));
51 ServerInstance->PI->SendSNONotice("x", "Removing expired CBan " + assign(this->matchtext) + " (set by " + std::string(this->source) + " " + ConvToStr(ServerInstance->Time() - this->set_time) + " seconds ago)");
54 const char* Displayable()
56 return matchtext.c_str();
60 /** An XLineFactory specialized to generate cban pointers
62 class CBanFactory : public XLineFactory
65 CBanFactory(InspIRCd* Instance) : XLineFactory(Instance, "CBAN") { }
69 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
71 return new CBan(ServerInstance, 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(InspIRCd* Me) : Command(Me, "CBAN", "o", 1, 3)
87 this->source = "m_cban.so";
88 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->WriteToSnoMask('x',"%s removed CBan on %s.",user->nick.c_str(),parameters[0].c_str());
102 ServerInstance->PI->SendSNONotice("x", user->nick + " removed CBan on " + parameters[0]);
106 user->WriteServ("NOTICE %s :*** CBan %s not found in list, try /stats C.",user->nick.c_str(),parameters[0].c_str());
111 else if (parameters.size() >= 2)
113 // Adding - XXX todo make this respect <insane> tag perhaps..
114 long duration = ServerInstance->Duration(parameters[1]);
116 const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied";
120 r = new CBan(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), reason, parameters[0].c_str());
124 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
129 if (ServerInstance->XLines->AddLine(r, user))
133 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent CBan for %s: %s", user->nick.c_str(), parameters[0].c_str(), reason);
134 ServerInstance->PI->SendSNONotice("x", user->nick + " added permenant CBan for " + parameters[0] + ": " + std::string(reason));
138 time_t c_requires_crap = duration + ServerInstance->Time();
139 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);
140 ServerInstance->PI->SendSNONotice("x", user->nick + " added timed CBan for " + parameters[0] + ", expires on " + ServerInstance->TimeString(c_requires_crap) + ": " + std::string(reason));
143 ServerInstance->XLines->ApplyLines();
148 user->WriteServ("NOTICE %s :*** CBan for %s already exists", user->nick.c_str(), parameters[0].c_str());
157 class ModuleCBan : public Module
159 CommandCBan* mycommand;
163 ModuleCBan(InspIRCd* Me) : Module(Me)
165 f = new CBanFactory(ServerInstance);
166 ServerInstance->XLines->RegisterFactory(f);
168 mycommand = new CommandCBan(Me);
169 ServerInstance->AddCommand(mycommand);
170 Implementation eventlist[] = { I_OnUserPreJoin, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
171 ServerInstance->Modules->Attach(eventlist, this, 4);
174 virtual ~ModuleCBan()
176 ServerInstance->XLines->DelAll("CBAN");
177 ServerInstance->XLines->UnregisterFactory(f);
180 virtual int OnStats(char symbol, User* user, string_list &out)
185 ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
189 virtual int 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);
197 ServerInstance->SNO->WriteToSnoMask('a', "%s tried to join %s which is CBANed (%s)", user->nick.c_str(), cname, rl->reason);
198 ServerInstance->PI->SendSNONotice("A", user->nick + " tried to join " + std::string(cname) + " which is CBANed (" + std::string(rl->reason) + ")");
205 virtual Version GetVersion()
207 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
211 MODULE_INIT(ModuleCBan)