Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015
00016 class NSIdentifyRequest : public IdentifyRequest
00017 {
00018 CommandSource source;
00019 Command *cmd;
00020
00021 public:
00022 NSIdentifyRequest(Module *o, CommandSource &s, Command *c, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(o, acc, pass), source(s), cmd(c) { }
00023
00024 void OnSuccess() anope_override
00025 {
00026 if (!source.GetUser())
00027 return;
00028
00029 User *u = source.GetUser();
00030 NickAlias *na = NickAlias::Find(GetAccount());
00031
00032 if (!na)
00033 source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str());
00034 else
00035 {
00036 if (u->IsIdentified())
00037 Log(LOG_COMMAND, source, cmd) << "to log out of account " << u->Account()->display;
00038
00039 Log(LOG_COMMAND, source, cmd) << "and identified for account " << na->nc->display;
00040 source.Reply(_("Password accepted - you are now recognized."));
00041 u->Identify(na);
00042 na->Release();
00043 }
00044 }
00045
00046 void OnFail() anope_override
00047 {
00048 if (source.GetUser())
00049 {
00050 Log(LOG_COMMAND, source, cmd) << "and failed to identify";
00051 if (NickAlias::Find(GetAccount()) != NULL)
00052 {
00053 source.Reply(PASSWORD_INCORRECT);
00054 source.GetUser()->BadPassword();
00055 }
00056 else
00057 source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str());
00058 }
00059 }
00060 };
00061
00062 class CommandNSIdentify : public Command
00063 {
00064 public:
00065 CommandNSIdentify(Module *creator) : Command(creator, "nickserv/identify", 1, 2)
00066 {
00067 this->SetDesc(_("Identify yourself with your password"));
00068 this->SetSyntax(_("[\037account\037] \037password\037"));
00069 this->AllowUnregistered(true);
00070 this->RequireUser(true);
00071 }
00072
00073 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00074 {
00075 User *u = source.GetUser();
00076
00077 const Anope::string &nick = params.size() == 2 ? params[0] : u->nick;
00078 Anope::string pass = params[params.size() - 1];
00079
00080 NickAlias *na = NickAlias::Find(nick);
00081 if (na && na->nc->HasExt("SUSPENDED"))
00082 source.Reply(NICK_X_SUSPENDED, na->nick.c_str());
00083 else if (u->Account() && na && u->Account() == na->nc)
00084 source.Reply(_("You are already identified."));
00085 else
00086 {
00087 NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass);
00088 FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(u, req));
00089 req->Dispatch();
00090 }
00091 return;
00092 }
00093
00094 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00095 {
00096 this->SendSyntax(source);
00097 source.Reply(" ");
00098 source.Reply(_("Tells %s that you are really the owner of this\n"
00099 "nick. Many commands require you to authenticate yourself\n"
00100 "with this command before you use them. The password\n"
00101 "should be the same one you sent with the \002REGISTER\002\n"
00102 "command."), source.service->nick.c_str());
00103 return true;
00104 }
00105 };
00106
00107 class NSIdentify : public Module
00108 {
00109 CommandNSIdentify commandnsidentify;
00110
00111 public:
00112 NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00113 commandnsidentify(this)
00114 {
00115 this->SetAuthor("Anope");
00116
00117 }
00118 };
00119
00120 MODULE_INIT(NSIdentify)