diff options
| author | 2024-07-22 16:23:41 +0100 | |
|---|---|---|
| committer | 2024-07-22 16:49:41 +0100 | |
| commit | 4e947b8733980f9d40f781f883b85e6f65bd953f (patch) | |
| tree | 0c8aa2d2d5e28517c8bf8f907be1bc94b71e06e6 | |
| parent | Disable text websockets when the server has an incompatible charset. (diff) | |
Allow contrib modules to specify their own module version.
| -rw-r--r-- | include/modules.h | 13 | ||||
| -rw-r--r-- | src/coremods/core_info/cmd_modules.cpp | 4 | ||||
| -rw-r--r-- | src/modulemanager.cpp | 6 | ||||
| -rw-r--r-- | src/modules.cpp | 15 |
4 files changed, 31 insertions, 7 deletions
diff --git a/include/modules.h b/include/modules.h index 6aebdb9d0..3996ffb8d 100644 --- a/include/modules.h +++ b/include/modules.h @@ -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. diff --git a/src/coremods/core_info/cmd_modules.cpp b/src/coremods/core_info/cmd_modules.cpp index ee70e5996..d17315c5d 100644 --- a/src/coremods/core_info/cmd_modules.cpp +++ b/src/coremods/core_info/cmd_modules.cpp @@ -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"); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 8bd8c1f87..4caafe239 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -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 { diff --git a/src/modules.cpp b/src/modules.cpp index a69b65418..b7cd29c84 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -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); |
