Exemplo n.º 1
0
bool ModuleManager::Load(const std::string& name, bool defer)
{
    modmap::iterator it = modlist->find(name);
    if (it == modlist->end())
        return false;
    Module* mod = NULL;

    ServiceList newservices;
    if (!defer)
        this->NewServices = &newservices;

    try
    {
        mod = (*it->second->init)();
        mod->ModuleSourceFile = name;
        mod->ModuleDLLManager = NULL;
        mod->dying = false;
        Modules[name] = mod;
        this->NewServices = NULL;
        if (defer)
        {
            ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str());
            return true;
        }
        else
        {
            ConfigStatus confstatus;

            AttachAll(mod);
            AddServices(newservices);
            mod->init();
            mod->ReadConfig(confstatus);
        }
    }
    catch (CoreException& modexcept)
    {
        this->NewServices = NULL;

        if (mod)
            DoSafeUnload(mod);
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason());
        return false;
    }

    FOREACH_MOD(OnLoadModule, (mod));
    PrioritizeHooks();
    ServerInstance->ISupport.Build();
    return true;
}
Exemplo n.º 2
0
void ModuleManager::LoadAll()
{
	std::map<std::string, ServiceList> servicemap;
	LoadCoreModules(servicemap);

	ConfigTagList tags = ServerInstance->Config->ConfTags("module");
	for (ConfigIter i = tags.first; i != tags.second; ++i)
	{
		ConfigTag* tag = i->second;
		std::string name = tag->getString("name");
		this->NewServices = &servicemap[name];
		std::cout << "[" << con_green << "*" << con_reset << "] Loading module:\t" << con_green << name << con_reset << std::endl;

		if (!this->Load(name, true))
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
			std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}

	ConfigStatus confstatus;

	for (ModuleMap::const_iterator i = Modules.begin(); i != Modules.end(); ++i)
	{
		Module* mod = i->second;
		try
		{
			ServerInstance->Logs->Log("MODULE", LOG_DEBUG, "Initializing %s", i->first.c_str());
			AttachAll(mod);
			AddServices(servicemap[i->first]);
			mod->init();
			mod->ReadConfig(confstatus);
		}
		catch (CoreException& modexcept)
		{
			LastModuleError = "Unable to initialize " + mod->ModuleSourceFile + ": " + modexcept.GetReason();
			ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
			std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl;
			ServerInstance->Exit(EXIT_STATUS_MODULE);
		}
	}

	this->NewServices = NULL;

	if (!PrioritizeHooks())
		ServerInstance->Exit(EXIT_STATUS_MODULE);
}
Exemplo n.º 3
0
bool ModuleManager::Load(const std::string& modname, bool defer)
{
    /* Don't allow people to specify paths for modules, it doesn't work as expected */
    if (modname.find('/') != std::string::npos)
    {
        LastModuleError = "You can't load modules with a path: " + modname;
        return false;
    }

    const std::string filename = ExpandModName(modname);
    const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);

    if (!FileSystem::FileExists(moduleFile))
    {
        LastModuleError = "Module file could not be found: " + filename;
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
        return false;
    }

    if (Modules.find(filename) != Modules.end())
    {
        LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
        return false;
    }

    Module* newmod = NULL;
    DLLManager* newhandle = new DLLManager(moduleFile.c_str());
    ServiceList newservices;
    if (!defer)
        this->NewServices = &newservices;

    try
    {
        newmod = newhandle->CallInit();
        this->NewServices = NULL;

        if (newmod)
        {
            newmod->ModuleSourceFile = filename;
            newmod->ModuleDLLManager = newhandle;
            newmod->dying = false;
            Modules[filename] = newmod;
            std::string version = newhandle->GetVersion();
            if (defer)
            {
                ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
                                          filename.c_str(), version.c_str());
            }
            else
            {
                ConfigStatus confstatus;

                AttachAll(newmod);
                AddServices(newservices);
                newmod->init();
                newmod->ReadConfig(confstatus);

                Version v = newmod->GetVersion();
                ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
                                          filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
            }
        }
        else
        {
            LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
            ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
            delete newhandle;
            return false;
        }
    }
    catch (CoreException& modexcept)
    {
        this->NewServices = NULL;

        // failure in module constructor
        if (newmod)
        {
            DoSafeUnload(newmod);
            ServerInstance->GlobalCulls.AddItem(newhandle);
        }
        else
            delete newhandle;
        LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
        ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
        return false;
    }

    if (defer)
        return true;

    FOREACH_MOD(OnLoadModule, (newmod));
    PrioritizeHooks();
    ServerInstance->ISupport.Build();
    return true;
}