diff options
| author | Adam <Adam@anope.org> | 2015-12-14 16:52:24 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-12-14 16:52:24 -0500 |
| commit | 6302f980fe6dad83aab7d2dc1046dadea5ffd939 (patch) | |
| tree | 4c27d33f55fc32ce34827977932dac4b3e5ceedd /modules/operserv/login.cpp | |
| parent | 64dac60071fab652745a6e7a06cf6b7bdbbd3625 (diff) | |
New source tree structure for modules. From commands/cs_access => chanserv/access etc.
Diffstat (limited to 'modules/operserv/login.cpp')
| -rw-r--r-- | modules/operserv/login.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/modules/operserv/login.cpp b/modules/operserv/login.cpp new file mode 100644 index 000000000..650c48e3d --- /dev/null +++ b/modules/operserv/login.cpp @@ -0,0 +1,148 @@ +/* OperServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ +#include "module.h" + +class CommandOSLogin : public Command +{ + public: + CommandOSLogin(Module *creator) : Command(creator, "operserv/login", 1, 1) + { + this->SetSyntax(_("\037password\037")); + this->RequireUser(true); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &password = params[0]; + + User *u = source.GetUser(); + Oper *o = source.nc->o; + if (o == NULL) + { + source.Reply(_("No oper block for your nickname.")); + return; + } + + if (o->GetPassword().empty()) + { + source.Reply(_("Your oper block doesn't require logging in.")); + return; + } + + if (u->HasExtOK("os_login")) + { + source.Reply(_("You are already logged in.")); + return; + } + + if (o->GetPassword() != password) + { + source.Reply(_("Password incorrect.")); + u->BadPassword(); + return; + } + + Log(LOG_ADMIN, source, this) << "and successfully identified to " << source.service->nick; + u->Extend<bool>("os_login", true); + source.Reply(_("Password accepted.")); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Logs you in to {0} so you gain Services Operator privileges. This command is unnecessary if your oper block is configured without a password."), source.service->nick); + return true; + } + + const Anope::string GetDesc(CommandSource &source) const override + { + return Anope::printf(Language::Translate(source.GetAccount(), _("Login to %s")), source.service->nick.c_str()); + } +}; + +class CommandOSLogout : public Command +{ + public: + CommandOSLogout(Module *creator) : Command(creator, "operserv/logout", 0, 0) + { + this->RequireUser(true); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + User *u = source.GetUser(); + Oper *o = source.nc->o; + if (o == NULL) + { + source.Reply(_("No oper block for your nick.")); + return; + } + + if (o->GetPassword().empty()) + { + source.Reply(_("Your oper block doesn't require logging in.")); + return; + } + + if (!u->HasExtOK("os_login")) + { + source.Reply(_("You are not identified.")); + return; + } + + Log(LOG_ADMIN, source, this); + u->ShrinkOK<bool>("os_login"); + source.Reply(_("You have been logged out.")); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Logs you out from %s so you lose Services Operator privileges. This command is only useful if your oper block is configured with a password."), source.service->nick); + return true; + } + + const Anope::string GetDesc(CommandSource &source) const override + { + return Anope::printf(Language::Translate(source.GetAccount(), _("Logout from %s")), source.service->nick.c_str()); + } +}; + +class OSLogin : public Module + , public EventHook<Event::IsServicesOperEvent> +{ + CommandOSLogin commandoslogin; + CommandOSLogout commandoslogout; + ExtensibleItem<bool> os_login; + + public: + OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandoslogin(this) + , commandoslogout(this) + , os_login(this, "os_login") + { + + } + + EventReturn IsServicesOper(User *u) override + { + if (!u->Account()->o->GetPassword().empty()) + { + if (os_login.HasExt(u)) + return EVENT_ALLOW; + return EVENT_STOP; + } + + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(OSLogin) |
