]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_watch.cpp
Works with the m_testclient test program/suite!
[user/henk/code/inspircd.git] / src / modules / m_watch.cpp
index e3a0815a599a5ed9b39ad99468011949e8070b6d..c15609a4d07e11fafffa02ce764884aa33060970 100644 (file)
@@ -29,7 +29,7 @@ using namespace std;
 
 static Server *Srv;
 
-class watchentry
+class watchentry : public classbase
 {
  public:
        userrec* watcher;
@@ -47,71 +47,71 @@ class cmd_watch : public command_t
                this->source = "m_watch.so";
        }
 
-       void Handle (char **parameters, int pcnt, userrec *user)
+       void Handle (const char** parameters, int pcnt, userrec *user)
        {
                if (!pcnt)
                {
-                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
-                       {
-                               if (q->watcher == user)
-                               {
+                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+                       {
+                               if (q->watcher == user)
+                               {
                                        userrec* targ = Srv->FindNick(q->target);
                                        if (targ)
                                        {
                                                WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
                                        }
-                               }
-                       }
+                               }
+                       }
                        WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
                }
                else if (pcnt > 0)
                {
                        for (int x = 0; x < pcnt; x++)
                        {
-                               char *nick = parameters[x];
+                               const char *nick = parameters[x];
                                if (!strcasecmp(nick,"C"))
                                {
                                        // watch clear
-                                       bool done = false;
-                                       while (!done)
-                                       {
-                                               done = true;
-                                               for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
-                                               {
-                                                       if (q->watcher == user)
-                                                       {
-                                                               done = false;
-                                                               watches.erase(q);
-                                                               break;
-                                                       }
-                                               }
-                                       }
+                                       bool done = false;
+                                       while (!done)
+                                       {
+                                               done = true;
+                                               for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+                                               {
+                                                       if (q->watcher == user)
+                                                       {
+                                                               done = false;
+                                                               watches.erase(q);
+                                                               break;
+                                                       }
+                                               }
+                                       }
                                }
                                else if (!strcasecmp(nick,"L"))
                                {
-                                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
-                                       {
-                                               if (q->watcher == user)
-                                               {
-                                                       userrec* targ = Srv->FindNick(q->target);
-                                                       if (targ)
-                                                       {
-                                                               WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
-                                                       }
-                                               }
-                                       }
-                                       WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+                                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+                                       {
+                                               if (q->watcher == user)
+                                               {
+                                                       userrec* targ = Srv->FindNick(q->target);
+                                                       if (targ)
+                                                       {
+                                                               WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
+                                                       }
+                                               }
+                                       }
+                                       WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
                                }
                                else if (!strcasecmp(nick,"S"))
                                {
                                        std::string list = "";
-                                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
-                                       {
-                                               if (q->watcher == user)
-                                               {
+                                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+                                       {
+                                               if (q->watcher == user)
+                                               {
                                                        list = list + " " + q->target;
-                                               }
-                                       }
+                                               }
+                                       }
                                        char* l = (char*)list.c_str();
                                        if (*l == ' ')
                                                l++;
@@ -123,25 +123,25 @@ class cmd_watch : public command_t
                                        // removing an item from the list
                                        nick++;
                                        irc::string n1 = nick;
-                                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
-                                       {
-                                               if (q->watcher == user)
-                                               {
+                                       for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+                                       {
+                                               if (q->watcher == user)
+                                               {
                                                        irc::string n2 = q->target.c_str();
                                                        userrec* a = Srv->FindNick(q->target);
-                                                       if (a)
-                                                       {
-                                                               WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
-                                                       }
-                                                       else
-                                                       {
-                                                                WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
-                                                       }
-                                                       if (n1 == n2)
-                                                       {
-                                                               watches.erase(q);
-                                                               break;
-                                                       }
+                                                       if (a)
+                                                       {
+                                                               WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
+                                                       }
+                                                       else
+                                                       {
+                                                                WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
+                                                       }
+                                                       if (n1 == n2)
+                                                       {
+                                                               watches.erase(q);
+                                                               break;
+                                                       }
                                                }
                                        }
                                }
@@ -170,15 +170,15 @@ class cmd_watch : public command_t
                                                watches.push_back(w);
                                                log(DEBUG,"*** Added %s to watchlist of %s",nick,user->nick);
                                        }
-                                       userrec* a = Srv->FindNick(nick);
-                                       if (a)
-                                       {
-                                               WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
-                                       }
-                                       else
-                                       {
-                                               WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
-                                       }
+                                       userrec* a = Srv->FindNick(nick);
+                                       if (a)
+                                       {
+                                               WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
+                                       }
+                                       else
+                                       {
+                                               WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
+                                       }
                                }
                        }
                }