summaryrefslogtreecommitdiff
path: root/modules/commands/cs_suspend.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-05 05:35:31 -0400
committerAdam <Adam@anope.org>2011-08-05 05:35:31 -0400
commite66063e6304538d34c40460ca0aa2be5ddb6bdec (patch)
treef50fe31097160f8f794669809e4f4ef87f477672 /modules/commands/cs_suspend.cpp
parent9ec18a3b020932eee6242c878149c484f49b13cb (diff)
Rewrote the example configurations and split them
up into seperate files for each pseudo client. Also reorganized how the modules are stored, and made most of the old "extra" modules "core"
Diffstat (limited to 'modules/commands/cs_suspend.cpp')
-rw-r--r--modules/commands/cs_suspend.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp
new file mode 100644
index 000000000..d59ffb44b
--- /dev/null
+++ b/modules/commands/cs_suspend.cpp
@@ -0,0 +1,158 @@
+/* ChanServ core functions
+ *
+ * (C) 2003-2011 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+/*************************************************************************/
+
+#include "module.h"
+
+class CommandCSSuspend : public Command
+{
+ public:
+ CommandCSSuspend(Module *creator) : Command(creator, "chanserv/suspend", 1, 2)
+ {
+ this->SetDesc(_("Prevent a channel from being used preserving channel data and settings"));
+ this->SetSyntax(_("\037channel\037 [\037reason\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &reason = params.size() > 1 ? params[1] : "";
+
+ User *u = source.u;
+
+ if (Config->ForceForbidReason && reason.empty())
+ {
+ this->OnSyntaxError(source, "");
+ return;
+ }
+
+ if (readonly)
+ source.Reply(READ_ONLY_MODE);
+
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (ci == NULL)
+ {
+ source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
+ return;
+ }
+
+ ci->SetFlag(CI_SUSPENDED);
+ ci->Extend("suspend_by", new ExtensibleItemRegular<Anope::string>(u->nick));
+ if (!reason.empty())
+ ci->Extend("suspend_reason", new ExtensibleItemRegular<Anope::string>(u->nick));
+
+ if (ci->c)
+ {
+ for (CUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; )
+ {
+ UserContainer *uc = *it++;
+
+ if (uc->user->HasMode(UMODE_OPER))
+ continue;
+
+ ci->c->Kick(NULL, uc->user, "%s", !reason.empty() ? reason.c_str() : translate(uc->user, _("This channel has been suspended.")));
+ }
+ }
+
+ Log(LOG_ADMIN, u, this, ci) << (!reason.empty() ? reason : "No reason");
+ source.Reply(_("Channel \002%s\002 is now suspended."), ci->name.c_str());
+
+ FOREACH_MOD(I_OnChanSuspend, OnChanSuspend(ci));
+
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand)
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Disallows anyone from using the given channel.\n"
+ "May be cancelled by using the UNSUSPEND\n"
+ "command to preserve all previous channel data/settings.\n"
+ " \n"
+ "Reason may be required on certain networks."));
+ return true;
+ }
+};
+
+class CommandCSUnSuspend : public Command
+{
+ public:
+ CommandCSUnSuspend(Module *creator) : Command(creator, "chanserv/unsuspend", 1, 1)
+ {
+ this->SetDesc(_("Releases a suspended channel"));
+ this->SetSyntax(_("\037channel\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ User *u = source.u;
+
+ if (readonly)
+ source.Reply(READ_ONLY_MODE);
+
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (ci == NULL)
+ {
+ source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
+ return;
+ }
+
+ /* Only UNSUSPEND already suspended channels */
+ if (!ci->HasFlag(CI_SUSPENDED))
+ {
+ source.Reply(_("Couldn't release channel \002%s\002!"), ci->name.c_str());
+ return;
+ }
+
+ Anope::string by, reason;
+ ci->GetExtRegular("suspend_by", by);
+ ci->GetExtRegular("suspend_reason", reason);
+ Log(LOG_ADMIN, u, this, ci) << " which was suspended by " << by << " for: " << (!reason.empty() ? reason : "No reason");
+
+ ci->UnsetFlag(CI_SUSPENDED);
+ ci->Shrink("suspend_by");
+ ci->Shrink("suspend_reason");
+
+ source.Reply(_("Channel \002%s\002 is now released."), ci->name.c_str());
+
+ FOREACH_MOD(I_OnChanUnsuspend, OnChanUnsuspend(ci));
+
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand)
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Releases a suspended channel. All data and settings\n"
+ "are preserved from before the suspension."));
+ return true;
+ }
+};
+
+class CSSuspend : public Module
+{
+ CommandCSSuspend commandcssuspend;
+ CommandCSUnSuspend commandcsunsuspend;
+
+ public:
+ CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
+ commandcssuspend(this), commandcsunsuspend(this)
+ {
+ this->SetAuthor("Anope");
+
+ ModuleManager::RegisterService(&commandcssuspend);
+ ModuleManager::RegisterService(&commandcsunsuspend);
+ }
+};
+
+MODULE_INIT(CSSuspend)