anope

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

hostserv.cpp (3518B)

      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 HostServCore : public Module
     15 {
     16 	Reference<BotInfo> HostServ;
     17  public:
     18 	HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
     19 	{
     20 		if (!IRCD || !IRCD->CanSetVHost)
     21 			throw ModuleException("Your IRCd does not support vhosts");
     22 	}
     23 
     24 	void OnReload(Configuration::Conf *conf) anope_override
     25 	{
     26 		const Anope::string &hsnick = conf->GetModule(this)->Get<const Anope::string>("client");
     27 
     28 		if (hsnick.empty())
     29 			throw ConfigException(Module::name + ": <client> must be defined");
     30 
     31 		BotInfo *bi = BotInfo::Find(hsnick, true);
     32 		if (!bi)
     33 			throw ConfigException(Module::name + ": no bot named " + hsnick);
     34 
     35 		HostServ = bi;
     36 	}
     37 
     38 	void OnUserLogin(User *u) anope_override
     39 	{
     40 		if (!IRCD->CanSetVHost)
     41 			return;
     42 
     43 		const NickAlias *na = NickAlias::Find(u->nick);
     44 		if (!na || na->nc != u->Account() || !na->HasVhost())
     45 			na = NickAlias::Find(u->Account()->display);
     46 		if (!na || !na->HasVhost())
     47 			return;
     48 
     49 		if (u->vhost.empty() || !u->vhost.equals_cs(na->GetVhostHost()) || (!na->GetVhostIdent().empty() && !u->GetVIdent().equals_cs(na->GetVhostIdent())))
     50 		{
     51 			IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
     52 
     53 			u->vhost = na->GetVhostHost();
     54 			u->UpdateHost();
     55 
     56 			if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
     57 				u->SetVIdent(na->GetVhostIdent());
     58 
     59 			if (HostServ)
     60 			{
     61 				if (!na->GetVhostIdent().empty())
     62 					u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
     63 				else
     64 					u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
     65 			}
     66 		}
     67 	}
     68 
     69 	void OnNickDrop(CommandSource &source, NickAlias *na) anope_override
     70 	{
     71 		if (na->HasVhost())
     72 		{
     73 			FOREACH_MOD(OnDeleteVhost, (na));
     74 			na->RemoveVhost();
     75 		}
     76 	}
     77 
     78 	void OnNickUpdate(User *u) anope_override
     79 	{
     80 		this->OnUserLogin(u);
     81 	}
     82 
     83 	EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     84 	{
     85 		if (!params.empty() || source.c || source.service != *HostServ)
     86 			return EVENT_CONTINUE;
     87 		source.Reply(_("%s commands:"), HostServ->nick.c_str());
     88 		return EVENT_CONTINUE;
     89 	}
     90 
     91 	void OnSetVhost(NickAlias *na) anope_override
     92 	{
     93 		if (Config->GetModule(this)->Get<bool>("activate_on_set"))
     94 		{
     95 			User *u = User::Find(na->nick);
     96 
     97 			if (u && u->Account() == na->nc)
     98 			{
     99 				IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
    100 
    101 				u->vhost = na->GetVhostHost();
    102 				u->UpdateHost();
    103 
    104 				if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
    105 					u->SetVIdent(na->GetVhostIdent());
    106 
    107 				if (HostServ)
    108 				{
    109 					if (!na->GetVhostIdent().empty())
    110 						u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
    111 					else
    112 						u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
    113 				}
    114 			}
    115 		}
    116 	}
    117 
    118 	void OnDeleteVhost(NickAlias *na) anope_override
    119 	{
    120 		if (Config->GetModule(this)->Get<bool>("activate_on_set"))
    121 		{
    122 			User *u = User::Find(na->nick);
    123 
    124 			if (u && u->Account() == na->nc)
    125 				IRCD->SendVhostDel(u);
    126 		}
    127 	}
    128 };
    129 
    130 MODULE_INIT(HostServCore)