anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
hs_group.cpp (2779B)
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 CommandHSGroup : public Command 15 { 16 bool setting; 17 18 public: 19 void Sync(const NickAlias *na) 20 { 21 if (setting) 22 return; 23 24 if (!na || !na->HasVhost()) 25 return; 26 27 setting = true; 28 for (unsigned i = 0; i < na->nc->aliases->size(); ++i) 29 { 30 NickAlias *nick = na->nc->aliases->at(i); 31 if (nick) 32 { 33 nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); 34 FOREACH_MOD(OnSetVhost, (nick)); 35 } 36 } 37 setting = false; 38 } 39 40 CommandHSGroup(Module *creator) : Command(creator, "hostserv/group", 0, 0), setting(false) 41 { 42 this->SetDesc(_("Syncs the vhost for all nicks in a group")); 43 } 44 45 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override 46 { 47 if (Anope::ReadOnly) 48 { 49 source.Reply(READ_ONLY_MODE); 50 return; 51 } 52 53 NickAlias *na = NickAlias::Find(source.GetNick()); 54 if (na && source.GetAccount() == na->nc && na->HasVhost()) 55 { 56 this->Sync(na); 57 if (!na->GetVhostIdent().empty()) 58 source.Reply(_("All vhosts in the group \002%s\002 have been set to \002%s\002@\002%s\002."), source.nc->display.c_str(), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); 59 else 60 source.Reply(_("All vhosts in the group \002%s\002 have been set to \002%s\002."), source.nc->display.c_str(), na->GetVhostHost().c_str()); 61 } 62 else 63 source.Reply(HOST_NOT_ASSIGNED); 64 65 return; 66 } 67 68 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override 69 { 70 this->SendSyntax(source); 71 source.Reply(" "); 72 source.Reply(_("This command allows users to set the vhost of their\n" 73 "CURRENT nick to be the vhost for all nicks in the same\n" 74 "group.")); 75 return true; 76 } 77 }; 78 79 class HSGroup : public Module 80 { 81 CommandHSGroup commandhsgroup; 82 bool syncongroup; 83 bool synconset; 84 85 public: 86 HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), 87 commandhsgroup(this) 88 { 89 if (!IRCD || !IRCD->CanSetVHost) 90 throw ModuleException("Your IRCd does not support vhosts"); 91 } 92 93 void OnSetVhost(NickAlias *na) anope_override 94 { 95 if (!synconset) 96 return; 97 98 commandhsgroup.Sync(na); 99 } 100 101 void OnNickGroup(User *u, NickAlias *na) anope_override 102 { 103 if (!syncongroup) 104 return; 105 106 commandhsgroup.Sync(na); 107 } 108 109 void OnReload(Configuration::Conf *conf) anope_override 110 { 111 Configuration::Block *block = conf->GetModule(this); 112 syncongroup = block->Get<bool>("syncongroup"); 113 synconset = block->Get<bool>("synconset"); 114 } 115 }; 116 117 MODULE_INIT(HSGroup)