Anope IRC Services  Version 2.0
ns_identify.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 
15 {
18 
19  public:
20  NSIdentifyRequest(Module *o, CommandSource &s, Command *c, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(o, acc, pass), source(s), cmd(c) { }
21 
23  {
24  if (!source.GetUser())
25  return;
26 
27  User *u = source.GetUser();
29 
30  if (!na)
31  source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str());
32  else
33  {
34  if (u->IsIdentified())
35  Log(LOG_COMMAND, source, cmd) << "to log out of account " << u->Account()->display;
36 
37  Log(LOG_COMMAND, source, cmd) << "and identified for account " << na->nc->display;
38  source.Reply(_("Password accepted - you are now recognized."));
39  u->Identify(na);
40  }
41  }
42 
44  {
45  if (source.GetUser())
46  {
47  bool accountexists = NickAlias::Find(GetAccount()) != NULL;
48  Log(LOG_COMMAND, source, cmd) << "and failed to identify to" << (accountexists ? " " : " nonexistent ") << "account " << GetAccount();
49  if (accountexists)
50  {
51  source.Reply(PASSWORD_INCORRECT);
52  source.GetUser()->BadPassword();
53  }
54  else
55  source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str());
56  }
57  }
58 };
59 
60 class CommandNSIdentify : public Command
61 {
62  public:
63  CommandNSIdentify(Module *creator) : Command(creator, "nickserv/identify", 1, 2)
64  {
65  this->SetDesc(_("Identify yourself with your password"));
66  this->SetSyntax(_("[\037account\037] \037password\037"));
67  this->AllowUnregistered(true);
68  this->RequireUser(true);
69  }
70 
71  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
72  {
73  User *u = source.GetUser();
74 
75  const Anope::string &nick = params.size() == 2 ? params[0] : u->nick;
76  Anope::string pass = params[params.size() - 1];
77 
78  NickAlias *na = NickAlias::Find(nick);
79  if (na && na->nc->HasExt("NS_SUSPENDED"))
80  source.Reply(NICK_X_SUSPENDED, na->nick.c_str());
81  else if (u->Account() && na && u->Account() == na->nc)
82  source.Reply(_("You are already identified."));
83  else
84  {
85  NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass);
86  FOREACH_MOD(OnCheckAuthentication, (u, req));
87  req->Dispatch();
88  }
89  return;
90  }
91 
92  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
93  {
94  this->SendSyntax(source);
95  source.Reply(" ");
96  source.Reply(_("Tells %s that you are really the owner of this\n"
97  "nick. Many commands require you to authenticate yourself\n"
98  "with this command before you use them. The password\n"
99  "should be the same one you sent with the \002REGISTER\002\n"
100  "command."), source.service->nick.c_str());
101  return true;
102  }
103 };
104 
105 class NSIdentify : public Module
106 {
108 
109  public:
110  NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
111  commandnsidentify(this)
112  {
113 
114  }
115 };
116 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
CommandNSIdentify commandnsidentify
bool BadPassword()
Definition: users.cpp:797
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ns_identify.cpp:71
Anope::string nick
Definition: account.h:37
void Dispatch()
Definition: account.cpp:57
Definition: users.h:34
#define NICK_X_NOT_REGISTERED
Definition: language.h:79
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
void Identify(NickAlias *na)
Definition: users.cpp:355
NSIdentifyRequest(Module *o, CommandSource &s, Command *c, const Anope::string &acc, const Anope::string &pass)
Definition: ns_identify.cpp:20
#define PASSWORD_INCORRECT
Definition: language.h:72
NSIdentify(const Anope::string &modname, const Anope::string &creator)
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ns_identify.cpp:92
void OnSuccess() anope_override
Definition: ns_identify.cpp:22
void Reply(const char *message,...)
Definition: command.cpp:96
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
#define MODULE_INIT(x)
Definition: modules.h:45
bool AllowUnregistered() const
Definition: command.cpp:159
User * GetUser()
Definition: command.cpp:31
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
bool RequireUser() const
Definition: command.cpp:169
Anope::string nick
Definition: users.h:62
CommandNSIdentify(Module *creator)
Definition: ns_identify.cpp:63
NickCore * Account() const
Definition: users.cpp:422
void SendSyntax(CommandSource &)
Definition: command.cpp:145
void OnFail() anope_override
Definition: ns_identify.cpp:43
CommandSource source
Definition: ns_identify.cpp:16
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
#define _(x)
Definition: services.h:50
const Anope::string & GetAccount() const
Definition: account.h:250
#define NICK_X_SUSPENDED
Definition: language.h:82
Module * owner
Definition: service.h:84