]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_watch.cpp
Tidyup
[user/henk/code/inspircd.git] / src / modules / m_watch.cpp
index 521ddde5610a6a4a97de36177cd93d8c67982b50..e60196c009e7e9e0fc6bd5cd975df396f2d22791 100644 (file)
@@ -22,15 +22,13 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "helperfuncs.h"
 #include "hashcomp.h"
 #include "inspircd.h"
 
 /* $ModDesc: Provides support for the /watch command */
 
-
-
-
+/** A watchlist entry
+ */
 class watchentry : public classbase
 {
  public:
@@ -41,16 +39,18 @@ class watchentry : public classbase
 typedef std::vector<watchentry*> watchlist;
 watchlist watches;
 
+/** Handle /WATCH
+ */
 class cmd_watch : public command_t
 {
  public:
- cmd_watch (InspIRCd* Instance) : command_t(Instance,"WATCH",0,0)
      cmd_watch (InspIRCd* Instance) : command_t(Instance,"WATCH",0,0)
        {
                this->source = "m_watch.so";
                syntax = "[C|L|S]|[+|-<nick>]";
        }
 
-       void Handle (const char** parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                if (!pcnt)
                {
@@ -130,6 +130,11 @@ class cmd_watch : public command_t
                                {
                                        // removing an item from the list
                                        nick++;
+                                       if (!ServerInstance->IsNick(nick))
+                                       {
+                                               user->WriteServ("942 %s %s :Invalid nickname",user->nick,nick);
+                                               return CMD_FAILURE;
+                                       }
                                        irc::string n1 = nick;
                                        for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
                                        {
@@ -144,7 +149,7 @@ class cmd_watch : public command_t
                                                        }
                                                        else
                                                        {
-                                                                user->WriteServ("602 %s %s * * 0 :stopped watching",user->nick,b->target.c_str());
+                                                               user->WriteServ("602 %s %s * * 0 :stopped watching",user->nick,b->target.c_str());
                                                        }
                                                        if (n1 == n2)
                                                        {
@@ -158,6 +163,11 @@ class cmd_watch : public command_t
                                else if (nick[0] == '+')
                                {
                                        nick++;
+                                       if (!ServerInstance->IsNick(nick))
+                                       {
+                                               user->WriteServ("942 %s %s :Invalid nickname",user->nick,nick);
+                                               return CMD_FAILURE;
+                                       }
                                        irc::string n1 = nick;
                                        bool exists = false;
                                        for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
@@ -193,7 +203,8 @@ class cmd_watch : public command_t
                                }
                        }
                }
-               return;
+               /* So that spanningtree doesnt pass the WATCH commands to the network! */
+               return CMD_FAILURE;
        }
 };
 
@@ -212,7 +223,7 @@ class Modulewatch : public Module
 
        void Implements(char* List)
        {
-               List[I_OnUserQuit] = List[I_OnGlobalConnect] = List[I_OnUserPostNick] = List[I_On005Numeric] = 1;
+               List[I_OnUserQuit] = List[I_OnPostConnect] = List[I_OnUserPostNick] = List[I_On005Numeric] = 1;
        }
 
        virtual void OnUserQuit(userrec* user, const std::string &reason)
@@ -247,7 +258,7 @@ class Modulewatch : public Module
                }
        }
 
-       virtual void OnGlobalConnect(userrec* user)
+       virtual void OnPostConnect(userrec* user)
        {
                irc::string n2 = user->nick;
                ServerInstance->Log(DEBUG,"*** WATCH: On global connect: user %s",user->nick);
@@ -299,7 +310,7 @@ class Modulewatch : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1,VF_VENDOR);
+               return Version(1,1,0,1,VF_VENDOR,API_VERSION);
        }
 };