Anope IRC Services  Version 2.0
os_login.cpp
Go to the documentation of this file.
1 /* OperServ 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  */
13 #include "module.h"
14 
15 class CommandOSLogin : public Command
16 {
17  public:
18  CommandOSLogin(Module *creator) : Command(creator, "operserv/login", 1, 1)
19  {
20  this->SetSyntax(_("\037password\037"));
21  this->RequireUser(true);
22  }
23 
24  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
25  {
26  const Anope::string &password = params[0];
27 
28  User *u = source.GetUser();
29  Oper *o = source.nc->o;
30  if (o == NULL)
31  source.Reply(_("No oper block for your nick."));
32  else if (o->password.empty())
33  source.Reply(_("Your oper block doesn't require logging in."));
34  else if (u->HasExt("os_login"))
35  source.Reply(_("You are already identified."));
36  else if (o->password != password)
37  {
38  source.Reply(PASSWORD_INCORRECT);
39  u->BadPassword();
40  }
41  else
42  {
43  Log(LOG_ADMIN, source, this) << "and successfully identified to " << source.service->nick;
44  u->Extend<bool>("os_login");
45  source.Reply(_("Password accepted."));
46  }
47  }
48 
49  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
50  {
51  this->SendSyntax(source);
52  source.Reply(" ");
53  source.Reply(_("Logs you in to %s so you gain Services Operator privileges.\n"
54  "This command may be unnecessary if your oper block is\n"
55  "configured without a password."), source.service->nick.c_str());
56  return true;
57  }
58 
60  {
61  return Anope::printf(Language::Translate(source.GetAccount(), _("Login to %s")), source.service->nick.c_str());
62  }
63 };
64 
65 class CommandOSLogout : public Command
66 {
67  public:
68  CommandOSLogout(Module *creator) : Command(creator, "operserv/logout", 0, 0)
69  {
70  this->RequireUser(true);
71  }
72 
73  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
74  {
75  User *u = source.GetUser();
76  Oper *o = source.nc->o;
77  if (o == NULL)
78  source.Reply(_("No oper block for your nick."));
79  else if (o->password.empty())
80  source.Reply(_("Your oper block doesn't require logging in."));
81  else if (!u->HasExt("os_login"))
82  source.Reply(_("You are not identified."));
83  else
84  {
85  Log(LOG_ADMIN, source, this);
86  u->Shrink<bool>("os_login");
87  source.Reply(_("You have been logged out."));
88  }
89  }
90 
91  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
92  {
93  this->SendSyntax(source);
94  source.Reply(" ");
95  source.Reply(_("Logs you out from %s so you lose Services Operator privileges.\n"
96  "This command is only useful if your oper block is configured\n"
97  "with a password."), source.service->nick.c_str());
98  return true;
99  }
100 
102  {
103  return Anope::printf(Language::Translate(source.GetAccount(), _("Logout from %s")), source.service->nick.c_str());
104  }
105 };
106 
107 class OSLogin : public Module
108 {
112 
113  public:
114  OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
115  commandoslogin(this), commandoslogout(this), os_login(this, "os_login")
116  {
117 
118  }
119 
121  {
122  if (!u->Account()->o->password.empty())
123  {
124  if (os_login.HasExt(u))
125  return EVENT_ALLOW;
126  return EVENT_STOP;
127  }
128 
129  return EVENT_CONTINUE;
130  }
131 };
132 
bool BadPassword()
Definition: users.cpp:797
CommandOSLogin commandoslogin
Definition: os_login.cpp:109
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_login.cpp:24
Definition: opertype.h:18
const Anope::string GetDesc(CommandSource &source) const anope_override
Definition: os_login.cpp:101
CoreExport string printf(const char *fmt,...)
Definition: misc.cpp:536
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_login.cpp:91
Definition: users.h:34
T * Extend(const Anope::string &name, const T &what)
Definition: extensible.h:224
ExtensibleItem< bool > os_login
Definition: os_login.cpp:111
CommandOSLogin(Module *creator)
Definition: os_login.cpp:18
CommandOSLogout(Module *creator)
Definition: os_login.cpp:68
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_login.cpp:73
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_login.cpp:49
const Anope::string GetDesc(CommandSource &source) const anope_override
Definition: os_login.cpp:59
#define PASSWORD_INCORRECT
Definition: language.h:72
void Shrink(const Anope::string &name)
Definition: extensible.h:253
CommandOSLogout commandoslogout
Definition: os_login.cpp:110
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
OSLogin(const Anope::string &modname, const Anope::string &creator)
Definition: os_login.cpp:114
EventReturn IsServicesOper(User *u) anope_override
Definition: os_login.cpp:120
EventReturn
Definition: modules.h:129
#define MODULE_INIT(x)
Definition: modules.h:45
CoreExport const char * Translate(const char *string)
Definition: language.cpp:59
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
bool RequireUser() const
Definition: command.cpp:169
void SendSyntax(CommandSource &)
Definition: command.cpp:145
Definition: logger.h:53
bool HasExt(const Extensible *obj) const
Definition: extensible.h:111
#define _(x)
Definition: services.h:50
bool HasExt(const Anope::string &name) const
Definition: extensible.cpp:31
Anope::string password
Definition: opertype.h:26