1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
14 /* $ModDesc: Adds timed bans */
20 class TimedBan : public classbase
28 typedef std::vector<TimedBan> timedbans;
29 timedbans TimedBanList;
33 class cmd_tban : public Command
36 cmd_tban (InspIRCd* Instance) : Command(Instance,"TBAN", 0, 3)
38 this->source = "m_timedbans.so";
39 syntax = "<channel> <duration> <banmask>";
40 TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END);
43 CmdResult Handle (const char** parameters, int pcnt, User *user)
45 Channel* channel = ServerInstance->FindChan(parameters[0]);
48 int cm = channel->GetStatus(user);
49 if ((cm == STATUS_HOP) || (cm == STATUS_OP))
51 if (!ServerInstance->IsValidMask(parameters[2]))
53 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban mask");
56 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
58 if (!strcasecmp(i->data,parameters[2]))
60 user->WriteServ("NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0]));
65 std::string channelname = parameters[0];
66 long duration = ServerInstance->Duration(parameters[1]);
67 unsigned long expire = duration + time(NULL);
70 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban time");
73 std::string mask = parameters[2];
74 const char *setban[32];
75 setban[0] = parameters[0];
77 setban[2] = parameters[2];
78 // use CallCommandHandler to make it so that the user sets the mode
80 ServerInstance->CallCommandHandler("MODE",setban,3,user);
81 /* Check if the ban was actually added (e.g. banlist was NOT full) */
82 bool was_added = false;
83 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
84 if (!strcasecmp(i->data,mask.c_str()))
88 T.channel = channelname;
91 TimedBanList.push_back(T);
92 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s added a timed ban on %s lasting for %ld seconds.", channel->name, user->nick, mask.c_str(), duration);
97 else user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, channel->name);
100 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
105 class ModuleTimedBans : public Module
109 ModuleTimedBans(InspIRCd* Me)
113 mycommand = new cmd_tban(ServerInstance);
114 ServerInstance->AddCommand(mycommand);
115 TimedBanList.clear();
118 virtual ~ModuleTimedBans()
120 TimedBanList.clear();
123 void Implements(char* List)
125 List[I_OnDelBan] = List[I_OnBackgroundTimer] = 1;
128 virtual int OnDelBan(User* source, Channel* chan, const std::string &banmask)
130 irc::string listitem = banmask.c_str();
131 irc::string thischan = chan->name;
132 for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++)
134 irc::string target = i->mask.c_str();
135 irc::string tchan = i->channel.c_str();
136 if ((listitem == target) && (tchan == thischan))
138 TimedBanList.erase(i);
145 virtual void OnBackgroundTimer(time_t curtime)
151 for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++)
153 if (curtime > i->expire)
155 Channel* cr = ServerInstance->FindChan(i->channel);
159 cr->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :Timed ban on %s expired.", cr->name, i->mask.c_str());
160 const char *setban[3];
161 setban[0] = i->channel.c_str();
163 setban[2] = i->mask.c_str();
165 /* Send mode remotely*/
166 std::deque<std::string> n;
167 n.push_back(setban[0]);
169 n.push_back(setban[2]);
170 ServerInstance->SendMode(setban,3, ServerInstance->FakeClient);
171 Event rmode((char *)&n, NULL, "send_mode");
172 rmode.Send(ServerInstance);
176 /* Where the hell did our channel go?! */
177 TimedBanList.erase(i);
179 // we used to delete the item here, but we dont need to as the servermode above does it for us,
186 virtual Version GetVersion()
188 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
192 MODULE_INIT(ModuleTimedBans)