]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_callerid.cpp
m_callerid Ignore duplicate entries when unserializing callerid_data
[user/henk/code/inspircd.git] / src / modules / m_callerid.cpp
index f24c38b653acbfa074eee188a393497e84dd25e8..b0d6b9c64835829315a5bd764d83cb927c3f37eb 100644 (file)
@@ -38,26 +38,6 @@ class callerid_data
        std::list<callerid_data *> wholistsme;
 
        callerid_data() : lastnotify(0) { }
-       callerid_data(const std::string& str)
-       {
-               irc::commasepstream s(str);
-               std::string tok;
-               if (s.GetToken(tok))
-               {
-                       lastnotify = ConvToInt(tok);
-               }
-               while (s.GetToken(tok))
-               {
-                       if (tok.empty())
-                       {
-                               continue;
-                       }
-
-                       User *u = ServerInstance->FindNick(tok);
-                       if ((u) && (u->registered == REG_ALL) && (!u->quitting) && (!IS_SERVER(u)))
-                               accepting.insert(u);
-               }
-       }
 
        std::string ToString(SerializeFormat format) const
        {
@@ -88,8 +68,31 @@ struct CallerIDExtInfo : public ExtensionItem
 
        void unserialize(SerializeFormat format, Extensible* container, const std::string& value)
        {
-               callerid_data* dat = new callerid_data(value);
-               set_raw(container, dat);
+               callerid_data* dat = new callerid_data;
+               irc::commasepstream s(value);
+               std::string tok;
+               if (s.GetToken(tok))
+                       dat->lastnotify = ConvToInt(tok);
+
+               while (s.GetToken(tok))
+               {
+                       if (tok.empty())
+                               continue;
+
+                       User *u = ServerInstance->FindNick(tok);
+                       if ((u) && (u->registered == REG_ALL) && (!u->quitting) && (!IS_SERVER(u)))
+                       {
+                               if (dat->accepting.insert(u).second)
+                               {
+                                       callerid_data* other = this->get(u, true);
+                                       other->wholistsme.push_back(dat);
+                               }
+                       }
+               }
+
+               void* old = set_raw(container, dat);
+               if (old)
+                       this->free(old);
        }
 
        callerid_data* get(User* user, bool create)
@@ -119,6 +122,7 @@ struct CallerIDExtInfo : public ExtensionItem
                        if (it2 != targ->wholistsme.end())
                                targ->wholistsme.erase(it2);
                }
+               delete dat;
        }
 };
 
@@ -136,6 +140,7 @@ public:
        CommandAccept(Module* Creator) : Command(Creator, "ACCEPT", 1),
                extInfo(Creator)
        {
+               allow_empty_last_param = false;
                syntax = "{[+|-]<nicks>}|*}";
                TRANSLATE2(TR_CUSTOM, TR_END);
        }
@@ -144,7 +149,7 @@ public:
        {
                if (index != 0)
                        return;
-               std::string out = "";
+               std::string out;
                irc::commasepstream nicks(parameter);
                std::string tok;
                while (nicks.GetToken(tok))
@@ -338,7 +343,7 @@ public:
                ServerInstance->Modules->AddService(cmd.extInfo);
 
                Implementation eventlist[] = { I_OnRehash, I_OnUserPostNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage };
-               ServerInstance->Modules->Attach(eventlist, this, 6);
+               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
        virtual ~ModuleCallerID()
@@ -412,11 +417,11 @@ public:
 
        virtual void OnRehash(User* user)
        {
-               ConfigReader Conf;
-               cmd.maxaccepts = Conf.ReadInteger("callerid", "maxaccepts", "16", 0, true);
-               operoverride = Conf.ReadFlag("callerid", "operoverride", "0", 0);
-               tracknick = Conf.ReadFlag("callerid", "tracknick", "0", 0);
-               notify_cooldown = Conf.ReadInteger("callerid", "cooldown", "60", 0, true);
+               ConfigTag* tag = ServerInstance->Config->ConfValue("callerid");
+               cmd.maxaccepts = tag->getInt("maxaccepts", 16);
+               operoverride = tag->getBool("operoverride");
+               tracknick = tag->getBool("tracknick");
+               notify_cooldown = tag->getInt("cooldown", 60);
        }
 };