Allow contrib modules to specify their own module version.

This commit is contained in:
Sadie Powell 2024-07-22 16:23:41 +01:00
parent 31c8a3b01a
commit 4e947b8733
4 changed files with 31 additions and 7 deletions

View File

@ -218,6 +218,13 @@ protected:
*/
Module(int mprops, const std::string& mdesc);
/** Initializes a new instance of the Module class.
* @param mprops The properties of this module.
* @param mversion The version of this module (for contrib modules).
* @param mdesc A description of this module.
*/
Module(int mprops, const std::string& mversion, const std::string& mdesc);
/** Detach an event from this module
* @param i Event type to detach
*/
@ -250,6 +257,9 @@ public:
/** The properties of this module. */
const int properties;
/** The version of this module. */
const std::string version;
/** Module setup
* \exception ModuleException Throwing this class, or any class derived from ModuleException, causes loading of the module to abort.
*/
@ -275,6 +285,9 @@ public:
/** Retrieves a string that represents the properties of this module. */
std::string GetPropertyString() const;
/** Retrieves the version of the module. */
std::string GetVersion() const;
/** This method is called when you should reload module specific configuration:
* on boot, on a /REHASH and on module load.
* @param status The current status, can be inspected for more information.

View File

@ -64,8 +64,8 @@ CmdResult CommandModules::Handle(User* user, const Params& parameters)
bool has_priv = IS_LOCAL(user) && user->HasPrivPermission("servers/auspex");
for (const auto& [modname, mod] : ServerInstance->Modules.GetModules())
{
const char* version = has_priv ? mod->ModuleDLL->GetVersion() : "*";
const std::string props = has_priv ? mod->GetPropertyString() : "*";
const auto version = has_priv ? mod->GetVersion() : "*";
const auto props = has_priv ? mod->GetPropertyString() : "*";
user->WriteRemoteNumeric(RPL_MODLIST, ModuleManager::ShrinkModName(modname), version, props, mod->description);
}
user->WriteRemoteNumeric(RPL_ENDOFMODLIST, "End of MODULES list");

View File

@ -82,12 +82,8 @@ bool ModuleManager::Load(const std::string& modname, bool defer)
newmod->ReadConfig(confstatus);
}
const char* version = newhandle->GetVersion();
if (!version)
version = "unknown";
ServerInstance->Logs.Normal("MODULE", "New module introduced: {} (version {}, properties {})",
filename, version, newmod->GetPropertyString());
filename, newmod->GetVersion(), newmod->GetPropertyString());
}
else
{

View File

@ -46,8 +46,14 @@ void dynamic_reference_base::reset_all()
}
Module::Module(int mprops, const std::string& mdesc)
: Module(mprops, "", mdesc)
{
}
Module::Module(int mprops, const std::string& mversion, const std::string& mdesc)
: description(mdesc)
, properties(mprops)
, version(mversion)
{
}
@ -83,6 +89,15 @@ std::string Module::GetPropertyString() const
return propstr;
}
std::string Module::GetVersion() const
{
if (!version.empty())
return version;
const auto* dll_version = ModuleDLL->GetVersion();
return dll_version ? dll_version : "unknown";
}
void Module::DetachEvent(Implementation i)
{
ServerInstance->Modules.Detach(i, this);