00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015
00016 class CommandOSModInfo : public Command
00017 {
00018 public:
00019 CommandOSModInfo(Module *creator) : Command(creator, "operserv/modinfo", 1, 1)
00020 {
00021 this->SetDesc(_("Info about a loaded module"));
00022 this->SetSyntax(_("\037modname\037"));
00023 }
00024
00025 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00026 {
00027 const Anope::string &file = params[0];
00028
00029 Module *m = ModuleManager::FindModule(file);
00030 if (m)
00031 {
00032 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() : "?", Anope::strftime(m->created).c_str());
00033
00034 std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command");
00035 for (unsigned i = 0; i < servicekeys.size(); ++i)
00036 {
00037 ServiceReference<Command> c("Command", servicekeys[i]);
00038 if (!c || c->owner != m)
00039 continue;
00040
00041 source.Reply(_(" Providing service: \002%s\002"), c->name.c_str());
00042
00043 for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
00044 {
00045 const BotInfo *bi = it->second;
00046
00047 for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit)
00048 {
00049 const Anope::string &c_name = cit->first;
00050 const CommandInfo &info = cit->second;
00051 if (info.name != c->name)
00052 continue;
00053 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());
00054 }
00055 }
00056 }
00057 }
00058 else
00059 source.Reply(_("No information about module \002%s\002 is available."), file.c_str());
00060
00061 return;
00062 }
00063
00064 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00065 {
00066 this->SendSyntax(source);
00067 source.Reply(" ");
00068 source.Reply(_("This command lists information about the specified loaded module."));
00069 return true;
00070 }
00071 };
00072
00073 class CommandOSModList : public Command
00074 {
00075 public:
00076 CommandOSModList(Module *creator) : Command(creator, "operserv/modlist", 0, 1)
00077 {
00078 this->SetDesc(_("List loaded modules"));
00079 this->SetSyntax(_("[Core|3rd|protocol|encryption|supported]"));
00080 }
00081
00082 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00083 {
00084 const Anope::string ¶m = !params.empty() ? params[0] : "";
00085
00086 int count = 0;
00087 int showCore = 0;
00088 int showThird = 1;
00089 int showProto = 1;
00090 int showEnc = 1;
00091 int showSupported = 1;
00092 int showDB = 1;
00093
00094 char core[] = "Core";
00095 char third[] = "3rd";
00096 char proto[] = "Protocol";
00097 char enc[] = "Encryption";
00098 char supported[] = "Supported";
00099 char db[] = "Database";
00100
00101 if (!param.empty())
00102 {
00103 if (param.equals_ci(core))
00104 {
00105 showCore = 1;
00106 showThird = 0;
00107 showProto = 0;
00108 showEnc = 0;
00109 showSupported = 0;
00110 showDB = 0;
00111 }
00112 else if (param.equals_ci(third))
00113 {
00114 showCore = 0;
00115 showThird = 1;
00116 showSupported = 0;
00117 showProto = 0;
00118 showEnc = 0;
00119 showDB = 0;
00120 }
00121 else if (param.equals_ci(proto))
00122 {
00123 showCore = 0;
00124 showThird = 0;
00125 showProto = 1;
00126 showEnc = 0;
00127 showSupported = 0;
00128 showDB = 0;
00129 }
00130 else if (param.equals_ci(supported))
00131 {
00132 showCore = 0;
00133 showThird = 0;
00134 showProto = 0;
00135 showSupported = 1;
00136 showEnc = 0;
00137 showDB = 0;
00138 }
00139 else if (param.equals_ci(enc))
00140 {
00141 showCore = 0;
00142 showThird = 0;
00143 showProto = 0;
00144 showSupported = 0;
00145 showEnc = 1;
00146 showDB = 0;
00147 }
00148 else if (param.equals_ci(db))
00149 {
00150 showCore = 0;
00151 showThird = 0;
00152 showProto = 0;
00153 showSupported = 0;
00154 showEnc = 0;
00155 showDB = 1;
00156 }
00157 }
00158
00159 Module *protocol = ModuleManager::FindFirstOf(PROTOCOL);
00160
00161 source.Reply(_("Current module list:"));
00162
00163 for (std::list<Module *>::iterator it = ModuleManager::Modules.begin(), it_end = ModuleManager::Modules.end(); it != it_end; ++it)
00164 {
00165 Module *m = *it;
00166
00167 switch (m->type)
00168 {
00169 case CORE:
00170 if (showCore)
00171 {
00172 source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), core);
00173 ++count;
00174 }
00175 break;
00176 case THIRD:
00177 if (showThird)
00178 {
00179 source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), third);
00180 ++count;
00181 }
00182 break;
00183 case PROTOCOL:
00184 if (m != protocol)
00185 break;
00186 if (showProto)
00187 {
00188 source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), proto);
00189 ++count;
00190 }
00191 break;
00192 case SUPPORTED:
00193 if (showSupported)
00194 {
00195 source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), supported);
00196 ++count;
00197 }
00198 break;
00199 case ENCRYPTION:
00200 if (showEnc)
00201 {
00202 source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), enc);
00203 ++count;
00204 }
00205 break;
00206 case DATABASE:
00207 if (showDB)
00208 {
00209 source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), db);
00210 ++count;
00211 }
00212 break;
00213 default:
00214 break;
00215 }
00216 }
00217 if (!count)
00218 source.Reply(_("No modules currently loaded."));
00219 else
00220 source.Reply(_("%d modules loaded."), count);
00221
00222 return;
00223 }
00224
00225 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00226 {
00227 this->SendSyntax(source);
00228 source.Reply(" ");
00229 source.Reply(_("Lists all currently loaded modules."));
00230 return true;
00231 }
00232 };
00233
00234 class OSModInfo : public Module
00235 {
00236 CommandOSModInfo commandosmodinfo;
00237 CommandOSModList commandosmodlist;
00238
00239 public:
00240 OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00241 commandosmodinfo(this), commandosmodlist(this)
00242 {
00243 this->SetAuthor("Anope");
00244
00245 }
00246 };
00247
00248 MODULE_INIT(OSModInfo)