]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_watch.cpp
Add initial query support to m_mysql [patch by Athenon]
[user/henk/code/inspircd.git] / src / modules / m_watch.cpp
index fd48f7f04571f4e740c02791558eb2def100074e..1cda4484fd6820149783c20e6dc558cceeead89b 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  * Before you start screaming, this definition is only used here, so moving it to a header is pointless.
  * Yes, it's horrid. Blame cl for being different. -- w00t
  */
-#ifdef WINDOWS
-typedef nspace::hash_map<irc::string, std::deque<User*>, nspace::hash_compare<irc::string, std::less<irc::string> > > watchentries;
+#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
+       typedef nspace::hash_map<irc::string, std::deque<User*>, nspace::hash_compare<irc::string, std::less<irc::string> > > watchentries;
 #else
-typedef nspace::hash_map<irc::string, std::deque<User*>, nspace::hash<irc::string> > watchentries;
+       typedef nspace::hash_map<irc::string, std::deque<User*>, nspace::hash<irc::string> > watchentries;
 #endif
 typedef std::map<irc::string, std::string> watchlist;
 
@@ -103,9 +103,8 @@ watchentries* whos_watching_me;
 class CommandSVSWatch : public Command
 {
  public:
-       CommandSVSWatch (InspIRCd* Instance) : Command(Instance,"SVSWATCH", 0, 2)
+       CommandSVSWatch (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"SVSWATCH", 0, 2)
        {
-               this->source = "m_watch.so";
                syntax = "<target> [C|L|S]|[+|-<nick>]";
                TRANSLATE3(TR_NICK, TR_TEXT, TR_END); /* we watch for a nick. not a UID. */
        }
@@ -183,11 +182,7 @@ class CommandWatch : public Command
                        }
                }
 
-               /* This might seem confusing, but we return CMD_FAILURE
-                * to indicate that this message shouldnt be routed across
-                * the network to other linked servers.
-                */
-               return CMD_FAILURE;
+               return CMD_LOCALONLY;
        }
 
        CmdResult add_watch(User* user, const char* nick)
@@ -231,13 +226,6 @@ class CommandWatch : public Command
                        User* target = ServerInstance->FindNick(nick);
                        if (target)
                        {
-                               if (target->Visibility && !target->Visibility->VisibleTo(user))
-                               {
-                                       (*wl)[nick] = "";
-                                       user->WriteNumeric(605, "%s %s * * 0 :is offline",user->nick.c_str(), nick);
-                                       return CMD_FAILURE;
-                               }
-
                                (*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());
                                if (IS_AWAY(target))
@@ -252,12 +240,11 @@ class CommandWatch : public Command
                        }
                }
 
-               return CMD_FAILURE;
+               return CMD_LOCALONLY;
        }
 
-       CommandWatch (InspIRCd* Instance, unsigned int &maxwatch) : Command(Instance,"WATCH",0,0), MAX_WATCH(maxwatch)
+       CommandWatch (InspIRCd* Instance, Module* parent, unsigned int &maxwatch) : Command(Instance,parent,"WATCH",0,0), MAX_WATCH(maxwatch)
        {
-               this->source = "m_watch.so";
                syntax = "[C|L|S]|[+|-<nick>]";
                TRANSLATE2(TR_TEXT, TR_END); /* we watch for a nick. not a UID. */
        }
@@ -365,32 +352,29 @@ class CommandWatch : public Command
                                }
                        }
                }
-               /* So that spanningtree doesnt pass the WATCH commands to the network! */
-               return CMD_FAILURE;
+               return CMD_LOCALONLY;
        }
 };
 
 class Modulewatch : public Module
 {
-       CommandWatch* mycommand;
-       CommandSVSWatch *sw;
        unsigned int maxwatch;
+       CommandWatch cmdw;
+       CommandSVSWatch sw;
 
  public:
        Modulewatch(InspIRCd* Me)
-               : Module(Me), maxwatch(32)
+               : Module(Me), maxwatch(32), cmdw(Me, this, maxwatch), sw(Me,this) 
        {
-               OnRehash(NULL, "");
+               OnRehash(NULL);
                whos_watching_me = new watchentries();
-               mycommand = new CommandWatch(ServerInstance, maxwatch);
-               ServerInstance->AddCommand(mycommand);
-               sw = new CommandSVSWatch(ServerInstance);
-               ServerInstance->AddCommand(sw);
+               ServerInstance->AddCommand(&cmdw);
+               ServerInstance->AddCommand(&sw);
                Implementation eventlist[] = { I_OnRehash, I_OnGarbageCollect, I_OnCleanup, I_OnUserQuit, I_OnPostConnect, I_OnUserPostNick, I_On005Numeric, I_OnSetAway };
                ServerInstance->Modules->Attach(eventlist, this, 8);
        }
 
-       virtual void OnRehash(User* user, const std::string &parameter)
+       virtual void OnRehash(User* user)
        {
                ConfigReader Conf(ServerInstance);
                maxwatch = Conf.ReadInteger("watch", "maxentries", 0, true);
@@ -398,7 +382,7 @@ class Modulewatch : public Module
                        maxwatch = 32;
        }
 
-       virtual int OnSetAway(User *user, const std::string &awaymsg)
+       virtual ModResult OnSetAway(User *user, const std::string &awaymsg)
        {
                std::string numeric;
                int inum;
@@ -419,12 +403,11 @@ class Modulewatch : public Module
                {
                        for (std::deque<User*>::iterator n = x->second.begin(); n != x->second.end(); n++)
                        {
-                               if (!user->Visibility || user->Visibility->VisibleTo(user))
-                                       (*n)->WriteNumeric(inum, numeric);
+                               (*n)->WriteNumeric(inum, numeric);
                        }
                }
 
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 
        virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
@@ -434,8 +417,7 @@ class Modulewatch : public Module
                {
                        for (std::deque<User*>::iterator n = x->second.begin(); n != x->second.end(); n++)
                        {
-                               if (!user->Visibility || user->Visibility->VisibleTo(*n))
-                                       (*n)->WriteNumeric(601, "%s %s %s %s %lu :went offline", (*n)->nick.c_str() ,user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) ServerInstance->Time());
+                               (*n)->WriteNumeric(601, "%s %s %s %s %lu :went offline", (*n)->nick.c_str() ,user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) ServerInstance->Time());
 
                                watchlist* wl;
                                if ((*n)->GetExt("watchlist", wl))
@@ -505,8 +487,7 @@ class Modulewatch : public Module
                {
                        for (std::deque<User*>::iterator n = x->second.begin(); n != x->second.end(); n++)
                        {
-                               if (!user->Visibility || user->Visibility->VisibleTo(*n))
-                                       (*n)->WriteNumeric(600, "%s %s %s %s %lu :arrived online", (*n)->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) user->age);
+                               (*n)->WriteNumeric(600, "%s %s %s %s %lu :arrived online", (*n)->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) user->age);
 
                                watchlist* wl;
                                if ((*n)->GetExt("watchlist", wl))
@@ -528,8 +509,7 @@ class Modulewatch : public Module
                                watchlist* wl;
                                if ((*n)->GetExt("watchlist", wl))
                                {
-                                       if (!user->Visibility || user->Visibility->VisibleTo(*n))
-                                               (*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);
+                                       (*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()] = "";
                                }
                        }
@@ -543,8 +523,7 @@ class Modulewatch : public Module
                                if ((*n)->GetExt("watchlist", wl))
                                {
                                        (*wl)[user->nick.c_str()] = std::string(user->ident).append(" ").append(user->dhost).append(" ").append(ConvToStr(user->age));
-                                       if (!user->Visibility || user->Visibility->VisibleTo(*n))
-                                               (*n)->WriteNumeric(600, "%s %s %s :arrived online", (*n)->nick.c_str(), user->nick.c_str(), (*wl)[user->nick.c_str()].c_str());
+                                       (*n)->WriteNumeric(600, "%s %s %s :arrived online", (*n)->nick.c_str(), user->nick.c_str(), (*wl)[user->nick.c_str()].c_str());
                                }
                        }
                }