anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
ns_identify.cpp (3601B)
1 /* NickServ core functions 2 * 3 * (C) 2003-2022 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 NSIdentifyRequest : public IdentifyRequest 15 { 16 CommandSource source; 17 Command *cmd; 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 22 void OnSuccess() anope_override 23 { 24 if (!source.GetUser()) 25 return; 26 27 User *u = source.GetUser(); 28 NickAlias *na = NickAlias::Find(GetAccount()); 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 43 void OnFail() anope_override 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> ¶ms) 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 { 81 source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); 82 return; 83 } 84 85 if (u->Account() && na && u->Account() == na->nc) 86 { 87 source.Reply(_("You are already identified.")); 88 return; 89 } 90 91 unsigned int maxlogins = Config->GetModule(this->owner)->Get<unsigned int>("maxlogins"); 92 if (na && maxlogins && na->nc->users.size() >= maxlogins) 93 { 94 source.Reply(_("Account \002%s\002 has already reached the maximum number of simultaneous logins (%u)."), na->nc->display.c_str(), maxlogins); 95 return; 96 } 97 98 NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass); 99 FOREACH_MOD(OnCheckAuthentication, (u, req)); 100 req->Dispatch(); 101 } 102 103 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override 104 { 105 this->SendSyntax(source); 106 source.Reply(" "); 107 source.Reply(_("Tells %s that you are really the owner of this\n" 108 "nick. Many commands require you to authenticate yourself\n" 109 "with this command before you use them. The password\n" 110 "should be the same one you sent with the \002REGISTER\002\n" 111 "command."), source.service->nick.c_str()); 112 return true; 113 } 114 }; 115 116 class NSIdentify : public Module 117 { 118 CommandNSIdentify commandnsidentify; 119 120 public: 121 NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), 122 commandnsidentify(this) 123 { 124 125 } 126 }; 127 128 MODULE_INIT(NSIdentify)