ns_status.cpp

Go to the documentation of this file.
00001 /* NickServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  */
00011 
00012 /*************************************************************************/
00013 
00014 #include "module.h"
00015 
00016 class CommandNSStatus : public Command
00017 {
00018  public:
00019         CommandNSStatus(Module *creator) : Command(creator, "nickserv/status", 0, 16)
00020         {
00021                 this->SetDesc(_("Returns the owner status of the given nickname"));
00022                 this->SetSyntax(_("\037nickname\037"));
00023                 this->AllowUnregistered(true);
00024         }
00025 
00026         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00027         {
00028                 const Anope::string &nick = !params.empty() ? params[0] : source.GetNick();
00029                 const NickAlias *na = NickAlias::Find(nick);
00030                 spacesepstream sep(nick);
00031                 Anope::string nickbuf;
00032 
00033                 while (sep.GetToken(nickbuf))
00034                 {
00035                         User *u2 = User::Find(nickbuf, true);
00036                         if (!u2) /* Nick is not online */
00037                                 source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 0, "");
00038                         else if (u2->IsIdentified() && na && na->nc == u2->Account()) /* Nick is identified */
00039                                 source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 3, u2->Account()->display.c_str());
00040                         else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */
00041                                 source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : "");
00042                         else if (!na) /* Nick is online, but NOT a registered */
00043                                 source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 0, "");
00044                         else
00045                                 /* Nick is not identified for the nick, but they could be logged into an account,
00046                                  * so we tell the user about it
00047                                  */
00048                                 source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : "");
00049                 }
00050                 return;
00051         }
00052 
00053         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00054         {
00055                 this->SendSyntax(source);
00056                 source.Reply(" ");
00057                 source.Reply(_("Returns whether the user using the given nickname is\n"
00058                                 "recognized as the owner of the nickname. The response has\n"
00059                                 "this format:\n"
00060                                 " \n"
00061                                 "    \037nickname\037 \037status-code\037 \037account\037\n"
00062                                 " \n"
00063                                 "where \037nickname\037 is the nickname sent with the command,\n"
00064                                 "\037status-code\037 is one of the following, and \037account\037\n"
00065                                 "is the account they are logged in as.\n"
00066                                 " \n"
00067                                 "    0 - no such user online \002or\002 nickname not registered\n"
00068                                 "    1 - user not recognized as nickname's owner\n"
00069                                 "    2 - user recognized as owner via access list only\n"
00070                                 "    3 - user recognized as owner via password identification"));
00071                 return true;
00072         }
00073 };
00074 
00075 class NSStatus : public Module
00076 {
00077         CommandNSStatus commandnsstatus;
00078 
00079  public:
00080         NSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00081                 commandnsstatus(this)
00082         {
00083                 this->SetAuthor("Anope");
00084 
00085         }
00086 };
00087 
00088 MODULE_INIT(NSStatus)