+ for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+ {
+ if (!strcasecmp(i->data,parameters[2]))
+ {
+ user->WriteServ("NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0]));
+ return CMD_FAILURE;
+ }
+ }
+ TimedBan T;
+ std::string channelname = parameters[0];
+ long duration = ServerInstance->Duration(parameters[1]);
+ unsigned long expire = duration + time(NULL);
+ if (duration < 1)
+ {
+ user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban time");
+ return CMD_FAILURE;
+ }
+ std::string mask = parameters[2];
+ const char *setban[32];
+ setban[0] = parameters[0];
+ setban[1] = "+b";
+ setban[2] = parameters[2];
+ // use CallCommandHandler to make it so that the user sets the mode
+ // themselves
+ ServerInstance->CallCommandHandler("MODE",setban,3,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,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, user->nick, mask.c_str(), duration);
+ channel->WriteAllExcept(user, true, '%', tmp, "NOTICE %s :%s added a timed ban on %s lasting for %ld seconds.", channel->name, user->nick, mask.c_str(), duration);
+ return CMD_SUCCESS;
+ }
+ return CMD_FAILURE;