anope

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

module.cpp (2854B)

      1 /* Modular support
      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 
      9 #include "services.h"
     10 #include "modules.h"
     11 #include "language.h"
     12 #include "account.h"
     13 
     14 #ifdef GETTEXT_FOUND
     15 # include <libintl.h>
     16 #endif
     17 
     18 Module::Module(const Anope::string &modname, const Anope::string &, ModType modtype) : name(modname), type(modtype)
     19 {
     20 	this->handle = NULL;
     21 	this->permanent = false;
     22 	this->created = Anope::CurTime;
     23 	this->SetVersion(Anope::Version());
     24 
     25 	if (type & VENDOR)
     26 		this->SetAuthor("Anope");
     27 	else
     28 	{
     29 		/* Not vendor implies third */
     30 		type |= THIRD;
     31 		this->SetAuthor("Unknown");
     32 	}
     33 
     34 	if (ModuleManager::FindModule(this->name))
     35 		throw CoreException("Module already exists!");
     36 
     37 	if (Anope::NoThird && type & THIRD)
     38 		throw ModuleException("Third party modules may not be loaded");
     39 
     40 	ModuleManager::Modules.push_back(this);
     41 
     42 #if GETTEXT_FOUND
     43 	for (unsigned i = 0; i < Language::Languages.size(); ++i)
     44 	{
     45 		/* Remove .UTF-8 or any other suffix */
     46 		Anope::string lang;
     47 		sepstream(Language::Languages[i], '.').GetToken(lang);
     48 
     49 		if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo"))
     50 		{
     51 			if (!bindtextdomain(this->name.c_str(), Anope::LocaleDir.c_str()))
     52 				Log() << "Error calling bindtextdomain, " << Anope::LastError();
     53 			else
     54 			{
     55 				Log() << "Found language file " << lang << " for " << modname;
     56 				Language::Domains.push_back(modname);
     57 			}
     58 			break;
     59 		}
     60 	}
     61 #endif
     62 }
     63 
     64 Module::~Module()
     65 {
     66 	UnsetExtensibles();
     67 
     68 	/* Detach all event hooks for this module */
     69 	ModuleManager::DetachAll(this);
     70 	IdentifyRequest::ModuleUnload(this);
     71 	/* Clear any active timers this module has */
     72 	TimerManager::DeleteTimersFor(this);
     73 
     74 	std::list<Module *>::iterator it = std::find(ModuleManager::Modules.begin(), ModuleManager::Modules.end(), this);
     75 	if (it != ModuleManager::Modules.end())
     76 		ModuleManager::Modules.erase(it);
     77 
     78 #if GETTEXT_FOUND
     79 	std::vector<Anope::string>::iterator dit = std::find(Language::Domains.begin(), Language::Domains.end(), this->name);
     80 	if (dit != Language::Domains.end())
     81 		Language::Domains.erase(dit);
     82 #endif
     83 }
     84 
     85 void Module::SetPermanent(bool state)
     86 {
     87 	this->permanent = state;
     88 }
     89 
     90 bool Module::GetPermanent() const
     91 {
     92 	return this->permanent;
     93 }
     94 
     95 void Module::SetVersion(const Anope::string &nversion)
     96 {
     97 	this->version = nversion;
     98 }
     99 
    100 void Module::SetAuthor(const Anope::string &nauthor)
    101 {
    102 	this->author = nauthor;
    103 }
    104 
    105 void Module::Prioritize()
    106 {
    107 }
    108 
    109 ModuleVersion::ModuleVersion(const ModuleVersionC &ver)
    110 {
    111 	version_major = ver.version_major;
    112 	version_minor = ver.version_minor;
    113 	version_patch = ver.version_patch;
    114 }
    115 
    116 int ModuleVersion::GetMajor() const
    117 {
    118 	return this->version_major;
    119 }
    120 
    121 int ModuleVersion::GetMinor() const
    122 {
    123 	return this->version_minor;
    124 }
    125 
    126 int ModuleVersion::GetPatch() const
    127 {
    128 	return this->version_patch;
    129 }