mirror of
https://github.com/anope/anope.git
synced 2026-07-03 02:43:13 +02:00
Add an expiry option to /cs ban
This commit is contained in:
@@ -397,7 +397,7 @@ privilege
|
||||
/*
|
||||
* BAN privilege.
|
||||
*
|
||||
* Used by chanserv/ban and chanserv/tban.
|
||||
* Used by chanserv/ban.
|
||||
*
|
||||
* Users with this permission can use the BAN command.
|
||||
*/
|
||||
@@ -879,16 +879,6 @@ command { service = "ChanServ"; name = "AKICK"; command = "chanserv/akick"; }
|
||||
module { name = "cs_ban" }
|
||||
command { service = "ChanServ"; name = "BAN"; command = "chanserv/ban"; }
|
||||
|
||||
/*
|
||||
* cs_tban
|
||||
*
|
||||
* Provides the command chanserv/tban.
|
||||
*
|
||||
* Used for banning users from channels for a specified time.
|
||||
*/
|
||||
module { name = "cs_tban" }
|
||||
command { service = "ChanServ"; name = "TBAN"; command = "chanserv/tban"; }
|
||||
|
||||
/*
|
||||
* cs_clone
|
||||
*
|
||||
|
||||
+80
-19
@@ -13,52 +13,95 @@
|
||||
|
||||
#include "module.h"
|
||||
|
||||
static Module *me;
|
||||
|
||||
class TempBan : public CallBack
|
||||
{
|
||||
private:
|
||||
Anope::string channel;
|
||||
Anope::string mask;
|
||||
|
||||
public:
|
||||
TempBan(time_t seconds, Channel *c, const Anope::string &banmask) : CallBack(me, seconds), channel(c->name), mask(banmask) { }
|
||||
|
||||
void Tick(time_t ctime) anope_override
|
||||
{
|
||||
Channel *c = Channel::Find(this->channel);
|
||||
if (c)
|
||||
c->RemoveMode(NULL, CMODE_BAN, this->mask);
|
||||
}
|
||||
};
|
||||
|
||||
class CommandCSBan : public Command
|
||||
{
|
||||
public:
|
||||
CommandCSBan(Module *creator) : Command(creator, "chanserv/ban", 2, 3)
|
||||
CommandCSBan(Module *creator) : Command(creator, "chanserv/ban", 2, 4)
|
||||
{
|
||||
this->SetDesc(_("Bans a selected nick on a channel"));
|
||||
this->SetSyntax(_("\037channel\037 \037nick\037 [\037reason\037]"));
|
||||
this->SetSyntax(_("\037channel\037 \037mask\037 [\037reason\037]"));
|
||||
this->SetDesc(_("Bans a given nick or mask on a channel"));
|
||||
this->SetSyntax(_("\037channel\037 [+\037expiry\037] \037nick\037 [\037reason\037]"));
|
||||
this->SetSyntax(_("\037channel\037 [+\037expiry\037] \037mask\037 [\037reason\037]"));
|
||||
}
|
||||
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
|
||||
{
|
||||
const Anope::string &chan = params[0];
|
||||
const Anope::string &target = params[1];
|
||||
Anope::string reason = params.size() > 2 ? params[2] : "Requested";
|
||||
|
||||
ChannelInfo *ci = ChannelInfo::Find(params[0]);
|
||||
ChannelInfo *ci = ChannelInfo::Find(chan);
|
||||
if (ci == NULL)
|
||||
{
|
||||
source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
|
||||
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
Anope::string expiry, target, reason;
|
||||
time_t ban_time;
|
||||
if (params[1][0] == '+')
|
||||
{
|
||||
ban_time = Anope::DoTime(params[1]);
|
||||
if (params.size() < 3)
|
||||
{
|
||||
this->SendSyntax(source);
|
||||
return;
|
||||
}
|
||||
target = params[2];
|
||||
reason = "Requested";
|
||||
if (params.size() > 3)
|
||||
reason = params[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
ban_time = 0;
|
||||
target = params[1];
|
||||
reason = "Requested";
|
||||
if (params.size() > 2)
|
||||
reason = params[2];
|
||||
if (params.size() > 3)
|
||||
reason += " " + params[3];
|
||||
}
|
||||
|
||||
if (reason.length() > Config->CSReasonMax)
|
||||
reason = reason.substr(0, Config->CSReasonMax);
|
||||
|
||||
Channel *c = ci->c;
|
||||
User *u = source.GetUser();
|
||||
User *u2 = User::Find(target, true);
|
||||
|
||||
AccessGroup u_access = source.AccessFor(ci);
|
||||
|
||||
if (reason.length() > Config->CSReasonMax)
|
||||
reason = reason.substr(0, Config->CSReasonMax);
|
||||
|
||||
if (!c)
|
||||
source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
|
||||
else if (!u_access.HasPriv("BAN"))
|
||||
source.Reply(ACCESS_DENIED);
|
||||
/*
|
||||
* Dont ban/kick the user on channels where he is excepted
|
||||
* to prevent services <-> server wars.
|
||||
*/
|
||||
else if (u2)
|
||||
{
|
||||
AccessGroup u2_access = ci->AccessFor(u2);
|
||||
|
||||
if (u != u2 && ci->HasFlag(CI_PEACE) && u2_access >= u_access)
|
||||
source.Reply(ACCESS_DENIED);
|
||||
/*
|
||||
* Dont ban/kick the user on channels where he is excepted
|
||||
* to prevent services <-> server wars.
|
||||
*/
|
||||
else if (ci->c->MatchesList(u2, CMODE_EXCEPT))
|
||||
source.Reply(CHAN_EXCEPTED, u2->nick.c_str(), ci->name.c_str());
|
||||
else if (u2->IsProtected())
|
||||
@@ -70,7 +113,15 @@ class CommandCSBan : public Command
|
||||
// XXX need a way to detect if someone is overriding
|
||||
Log(LOG_COMMAND, source, this, ci) << "for " << mask;
|
||||
|
||||
c->SetMode(NULL, CMODE_BAN, mask);
|
||||
if (!c->HasMode(CMODE_BAN, mask))
|
||||
{
|
||||
c->SetMode(NULL, CMODE_BAN, mask);
|
||||
if (ban_time)
|
||||
{
|
||||
new TempBan(ban_time, c, mask);
|
||||
source.Reply(_("Ban on \2%s\2 expires in %s."), mask.c_str(), Anope::Duration(ban_time, source.GetAccount()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/* We still allow host banning while not allowing to kick */
|
||||
if (!c->FindUser(u2))
|
||||
@@ -86,7 +137,15 @@ class CommandCSBan : public Command
|
||||
{
|
||||
Log(LOG_COMMAND, source, this, ci) << "for " << target;
|
||||
|
||||
c->SetMode(NULL, CMODE_BAN, target);
|
||||
if (!c->HasMode(CMODE_BAN, target))
|
||||
{
|
||||
c->SetMode(NULL, CMODE_BAN, target);
|
||||
if (ban_time)
|
||||
{
|
||||
new TempBan(ban_time, c, target);
|
||||
source.Reply(_("Ban on \2%s\2 expires in %s."), target.c_str(), Anope::Duration(ban_time, source.GetAccount()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int matched = 0, kicked = 0;
|
||||
for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;)
|
||||
@@ -127,7 +186,9 @@ class CommandCSBan : public Command
|
||||
{
|
||||
this->SendSyntax(source);
|
||||
source.Reply(" ");
|
||||
source.Reply(_("Bans a selected nick on a channel.\n"
|
||||
source.Reply(_("Bans a given nick or mask on a channel. An optional expiry may\n"
|
||||
"be given to cause services to remove the ban after a set amount\n"
|
||||
"of time.\n"
|
||||
" \n"
|
||||
"By default, limited to AOPs or those with level 5 access\n"
|
||||
"and above on the channel. Channel founders may ban masks."));
|
||||
@@ -143,7 +204,7 @@ class CSBan : public Module
|
||||
CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), commandcsban(this)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
me = this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/* cs_tban.c - Bans the user for a given length of time
|
||||
*
|
||||
* (C) 2003-2012 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"
|
||||
|
||||
static Module *me;
|
||||
|
||||
class TempBan : public CallBack
|
||||
{
|
||||
private:
|
||||
Reference<Channel> chan;
|
||||
Anope::string mask;
|
||||
|
||||
public:
|
||||
TempBan(time_t seconds, Channel *c, const Anope::string &banmask) : CallBack(me, seconds), chan(c), mask(banmask) { }
|
||||
|
||||
void Tick(time_t ctime) anope_override
|
||||
{
|
||||
if (chan && chan->ci)
|
||||
chan->RemoveMode(NULL, CMODE_BAN, mask);
|
||||
}
|
||||
};
|
||||
|
||||
class CommandCSTBan : public Command
|
||||
{
|
||||
public:
|
||||
CommandCSTBan(Module *creator) : Command(creator, "chanserv/tban", 3, 3)
|
||||
{
|
||||
this->SetDesc(_("Bans the user for a given length of time"));
|
||||
this->SetSyntax(_("\037channel\037 \037nick\037 \037time\037"));
|
||||
}
|
||||
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
|
||||
{
|
||||
Channel *c = Channel::Find(params[0]);
|
||||
|
||||
const Anope::string &nick = params[1];
|
||||
const Anope::string &time = params[2];
|
||||
|
||||
User *u2;
|
||||
if (!c)
|
||||
source.Reply(CHAN_X_NOT_IN_USE, params[0].c_str());
|
||||
else if (!c->ci)
|
||||
source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str());
|
||||
else if (!source.AccessFor(c->ci).HasPriv("BAN"))
|
||||
source.Reply(ACCESS_DENIED);
|
||||
else if (!(u2 = User::Find(nick, true)))
|
||||
source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
|
||||
else if (c->MatchesList(u2, CMODE_EXCEPT))
|
||||
source.Reply(CHAN_EXCEPTED, u2->nick.c_str(), c->ci->name.c_str());
|
||||
else if (u2->IsProtected())
|
||||
source.Reply(ACCESS_DENIED);
|
||||
else
|
||||
{
|
||||
time_t t = Anope::DoTime(time);
|
||||
Anope::string mask = c->ci->GetIdealBan(u2);
|
||||
c->SetMode(NULL, CMODE_BAN, mask);
|
||||
new TempBan(t, c, mask);
|
||||
|
||||
Log(LOG_COMMAND, source, this, c->ci) << "for " << mask << " to expire in " << Anope::Duration(t);
|
||||
|
||||
source.Reply(_("%s banned from %s, will auto-expire in %s."), mask.c_str(), c->name.c_str(), Anope::Duration(t).c_str());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
|
||||
{
|
||||
this->OnSyntaxError(source, "");
|
||||
source.Reply(" ");
|
||||
source.Reply(_("Bans the user for a given length of time.\n"
|
||||
" \n"
|
||||
"Bans the given user from a channel for a specified length of\n"
|
||||
"time. If the ban is removed before by hand, it\n"
|
||||
"will NOT be replaced."));
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class CSTBan : public Module
|
||||
{
|
||||
CommandCSTBan commandcstban;
|
||||
|
||||
public:
|
||||
CSTBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), commandcstban(this)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
me = this;
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(CSTBan)
|
||||
Reference in New Issue
Block a user