summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-02-14 00:28:41 -0500
committerAdam <Adam@anope.org>2013-02-14 01:20:18 -0500
commit7656c25e38529013e53bd9e95a3060d3baf1f8f2 (patch)
treecb4d48db62935463405d7a2998703f9849244cd1
parent5cf1edeb6efe6277f5674e0647f2c9c091346ddc (diff)
Made chanserv/unban with no parameters unban you in every channel you have access in
-rw-r--r--include/channels.h3
-rw-r--r--modules/commands/cs_unban.cpp33
-rw-r--r--src/channels.cpp11
3 files changed, 40 insertions, 7 deletions
diff --git a/include/channels.h b/include/channels.h
index b66dc1c3d..06132a32f 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -277,8 +277,9 @@ class CoreExport Channel : public Base, public Extensible
/** Unbans a user from this channel.
* @param u The user to unban
* @param full Whether or not to match using the user's real host and IP
+ * @return whether or not a ban was removed
*/
- void Unban(const User *u, bool full = false);
+ bool Unban(const User *u, bool full = false);
/** Finds a channel
* @param name The channel to find
diff --git a/modules/commands/cs_unban.cpp b/modules/commands/cs_unban.cpp
index 41941a047..eaf371a34 100644
--- a/modules/commands/cs_unban.cpp
+++ b/modules/commands/cs_unban.cpp
@@ -16,7 +16,7 @@
class CommandCSUnban : public Command
{
public:
- CommandCSUnban(Module *creator) : Command(creator, "chanserv/unban", 1, 2)
+ CommandCSUnban(Module *creator) : Command(creator, "chanserv/unban", 0, 2)
{
this->SetDesc(_("Remove all bans preventing a user from entering a channel"));
this->SetSyntax(_("\037channel\037 [\037nick\037]"));
@@ -24,6 +24,31 @@ class CommandCSUnban : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
+ if (params.empty())
+ {
+ if (!source.GetUser())
+ return;
+
+ std::deque<ChannelInfo *> queue;
+ source.GetAccount()->GetChannelReferences(queue);
+
+ unsigned count = 0;
+ for (unsigned i = 0; i < queue.size(); ++i)
+ {
+ ChannelInfo *ci = queue[i];
+
+ if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN"))
+ continue;
+
+ if (ci->c->Unban(source.GetUser(), true))
+ ++count;
+ }
+
+ source.Reply(_("You have been unbanned from %d channels."), count);
+
+ return;
+ }
+
ChannelInfo *ci = ChannelInfo::Find(params[0]);
if (ci == NULL)
{
@@ -60,8 +85,6 @@ class CommandCSUnban : public Command
source.Reply(_("You have been unbanned from \002%s\002."), ci->c->name.c_str());
else
source.Reply(_("\002%s\002 has been unbanned from \002%s\002."), u2->nick.c_str(), ci->c->name.c_str());
-
- return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
@@ -69,7 +92,9 @@ class CommandCSUnban : public Command
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Tells %s to remove all bans preventing you or the given\n"
- "user from entering the given channel.\n"
+ "user from entering the given channel. If no channel is\n"
+ "given, all bans affecting you in channels you have access\n"
+ "in are removed.\n"
" \n"
"By default, limited to AOPs or those with level 5 and above\n"
"on the channel."), source.service->nick.c_str());
diff --git a/src/channels.cpp b/src/channels.cpp
index 9265fdacf..2e6023dae 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -996,10 +996,12 @@ void Channel::SetCorrectModes(User *user, bool give_modes, bool check_noop)
}
}
-void Channel::Unban(const User *u, bool full)
+bool Channel::Unban(const User *u, bool full)
{
if (!this->HasMode("BAN"))
- return;
+ return false;
+
+ bool ret = false;
std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = this->GetModeList("BAN");
for (; bans.first != bans.second;)
@@ -1007,8 +1009,13 @@ void Channel::Unban(const User *u, bool full)
Entry ban("BAN", bans.first->second);
++bans.first;
if (ban.Matches(u, full))
+ {
this->RemoveMode(NULL, "BAN", ban.GetMask());
+ ret = true;
+ }
}
+
+ return ret;
}
Channel* Channel::Find(const Anope::string &name)