Anope IRC Services  Version 2.0
ns_status.cpp
Go to the documentation of this file.
1 /* NickServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  */
11 
12 #include "module.h"
13 
14 class CommandNSStatus : public Command
15 {
16  public:
17  CommandNSStatus(Module *creator) : Command(creator, "nickserv/status", 0, 16)
18  {
19  this->SetDesc(_("Returns the owner status of the given nickname"));
20  this->SetSyntax(_("[\037nickname\037]"));
21  this->AllowUnregistered(true);
22  }
23 
24  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
25  {
26  const Anope::string &nick = !params.empty() ? params[0] : source.GetNick();
27  const NickAlias *na = NickAlias::Find(nick);
28  spacesepstream sep(nick);
29  Anope::string nickbuf;
30 
31  while (sep.GetToken(nickbuf))
32  {
33  User *u2 = User::Find(nickbuf, true);
34  if (!u2) /* Nick is not online */
35  source.Reply("STATUS %s %d %s", nickbuf.c_str(), 0, "");
36  else if (u2->IsIdentified() && na && na->nc == u2->Account()) /* Nick is identified */
37  source.Reply("STATUS %s %d %s", nickbuf.c_str(), 3, u2->Account()->display.c_str());
38  else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */
39  source.Reply("STATUS %s %d %s", nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : "");
40  else if (!na) /* Nick is online, but NOT a registered */
41  source.Reply("STATUS %s %d %s", nickbuf.c_str(), 0, "");
42  else
43  /* Nick is not identified for the nick, but they could be logged into an account,
44  * so we tell the user about it
45  */
46  source.Reply("STATUS %s %d %s", nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : "");
47  }
48  return;
49  }
50 
51  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
52  {
53  this->SendSyntax(source);
54  source.Reply(" ");
55  source.Reply(_("Returns whether the user using the given nickname is\n"
56  "recognized as the owner of the nickname. The response has\n"
57  "this format:\n"
58  " \n"
59  " \037nickname\037 \037status-code\037 \037account\037\n"
60  " \n"
61  "where \037nickname\037 is the nickname sent with the command,\n"
62  "\037status-code\037 is one of the following, and \037account\037\n"
63  "is the account they are logged in as.\n"
64  " \n"
65  " 0 - no such user online \002or\002 nickname not registered\n"
66  " 1 - user not recognized as nickname's owner\n"
67  " 2 - user recognized as owner via access list only\n"
68  " 3 - user recognized as owner via password identification\n"
69  " \n"
70  "If no nickname is given, your status will be returned."));
71  return true;
72  }
73 };
74 
75 class NSStatus : public Module
76 {
78 
79  public:
80  NSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
81  commandnsstatus(this)
82  {
83 
84  }
85 };
86 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
bool IsRecognized(bool check_secure=true) const
Definition: users.cpp:438
Definition: users.h:34
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ns_status.cpp:51
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ns_status.cpp:24
CommandNSStatus(Module *creator)
Definition: ns_status.cpp:17
bool IsIdentified(bool check_nick=false) const
Definition: users.cpp:427
Anope::string display
Definition: account.h:113
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
CommandNSStatus commandnsstatus
Definition: ns_status.cpp:77
#define MODULE_INIT(x)
Definition: modules.h:45
bool AllowUnregistered() const
Definition: command.cpp:159
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
NickCore * Account() const
Definition: users.cpp:422
NSStatus(const Anope::string &modname, const Anope::string &creator)
Definition: ns_status.cpp:80
bool GetToken(Anope::string &token)
Definition: hashcomp.cpp:99
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
#define _(x)
Definition: services.h:50