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;
87 T.expire = expire + (IS_REMOTE(user) ? 5 : 0);
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);
93 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
95 return ROUTE_BROADCAST;
99 class ModuleTimedBans : public Module
106 ServerInstance->AddCommand(&cmd);
107 TimedBanList.clear();
108 Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
109 ServerInstance->Modules->Attach(eventlist, this, 2);
112 virtual ~ModuleTimedBans()
114 TimedBanList.clear();
117 virtual ModResult OnDelBan(User* source, Channel* chan, const std::string &banmask)
119 irc::string listitem = banmask.c_str();
120 irc::string thischan = chan->name.c_str();
121 for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); i++)
123 irc::string target = i->mask.c_str();
124 irc::string tchan = i->channel.c_str();
125 if ((listitem == target) && (tchan == thischan))
127 TimedBanList.erase(i);
131 return MOD_RES_PASSTHRU;
134 virtual void OnBackgroundTimer(time_t curtime)
137 for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();)
139 if (curtime > i->expire)
141 expired.push_back(*i);
142 i = TimedBanList.erase(i);
148 for (timedbans::iterator i = expired.begin(); i != expired.end(); i++)
150 std::string chan = i->channel;
151 std::string mask = i->mask;
152 Channel* cr = ServerInstance->FindChan(chan);
155 std::vector<std::string> setban;
156 setban.push_back(chan);
157 setban.push_back("-b");
158 setban.push_back(mask);
161 std::string expiry = "*** Timed ban on " + chan + " expired.";
162 cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str());
163 ServerInstance->PI->SendChannelNotice(cr, '@', expiry);
165 ServerInstance->SendGlobalMode(setban, ServerInstance->FakeClient);
170 virtual Version GetVersion()
172 return Version("Adds timed bans", VF_COMMON | VF_VENDOR);
176 MODULE_INIT(ModuleTimedBans)