]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Move some local-only fields to LocalUser
[user/henk/code/inspircd.git] / src / modules.cpp
index 8957b4bb622522b23ca725e9ed306ae5b8760065..a0eb9e19ea643bf797b333df9c31b5a5d4332476 100644 (file)
@@ -51,12 +51,16 @@ void Event::Send()
 
 // These declarations define the behavours of the base class Module (which does nothing at all)
 
-Module::Module() { }
+Module::Module() : refcount(1) { }
 CullResult Module::cull()
 {
        return classbase::cull();
 }
-Module::~Module() { }
+Module::~Module()
+{
+       if (refcount != 1)
+               ServerInstance->Logs->Log("MODULE", DEFAULT, "References remain to destructed module " + ModuleSourceFile);
+}
 
 ModResult      Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return MOD_RES_PASSTHRU; }
 void           Module::OnUserConnect(User*) { }
@@ -460,7 +464,7 @@ void ModuleManager::DoSafeUnload(Module* mod)
 {
        std::map<std::string, Module*>::iterator modfind = Modules.find(mod->ModuleSourceFile);
 
-       std::vector<ExtensionItem*> items;
+       std::vector<reference<ExtensionItem> > items;
        ServerInstance->Extensions.BeginUnregister(modfind->second, items);
        /* Give the module a chance to tidy out all its metadata */
        for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++)
@@ -476,6 +480,16 @@ void ModuleManager::DoSafeUnload(Module* mod)
                mod->OnCleanup(TYPE_USER,u->second);
                u->second->doUnhookExtensions(items);
        }
+       for(char m='A'; m <= 'z'; m++)
+       {
+               ModeHandler* mh;
+               mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER);
+               if (mh && mh->creator == mod)
+                       ServerInstance->Modes->DelMode(mh);
+               mh = ServerInstance->Modes->FindMode(m, MODETYPE_CHANNEL);
+               if (mh && mh->creator == mod)
+                       ServerInstance->Modes->DelMode(mh);
+       }
 
        /* Tidy up any dangling resolvers */
        ServerInstance->Res->CleanResolvers(mod);
@@ -607,8 +621,7 @@ void ModuleManager::UnloadAll()
                        std::map<std::string, Module*>::iterator me = i++;
                        if (CanUnload(me->second))
                        {
-                               ServerInstance->GlobalCulls.AddItem(me->second);
-                               Modules.erase(me);
+                               DoSafeUnload(me->second);
                        }
                }
                ServerInstance->GlobalCulls.Apply();
@@ -771,54 +784,6 @@ void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
        this->Modes->Process(parameters, user);
 }
 
-void InspIRCd::DumpText(User* user, const std::string &text)
-{
-       if (IS_LOCAL(user))
-       {
-               user->Write(text);
-       }
-       else
-       {
-               PI->PushToClient(user, text);
-       }
-}
-
-void InspIRCd::DumpText(User* user, const char *text, ...)
-{
-       va_list argsPtr;
-       char line[MAXBUF];
-
-       va_start(argsPtr, text);
-       vsnprintf(line, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-
-       DumpText(user, std::string(line));
-}
-
-void InspIRCd::DumpText(User* user, const std::string &LinePrefix, std::stringstream &TextStream)
-{
-       char line[MAXBUF];
-       int start_pos = LinePrefix.length();
-       int pos = start_pos;
-       memcpy(line, LinePrefix.data(), pos);
-       std::string Word;
-       while (TextStream >> Word)
-       {
-               int len = Word.length();
-               if (pos + len + 12 > MAXBUF)
-               {
-                       line[pos] = '\0';
-                       DumpText(user, std::string(line));
-                       pos = start_pos;
-               }
-               line[pos] = ' ';
-               memcpy(line + pos + 1, Word.data(), len);
-               pos += len + 1;
-       }
-       line[pos] = '\0';
-       DumpText(user, std::string(line));
-}
-
 bool InspIRCd::AddResolver(Resolver* r, bool cached)
 {
        if (!cached)