]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_watch.cpp
m_watch Be more strict when checking whether the watch list of a user is full
[user/henk/code/inspircd.git] / src / modules / m_watch.cpp
index 3750fceac0bf2b0427a32ef0d6cb24ed6aa51040..be05d7d2d7e2c2154c51ae4abeaf2073b38b54bc 100644 (file)
@@ -214,7 +214,7 @@ class CommandWatch : public Command
                        ext.set(user, wl);
                }
 
-               if (wl->size() == MAX_WATCH)
+               if (wl->size() >= MAX_WATCH)
                {
                        user->WriteNumeric(512, "%s %s :Too many WATCH entries", user->nick.c_str(), nick);
                        return CMD_FAILURE;
@@ -238,7 +238,7 @@ class CommandWatch : public Command
                        }
 
                        User* target = ServerInstance->FindNick(nick);
-                       if (target)
+                       if ((target) && (target->registered == REG_ALL))
                        {
                                (*wl)[nick] = std::string(target->ident).append(" ").append(target->dhost).append(" ").append(ConvToStr(target->age));
                                user->WriteNumeric(604, "%s %s %s :is online",user->nick.c_str(), nick, (*wl)[nick].c_str());
@@ -249,7 +249,7 @@ class CommandWatch : public Command
                        }
                        else
                        {
-                               (*wl)[nick] = "";
+                               (*wl)[nick].clear();
                                user->WriteNumeric(605, "%s %s * * 0 :is offline",user->nick.c_str(), nick);
                        }
                }
@@ -316,10 +316,10 @@ class CommandWatch : public Command
                                        {
                                                for (watchlist::iterator q = wl->begin(); q != wl->end(); q++)
                                                {
-                                                       if (!q->second.empty())
+                                                       User* targ = ServerInstance->FindNick(q->first.c_str());
+                                                       if (targ && !q->second.empty())
                                                        {
                                                                user->WriteNumeric(604, "%s %s %s :is online", user->nick.c_str(), q->first.c_str(), q->second.c_str());
-                                                               User *targ = ServerInstance->FindNick(q->first.c_str());
                                                                if (IS_AWAY(targ))
                                                                {
                                                                        user->WriteNumeric(609, "%s %s %s %s %lu :is away", user->nick.c_str(), targ->nick.c_str(), targ->ident.c_str(), targ->dhost.c_str(), (unsigned long) targ->awaytime);
@@ -377,15 +377,19 @@ class Modulewatch : public Module
 
  public:
        Modulewatch()
-               : maxwatch(32), cmdw(this, maxwatch), sw(this) 
+               : maxwatch(32), cmdw(this, maxwatch), sw(this)
        {
-               OnRehash(NULL);
                whos_watching_me = new watchentries();
-               ServerInstance->AddCommand(&cmdw);
-               ServerInstance->AddCommand(&sw);
-               ServerInstance->Extensions.Register(&cmdw.ext);
+       }
+
+       void init()
+       {
+               OnRehash(NULL);
+               ServerInstance->Modules->AddService(cmdw);
+               ServerInstance->Modules->AddService(sw);
+               ServerInstance->Modules->AddService(cmdw.ext);
                Implementation eventlist[] = { I_OnRehash, I_OnGarbageCollect, I_OnUserQuit, I_OnPostConnect, I_OnUserPostNick, I_On005Numeric, I_OnSetAway };
-               ServerInstance->Modules->Attach(eventlist, this, 7);
+               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
        virtual void OnRehash(User* user)
@@ -435,7 +439,7 @@ class Modulewatch : public Module
                                watchlist* wl = cmdw.ext.get(*n);
                                if (wl)
                                        /* We were on somebody's notify list, set ourselves offline */
-                                       (*wl)[user->nick.c_str()] = "";
+                                       (*wl)[user->nick.c_str()].clear();
                        }
                }
 
@@ -504,7 +508,7 @@ class Modulewatch : public Module
                                if (wl)
                                {
                                        (*n)->WriteNumeric(601, "%s %s %s %s %lu :went offline", (*n)->nick.c_str(), oldnick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) user->age);
-                                       (*wl)[oldnick.c_str()] = "";
+                                       (*wl)[oldnick.c_str()].clear();
                                }
                        }
                }