1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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',"Expiring timed CBan %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, this->duration);
53 const char* Displayable()
55 return matchtext.c_str();
59 /** An XLineFactory specialized to generate cban pointers
61 class CBanFactory : public XLineFactory
64 CBanFactory(InspIRCd* Instance) : XLineFactory(Instance, "CBAN") { }
68 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
70 return new CBan(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
73 bool AutoApplyToUserList(XLine *x)
75 return false; // No, we apply to channels.
81 class CommandCBan : public Command
84 CommandCBan(InspIRCd* Me) : Command(Me, "CBAN", "o", 1, 3)
86 this->source = "m_cban.so";
87 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->WriteToSnoMask('x',"%s Removed CBan on %s.",user->nick.c_str(),parameters[0].c_str());
104 user->WriteServ("NOTICE %s :*** CBan %s not found in list, try /stats C.",user->nick.c_str(),parameters[0].c_str());
109 else if (parameters.size() >= 2)
111 // Adding - XXX todo make this respect <insane> tag perhaps..
112 long duration = ServerInstance->Duration(parameters[1]);
117 r = new CBan(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
121 ; // Do nothing. If we get here, the regex was fucked up, and they already got told it fucked up.
126 if (ServerInstance->XLines->AddLine(r, user))
130 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent CBan for %s: %s", user->nick.c_str(), parameters[0].c_str(), parameters[2].c_str());
134 time_t c_requires_crap = duration + ServerInstance->Time();
135 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(), parameters[2].c_str());
138 ServerInstance->XLines->ApplyLines();
143 user->WriteServ("NOTICE %s :*** CBan for %s already exists", user->nick.c_str(), parameters[0].c_str());
152 class ModuleCBan : public Module
154 CommandCBan* mycommand;
158 ModuleCBan(InspIRCd* Me) : Module(Me)
160 f = new CBanFactory(ServerInstance);
161 ServerInstance->XLines->RegisterFactory(f);
163 mycommand = new CommandCBan(Me);
164 ServerInstance->AddCommand(mycommand);
165 Implementation eventlist[] = { I_OnUserPreJoin, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
166 ServerInstance->Modules->Attach(eventlist, this, 4);
169 virtual ~ModuleCBan()
171 ServerInstance->XLines->DelAll("CBAN");
172 ServerInstance->XLines->UnregisterFactory(f);
175 virtual int OnStats(char symbol, User* user, string_list &out)
180 ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
184 virtual int OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
186 XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
190 // Channel is banned.
191 user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname, rl->reason);
192 ServerInstance->SNO->WriteToSnoMask('A', "%s tried to join %s which is CBANed (%s)", user->nick.c_str(), cname, rl->reason);
199 virtual Version GetVersion()
201 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
205 MODULE_INIT(ModuleCBan)