summaryrefslogtreecommitdiff
path: root/src/core/ns_suspend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ns_suspend.cpp')
-rw-r--r--src/core/ns_suspend.cpp201
1 files changed, 201 insertions, 0 deletions
diff --git a/src/core/ns_suspend.cpp b/src/core/ns_suspend.cpp
new file mode 100644
index 000000000..ef147551a
--- /dev/null
+++ b/src/core/ns_suspend.cpp
@@ -0,0 +1,201 @@
+/* NickServ core functions
+ *
+ * (C) 2003-2010 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 CommandNSSuspend : public Command
+{
+ public:
+ CommandNSSuspend() : Command("SUSPEND", 2, 2, "nickserv/suspend")
+ {
+ }
+
+ CommandReturn Execute(User *u, const std::vector<ci::string> &params)
+ {
+ NickAlias *na;
+ User *u2;
+ const char *nick = params[0].c_str();
+ const char *reason = params[1].c_str();
+
+ if (readonly)
+ {
+ notice_lang(Config.s_NickServ, u, READ_ONLY_MODE);
+ return MOD_CONT;
+ }
+
+ if (!(na = findnick(nick)))
+ {
+ notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
+ return MOD_CONT;
+ }
+
+ if (na->HasFlag(NS_FORBIDDEN))
+ {
+ notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
+ return MOD_CONT;
+ }
+
+ if (Config.NSSecureAdmins && na->nc->IsServicesOper())
+ {
+ notice_lang(Config.s_NickServ, u, ACCESS_DENIED);
+ return MOD_CONT;
+ }
+
+ if (na)
+ {
+ na->nc->SetFlag(NI_SUSPENDED);
+ na->nc->SetFlag(NI_SECURE);
+ na->nc->UnsetFlag(NI_KILLPROTECT);
+ na->nc->UnsetFlag(NI_KILL_QUICK);
+ na->nc->UnsetFlag(NI_KILL_IMMED);
+
+ for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(); it != na->nc->aliases.end(); ++it)
+ {
+ NickAlias *na2 = *it;
+
+ if (na2->nc == na->nc)
+ {
+ if (na2->last_quit)
+ delete [] na2->last_quit;
+ na2->last_quit = sstrdup(reason);
+
+ if ((u2 = finduser(na2->nick)))
+ {
+ u2->Logout();
+ u2->Collide(na2);
+ }
+ }
+ }
+
+ if (Config.WallForbid)
+ ircdproto->SendGlobops(NickServ, "\2%s\2 used SUSPEND on \2%s\2", u->nick.c_str(), nick);
+
+ Alog() << Config.s_NickServ << ": " << u->nick << " set SUSPEND for nick " << nick;
+ notice_lang(Config.s_NickServ, u, NICK_SUSPEND_SUCCEEDED, nick);
+
+ FOREACH_MOD(I_OnNickSuspended, OnNickSuspend(na))
+ }
+ else
+ {
+ Alog() << Config.s_NickServ << ": Valid SUSPEND for " << nick << " by " << u->nick << " failed";
+ notice_lang(Config.s_NickServ, u, NICK_SUSPEND_FAILED, nick);
+ }
+ return MOD_CONT;
+ }
+
+ bool OnHelp(User *u, const ci::string &subcommand)
+ {
+ notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_SUSPEND);
+ return true;
+ }
+
+ void OnSyntaxError(User *u, const ci::string &subcommand)
+ {
+ syntax_error(Config.s_NickServ, u, "SUSPEND", NICK_SUSPEND_SYNTAX);
+ }
+
+ void OnServHelp(User *u)
+ {
+ notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_SUSPEND);
+ }
+};
+
+class CommandNSUnSuspend : public Command
+{
+ public:
+ CommandNSUnSuspend() : Command("UNSUSPEND", 1, 1, "nickserv/suspend")
+ {
+ }
+
+ CommandReturn Execute(User *u, const std::vector<ci::string> &params)
+ {
+ NickAlias *na;
+ const char *nick = params[0].c_str();
+
+ if (readonly)
+ {
+ notice_lang(Config.s_NickServ, u, READ_ONLY_MODE);
+ return MOD_CONT;
+ }
+
+ if (!(na = findnick(nick)))
+ {
+ notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
+ return MOD_CONT;
+ }
+
+ if (na->HasFlag(NS_FORBIDDEN))
+ {
+ notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
+ return MOD_CONT;
+ }
+
+ if (Config.NSSecureAdmins && na->nc->IsServicesOper())
+ {
+ notice_lang(Config.s_NickServ, u, ACCESS_DENIED);
+ return MOD_CONT;
+ }
+
+ if (na)
+ {
+ na->nc->UnsetFlag(NI_SUSPENDED);
+
+ if (Config.WallForbid)
+ ircdproto->SendGlobops(NickServ, "\2%s\2 used UNSUSPEND on \2%s\2", u->nick.c_str(), nick);
+
+ Alog() << Config.s_NickServ << ": " << u->nick << " set UNSUSPEND for nick " << nick;
+ notice_lang(Config.s_NickServ, u, NICK_UNSUSPEND_SUCCEEDED, nick);
+
+ FOREACH_MOD(I_OnNickUnsuspended, OnNickUnsuspended(na));
+ }
+ else
+ {
+ Alog() << Config.s_NickServ << ": Valid UNSUSPEND for " << nick << " by " << u->nick << " failed";
+ notice_lang(Config.s_NickServ, u, NICK_UNSUSPEND_FAILED, nick);
+ }
+ return MOD_CONT;
+ }
+
+ bool OnHelp(User *u, const ci::string &subcommand)
+ {
+ notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_UNSUSPEND);
+ return true;
+ }
+
+ void OnSyntaxError(User *u, const ci::string &subcommand)
+ {
+ syntax_error(Config.s_NickServ, u, "UNSUSPEND", NICK_UNSUSPEND_SYNTAX);
+ }
+
+ void OnServHelp(User *u)
+ {
+ notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_UNSUSPEND);
+ }
+};
+
+class NSSuspend : public Module
+{
+ public:
+ NSSuspend(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ {
+ this->SetAuthor("Anope");
+ this->SetVersion(VERSION_STRING);
+ this->SetType(CORE);
+
+ this->AddCommand(NickServ, new CommandNSSuspend());
+ this->AddCommand(NickServ, new CommandNSUnSuspend());
+ }
+};
+
+MODULE_INIT(NSSuspend)