/* cs_tban.c - Bans the user for a given length of time * * (C) 2003-2010 Anope Team * Contact us at team@anope.org * * Based on the original module by Rob * Included in the Anope module pack since Anope 1.7.8 * Anope Coder: Rob * * Please read COPYING and README for further details. * * Send bug reports to the Anope Coder instead of the module * author, because any changes since the inclusion into anope * are not supported by the original author. */ /*************************************************************************/ #include "module.h" #define AUTHOR "Rob" void mySendResponse(User *u, const Anope::string &channel, const Anope::string &mask, const Anope::string &time); void addBan(Channel *c, time_t timeout, const Anope::string &banmask); int canBanUser(Channel *c, User *u, User *u2); void mAddLanguages(); static Module *me = NULL; enum { TBAN_HELP, TBAN_SYNTAX, TBAN_HELP_DETAIL, TBAN_RESPONSE, LANG_NUM_STRINGS }; class CommandCSTBan : public Command { public: CommandCSTBan() : Command("TBAN", 3, 3) { } CommandReturn Execute(User *u, const std::vector ¶ms) { Anope::string mask; Channel *c; User *u2 = NULL; Anope::string chan = params[0]; Anope::string nick = params[1]; Anope::string time = params[2]; if (!(c = findchan(chan))) notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!(u2 = finduser(nick))) notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, nick.c_str()); else if (canBanUser(c, u, u2)) { get_idealban(c->ci, u2, mask); addBan(c, dotime(time), mask); mySendResponse(u, chan, mask, time); } return MOD_CONT; } bool OnHelp(User *u, const Anope::string &subcommand) { this->OnSyntaxError(u, ""); u->SendMessage(Config.s_ChanServ, " "); me->NoticeLang(Config.s_ChanServ, u, TBAN_HELP_DETAIL); return true; } void OnSyntaxError(User *u, const Anope::string &subcommand) { me->NoticeLang(Config.s_ChanServ, u, TBAN_SYNTAX); } void OnServHelp(User *u) { me->NoticeLang(Config.s_ChanServ, u, TBAN_HELP); } }; class CSTBan : public Module { CommandCSTBan commandcstban; public: CSTBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { me = this; this->AddCommand(ChanServ, &commandcstban); this->SetAuthor(AUTHOR); this->SetType(SUPPORTED); const char *langtable_en_us[] = { " TBAN Bans the user for a given length of time", "Syntax: TBAN channel nick time", "Bans the given user from a channel for a specified length of\n" "time. If the ban is removed before by hand, it will NOT be replaced.", "%s banned from %s, will auto-expire in %s" }; const char *langtable_nl[] = { " TBAN Verban een gebruiker voor een bepaalde tijd", "Syntax: TBAN kanaal nick tijd", "Verbant de gegeven gebruiken van het gegeven kanaal voor de\n" "gegeven tijdsduur. Als de verbanning eerder wordt verwijderd,\n" "zal deze NIET worden vervangen.", "%s verbannen van %s, zal verlopen in %s" }; const char *langtable_de[] = { " TBAN Bant ein User fьr eine bestimmte Zeit aus ein Channel", "Syntax: TBAN Channel Nickname Zeit", "Bant ein User fьr eine bestimmte Zeit aus ein Channel\n" "Wenn der Ban manuell entfernt wird, wird es NICHT ersetzt.", "%s gebannt von %s, wird auto-auslaufen in %s" }; const char *langtable_pt[] = { " TBAN Bane o usuбrio por um determinado perнodo de tempo", "Sintaxe: TBAN canal nick tempo", "Bane de um canal o usuбrio especificado por um determinado perнodo de\n" "tempo. Se o ban for removido manualmente antes do tempo, ele nгo serб recolocado.", "%s foi banido do %s, irб auto-expirar em %s" }; const char *langtable_ru[] = { " TBAN Банит пользователя на указанный промежуток времени", "Синтаксис: TBAN #канал ник время", "Банит пользователя на указанный промежуток времени в секундах\n" "Примечание: удаленный вручную (до своего истечения) бан НЕ БУДЕТ\n" "переустановлен сервисами автоматически!", "Установленный бан %s на канале %s истечет через %s секунд" }; const char *langtable_it[] = { " TBAN Banna l'utente per un periodo di tempo specificato", "Sintassi: TBAN canale nick tempo", "Banna l'utente specificato da un canale per un periodo di tempo\n" "specificato. Se il ban viene rimosso a mano prima della scadenza, NON verrа rimpiazzato.", "%s bannato da %s, scadrа automaticamente tra %s" }; this->InsertLanguage(LANG_EN_US, LANG_NUM_STRINGS, langtable_en_us); this->InsertLanguage(LANG_NL, LANG_NUM_STRINGS, langtable_nl); this->InsertLanguage(LANG_DE, LANG_NUM_STRINGS, langtable_de); this->InsertLanguage(LANG_PT, LANG_NUM_STRINGS, langtable_pt); this->InsertLanguage(LANG_RU, LANG_NUM_STRINGS, langtable_ru); this->InsertLanguage(LANG_IT, LANG_NUM_STRINGS, langtable_it); } }; void mySendResponse(User *u, const Anope::string &channel, const Anope::string &mask, const Anope::string &time) { me->NoticeLang(Config.s_ChanServ, u, TBAN_RESPONSE, mask.c_str(), channel.c_str(), time.c_str()); } class TempBan : public CallBack { private: Anope::string chan; Anope::string mask; public: TempBan(time_t seconds, const Anope::string &channel, const Anope::string &banmask) : CallBack(me, seconds), chan(channel), mask(banmask) { } void Tick(time_t ctime) { Channel *c; if ((c = findchan(chan)) && c->ci) c->RemoveMode(NULL, CMODE_BAN, mask); } }; void addBan(Channel *c, time_t timeout, const Anope::string &banmask) { c->SetMode(NULL, CMODE_BAN, banmask); new TempBan(timeout, c->name, banmask); } int canBanUser(Channel *c, User *u, User *u2) { ChannelInfo *ci = c->ci; int ok = 0; if (!check_access(u, ci, CA_BAN)) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else if (is_excepted(ci, u2)) notice_lang(Config.s_ChanServ, u, CHAN_EXCEPTED, u2->nick.c_str(), ci->name.c_str()); else if (u2->IsProtected()) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else ok = 1; return ok; } MODULE_INIT(CSTBan)