Anope IRC Services  Version 2.0
hs_on.cpp
Go to the documentation of this file.
1 /* HostServ 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 
14 class CommandHSOn : public Command
15 {
16  public:
17  CommandHSOn(Module *creator) : Command(creator, "hostserv/on", 0, 0)
18  {
19  this->SetDesc(_("Activates your assigned vhost"));
20  this->RequireUser(true);
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  if (!IRCD->CanSetVHost)
26  return; // HostServ wouldn't even be loaded at this point
27 
28  User *u = source.GetUser();
29  const NickAlias *na = NickAlias::Find(u->nick);
30  if (na && u->Account() == na->nc && na->HasVhost())
31  {
32  if (!na->GetVhostIdent().empty())
33  source.Reply(_("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
34  else
35  source.Reply(_("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
36  Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost();
37  IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
38  u->vhost = na->GetVhostHost();
39  if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
40  u->SetVIdent(na->GetVhostIdent());
41  u->UpdateHost();
42  }
43  else
44  source.Reply(HOST_NOT_ASSIGNED);
45 
46  return;
47  }
48 
49  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
50  {
51  this->SendSyntax(source);
52  source.Reply(" ");
53  source.Reply(_("Activates the vhost currently assigned to the nick in use.\n"
54  "When you use this command any user who performs a /whois\n"
55  "on you will see the vhost instead of your real host/IP address."));
56  return true;
57  }
58 };
59 
60 class HSOn : public Module
61 {
63 
64  public:
65  HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
66  commandhson(this)
67  {
68 
69  }
70 };
71 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
virtual void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost)
Definition: protocol.h:99
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: hs_on.cpp:49
CommandHSOn(Module *creator)
Definition: hs_on.cpp:17
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: hs_on.cpp:23
const Anope::string & GetVhostHost() const
Definition: nickalias.cpp:106
bool HasVhost() const
Definition: nickalias.cpp:96
Definition: users.h:34
bool CanSetVHost
Definition: protocol.h:53
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
CommandHSOn commandhson
Definition: hs_on.cpp:62
bool CanSetVIdent
Definition: protocol.h:53
#define HOST_NOT_ASSIGNED
Definition: language.h:127
void SetVIdent(const Anope::string &ident)
Definition: users.cpp:238
#define anope_override
Definition: services.h:56
void UpdateHost()
Definition: users.cpp:494
bool empty() const
Definition: anope.h:126
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
HSOn(const Anope::string &modname, const Anope::string &creator)
Definition: hs_on.cpp:65
bool RequireUser() const
Definition: command.cpp:169
Anope::string nick
Definition: users.h:62
NickCore * Account() const
Definition: users.cpp:422
Definition: hs_on.cpp:60
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
#define _(x)
Definition: services.h:50
Anope::string vhost
Definition: users.h:67
const Anope::string & GetVhostIdent() const
Definition: nickalias.cpp:101