anope

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

os_modinfo.cpp (5770B)

      1 /* OperServ 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 CommandOSModInfo : public Command
     15 {
     16  public:
     17 	CommandOSModInfo(Module *creator) : Command(creator, "operserv/modinfo", 1, 1)
     18 	{
     19 		this->SetDesc(_("Info about a loaded module"));
     20 		this->SetSyntax(_("\037modname\037"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &file = params[0];
     26 
     27 		Log(LOG_ADMIN, source, this) << "on " << file;
     28 
     29 		Module *m = ModuleManager::FindModule(file);
     30 		if (m)
     31 		{
     32 			source.Reply(_("Module: \002%s\002 Version: \002%s\002 Author: \002%s\002 Loaded: \002%s\002"), m->name.c_str(), !m->version.empty() ? m->version.c_str() : "?", !m->author.empty() ? m->author.c_str() : "Unknown", Anope::strftime(m->created, source.GetAccount()).c_str());
     33 			if (Anope::Debug)
     34 				source.Reply(_(" Loaded at: %p"), m->handle);
     35 
     36 			std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command");
     37 			for (unsigned i = 0; i < servicekeys.size(); ++i)
     38 			{
     39 				ServiceReference<Command> c("Command", servicekeys[i]);
     40 				if (!c || c->owner != m)
     41 					continue;
     42 
     43 				source.Reply(_("   Providing service: \002%s\002"), c->name.c_str());
     44 
     45 				for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
     46 				{
     47 					const BotInfo *bi = it->second;
     48 
     49 					for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit)
     50 					{
     51 						const Anope::string &c_name = cit->first;
     52 						const CommandInfo &info = cit->second;
     53 						if (info.name != c->name)
     54 							continue;
     55 						source.Reply(_("   Command \002%s\002 on \002%s\002 is linked to \002%s\002"), c_name.c_str(), bi->nick.c_str(), c->name.c_str());
     56 					}
     57 				}
     58 			}
     59 		}
     60 		else
     61 			source.Reply(_("No information about module \002%s\002 is available."), file.c_str());
     62 
     63 		return;
     64 	}
     65 
     66 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     67 	{
     68 		this->SendSyntax(source);
     69 		source.Reply(" ");
     70 		source.Reply(_("This command lists information about the specified loaded module."));
     71 		return true;
     72 	}
     73 };
     74 
     75 class CommandOSModList : public Command
     76 {
     77  public:
     78 	CommandOSModList(Module *creator) : Command(creator, "operserv/modlist", 0, 1)
     79 	{
     80 		this->SetDesc(_("List loaded modules"));
     81 		this->SetSyntax("[all|third|vendor|extra|database|encryption|pseudoclient|protocol]");
     82 	}
     83 
     84 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     85 	{
     86 		const Anope::string &param = !params.empty() ? params[0] : "";
     87 
     88 		if (!param.empty())
     89 			Log(LOG_ADMIN, source, this) << "for " << param;
     90 		else
     91 			Log(LOG_ADMIN, source, this);
     92 
     93 		bool third = false, vendor = false, extra = false, database = false, encryption = false, pseudoclient = false, protocol = false;
     94 
     95 		if (param.equals_ci("all"))
     96 			third = vendor = extra = database = encryption = pseudoclient = protocol = true;
     97 		else if (param.equals_ci("third"))
     98 			third = true;
     99 		else if (param.equals_ci("vendor"))
    100 			vendor = true;
    101 		else if (param.equals_ci("extra"))
    102 			extra = true;
    103 		else if (param.equals_ci("database"))
    104 			database = true;
    105 		else if (param.equals_ci("encryption"))
    106 			encryption = true;
    107 		else if (param.equals_ci("pseudoclient"))
    108 			pseudoclient = true;
    109 		else if (param.equals_ci("protocol"))
    110 			protocol = true;
    111 		else
    112 			third = extra = database = encryption = protocol = true;
    113 
    114 		Module *protomod = ModuleManager::FindFirstOf(PROTOCOL);
    115 
    116 		source.Reply(_("Current module list:"));
    117 
    118 		int count = 0;
    119 		for (std::list<Module *>::iterator it = ModuleManager::Modules.begin(), it_end = ModuleManager::Modules.end(); it != it_end; ++it)
    120 		{
    121 			Module *m = *it;
    122 
    123 			bool show = false;
    124 			Anope::string mtype;
    125 
    126 			if (m->type & PROTOCOL)
    127 			{
    128 				show |= protocol;
    129 				if (!mtype.empty())
    130 					mtype += ", ";
    131 				mtype += "Protocol";
    132 			}
    133 			if (m->type & PSEUDOCLIENT)
    134 			{
    135 				show |= pseudoclient;
    136 				if (!mtype.empty())
    137 					mtype += ", ";
    138 				mtype += "Pseudoclient";
    139 			}
    140 			if (m->type & ENCRYPTION)
    141 			{
    142 				show |= encryption;
    143 				if (!mtype.empty())
    144 					mtype += ", ";
    145 				mtype += "Encryption";
    146 			}
    147 			if (m->type & DATABASE)
    148 			{
    149 				show |= database;
    150 				if (!mtype.empty())
    151 					mtype += ", ";
    152 				mtype += "Database";
    153 			}
    154 			if (m->type & EXTRA)
    155 			{
    156 				show |= extra;
    157 				if (!mtype.empty())
    158 					mtype += ", ";
    159 				mtype += "Extra";
    160 			}
    161 			if (m->type & VENDOR)
    162 			{
    163 				show |= vendor;
    164 				if (!mtype.empty())
    165 					mtype += ", ";
    166 				mtype += "Vendor";
    167 			}
    168 			if (m->type & THIRD)
    169 			{
    170 				show |= third;
    171 				if (!mtype.empty())
    172 					mtype += ", ";
    173 				mtype += "Third";
    174 			}
    175 
    176 			if (!show)
    177 				continue;
    178 			else if (m->type & PROTOCOL && param.empty() && m != protomod)
    179 				continue;
    180 
    181 			++count;
    182 
    183 			source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), mtype.c_str());
    184 		}
    185 
    186 		if (!count)
    187 			source.Reply(_("No modules currently loaded matching that criteria."));
    188 		else
    189 			source.Reply(_("%d modules loaded."), count);
    190 	}
    191 
    192 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    193 	{
    194 		this->SendSyntax(source);
    195 		source.Reply(" ");
    196 		source.Reply(_("Lists currently loaded modules."));
    197 		return true;
    198 	}
    199 };
    200 
    201 class OSModInfo : public Module
    202 {
    203 	CommandOSModInfo commandosmodinfo;
    204 	CommandOSModList commandosmodlist;
    205 
    206  public:
    207 	OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    208 		commandosmodinfo(this), commandosmodlist(this)
    209 	{
    210 
    211 	}
    212 };
    213 
    214 MODULE_INIT(OSModInfo)