1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 * ---------------------------------------------------
14 /* $ModDesc: Adds timed bans */
28 typedef std::vector<TimedBan> timedbans;
29 timedbans TimedBanList;
33 class CommandTban : public Command
36 CommandTban(Module* Creator) : Command(Creator,"TBAN", 3)
38 syntax = "<channel> <duration> <banmask>";
39 TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END);
42 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
44 Channel* channel = ServerInstance->FindChan(parameters[0]);
47 user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str());
50 int cm = channel->GetPrefixValue(user);
51 if (cm < HALFOP_VALUE)
53 user->WriteNumeric(482, "%s %s :You do not have permission to set bans on this channel",
54 user->nick.c_str(), channel->name.c_str());
57 if (!ServerInstance->IsValidMask(parameters[2]))
59 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban mask");
63 std::string channelname = parameters[0];
64 long duration = ServerInstance->Duration(parameters[1]);
65 unsigned long expire = duration + ServerInstance->Time();
68 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban time");
71 std::string mask = parameters[2];
72 std::vector<std::string> setban;
73 setban.push_back(parameters[0]);
74 setban.push_back("+b");
75 setban.push_back(parameters[2]);
76 // use CallCommandHandler to make it so that the user sets the mode
78 ServerInstance->CallCommandHandler("MODE",setban,user);
79 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
80 if (!strcasecmp(i->data.c_str(), mask.c_str()))
85 T.channel = channelname;
88 TimedBanList.push_back(T);
89 channel->WriteAllExcept(ServerInstance->FakeClient, true, '@', tmp, "NOTICE %s :%s added a timed ban on %s lasting for %ld seconds.", channel->name.c_str(), user->nick.c_str(), mask.c_str(), duration);
90 ServerInstance->PI->SendChannelNotice(channel, '@', user->nick + " added a timed ban on " + mask + " lasting for " + ConvToStr(duration) + " seconds.");
94 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
96 return ROUTE_BROADCAST;
100 class ModuleTimedBans : public Module
107 ServerInstance->AddCommand(&cmd);
108 TimedBanList.clear();
109 Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
110 ServerInstance->Modules->Attach(eventlist, this, 2);
113 virtual ~ModuleTimedBans()
115 TimedBanList.clear();
118 virtual ModResult OnDelBan(User* source, Channel* chan, const std::string &banmask)
120 irc::string listitem = banmask.c_str();
121 irc::string thischan = chan->name.c_str();
122 for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); i++)
124 irc::string target = i->mask.c_str();
125 irc::string tchan = i->channel.c_str();
126 if ((listitem == target) && (tchan == thischan))
128 TimedBanList.erase(i);
132 return MOD_RES_PASSTHRU;
135 virtual void OnBackgroundTimer(time_t curtime)
137 for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();)
139 if (curtime > i->expire)
141 std::string chan = i->channel;
142 std::string mask = i->mask;
143 Channel* cr = ServerInstance->FindChan(chan);
144 i = TimedBanList.erase(i);
147 std::vector<std::string> setban;
148 setban.push_back(chan);
149 setban.push_back("-b");
150 setban.push_back(mask);
153 std::string expiry = "*** Timed ban on " + chan + " expired.";
154 cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str());
155 ServerInstance->PI->SendChannelNotice(cr, '@', expiry);
157 ServerInstance->SendGlobalMode(setban, ServerInstance->FakeClient);
165 virtual Version GetVersion()
167 return Version("Adds timed bans", VF_COMMON | VF_VENDOR);
171 MODULE_INIT(ModuleTimedBans)