+ for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+ {
+ if (!strcasecmp(i->data.c_str(), parameters[2].c_str()))
+ {
+ user->WriteServ("NOTICE "+std::string(user->nick)+" :The ban "+parameters[2]+" is already on the banlist of "+parameters[0]);
+ return CMD_FAILURE;
+ }
+ }
+ TimedBan T;
+ std::string channelname = parameters[0];
+ long duration = ServerInstance->Duration(parameters[1]);
+ unsigned long expire = duration + ServerInstance->Time();
+ if (duration < 1)
+ {
+ user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban time");
+ return CMD_FAILURE;
+ }
+ std::string mask = parameters[2];
+ std::vector<std::string> setban;
+ setban.push_back(parameters[0]);
+ setban.push_back("+b");
+ setban.push_back(parameters[2]);
+ // use CallCommandHandler to make it so that the user sets the mode
+ // themselves
+ ServerInstance->CallCommandHandler("MODE",setban,user);
+ /* Check if the ban was actually added (e.g. banlist was NOT full) */
+ bool was_added = false;
+ for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+ if (!strcasecmp(i->data.c_str(), mask.c_str()))
+ was_added = true;
+ if (was_added)
+ {
+ CUList tmp;
+ T.channel = channelname;
+ T.mask = mask;
+ T.expire = expire;
+ TimedBanList.push_back(T);
+ channel->WriteAllExcept(user, 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);
+ if (ServerInstance->Config->AllowHalfop)
+ channel->WriteAllExcept(user, 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);
+ return CMD_SUCCESS;
+ }
+ return CMD_FAILURE;