anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

hs_on.cpp (2310B)

      1 /* HostServ 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 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 || na->nc != u->Account() || !na->HasVhost())
     31 			na = NickAlias::Find(u->Account()->display);
     32 		if (na && u->Account() == na->nc && na->HasVhost())
     33 		{
     34 			if (!na->GetVhostIdent().empty())
     35 				source.Reply(_("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
     36 			else
     37 				source.Reply(_("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
     38 			Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost();
     39 			IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
     40 			u->vhost = na->GetVhostHost();
     41 			if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
     42 				u->SetVIdent(na->GetVhostIdent());
     43 			u->UpdateHost();
     44 		}
     45 		else
     46 			source.Reply(HOST_NOT_ASSIGNED);
     47 
     48 		return;
     49 	}
     50 
     51 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     52 	{
     53 		this->SendSyntax(source);
     54 		source.Reply(" ");
     55 		source.Reply(_("Activates the vhost currently assigned to the nick in use.\n"
     56 				"When you use this command any user who performs a /whois\n"
     57 				"on you will see the vhost instead of your real host/IP address."));
     58 		return true;
     59 	}
     60 };
     61 
     62 class HSOn : public Module
     63 {
     64 	CommandHSOn commandhson;
     65 
     66  public:
     67 	HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
     68 		commandhson(this)
     69 	{
     70 		if (!IRCD || !IRCD->CanSetVHost)
     71 			throw ModuleException("Your IRCd does not support vhosts");
     72 	}
     73 };
     74 
     75 MODULE_INIT(HSOn)