1
0
mirror of https://github.com/anope/anope.git synced 2026-06-30 04:56:38 +02:00
Files
anope/src/modules/cs_tban.c
T
2009-02-11 00:07:53 +00:00

228 lines
6.3 KiB
C

/* cs_tban.c - Bans the user for a given length of time
*
* (C) 2003-2009 Anope Team
* Contact us at team@anope.org
*
* Based on the original module by Rob <rob@anope.org>
* Included in the Anope module pack since Anope 1.7.8
* Anope Coder: Rob <rob@anope.org>
*
* 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"
#define VERSION "$Id$"
void myHelp(User *u);
void mySendResponse(User *u, const char *channel, char *mask, const char *time);
void addBan(Channel *c, time_t timeout, char *banmask);
int delBan(int argc, char **argv);
int canBanUser(Channel *c, User *u, User *u2);
void mAddLanguages();
static Module *me = NULL;
#define LANG_NUM_STRINGS 4
#define TBAN_HELP 0
#define TBAN_SYNTAX 1
#define TBAN_HELP_DETAIL 2
#define TBAN_RESPONSE 3
class CommandCSTBan : public Command
{
public:
CommandCSTBan() : Command("TBAN", 3, 3)
{
}
CommandReturn Execute(User *u, std::vector<std::string> &params)
{
char mask[BUFSIZE];
Channel *c;
User *u2 = NULL;
const char *chan = params[0].c_str();
const char *nick = params[1].c_str();
const char *time = params[2].c_str();
if (!(c = findchan(chan)))
notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
else if (!(u2 = finduser(nick)))
notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, nick);
else
{
if (canBanUser(c, u, u2))
{
get_idealban(c->ci, u2, mask, sizeof(mask));
addBan(c, dotime(time), mask);
mySendResponse(u, chan, mask, time);
}
}
return MOD_CONT;
}
bool OnHelp(User *u, const std::string &subcommand)
{
this->OnSyntaxError(u);
ircdproto->SendMessage(findbot(s_ChanServ), u->nick, " ");
me->NoticeLang(s_ChanServ, u, TBAN_HELP_DETAIL);
return true;
}
void OnSyntaxError(User *u)
{
me->NoticeLang(s_ChanServ, u, TBAN_SYNTAX);
}
};
class CSTBan : public Module
{
public:
CSTBan(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
me = this;
this->SetChanHelp(myHelp);
this->AddCommand(CHANSERV, new CommandCSTBan(), MOD_HEAD);
this->SetAuthor(AUTHOR);
this->SetVersion(VERSION);
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 myHelp(User *u)
{
me->NoticeLang(s_ChanServ, u, TBAN_HELP);
}
void mySendResponse(User *u, const char *channel, char *mask, const char *time)
{
me->NoticeLang(s_ChanServ, u, TBAN_RESPONSE, mask, channel, time);
}
void addBan(Channel *c, time_t timeout, char *banmask)
{
const char *av[3];
char *cb[2];
cb[0] = c->name;
cb[1] = banmask;
av[0] = "+b";
av[1] = banmask;
ircdproto->SendMode(whosends(c->ci), c->name, "+b %s", av[1]);
chan_set_modes(s_ChanServ, c, 2, av, 1);
me->AddCallback("tban", time(NULL) + timeout, delBan, 2, cb);
}
int delBan(int argc, char **argv)
{
const char *av[3];
Channel *c;
av[0] = "-b";
av[1] = argv[1];
if ((c = findchan(argv[0])) && c->ci)
{
ircdproto->SendMode(whosends(c->ci), c->name, "-b %s", av[1]);
chan_set_modes(s_ChanServ, c, 2, av, 1);
}
return MOD_CONT;
}
int canBanUser(Channel * c, User * u, User * u2)
{
ChannelInfo *ci;
int ok = 0;
if (!(ci = c->ci))
notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
else if (ci->flags & CI_FORBIDDEN)
notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, c->name);
else if (!check_access(u, ci, CA_BAN))
notice_lang(s_ChanServ, u, ACCESS_DENIED);
else if (ircd->except && is_excepted(ci, u2))
notice_lang(s_ChanServ, u, CHAN_EXCEPTED, u2->nick, ci->name);
else if (ircd->protectedumode && is_protected(u2))
notice_lang(s_ChanServ, u, PERMISSION_DENIED);
else
ok = 1;
return ok;
}
MODULE_INIT("cs_tban", CSTBan)