X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_watch.cpp;h=9b98ca83badedc4b958e6ab5f3301e89b55b1b08;hb=8cebe2878f3878afce6f643d93668155cb26801d;hp=bbda1f593faa73cf99ba958beead0719523ae851;hpb=d185decae97752368d5cf62311cbc0d1a52aa22c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index bbda1f593..9b98ca83b 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -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. @@ -87,10 +87,10 @@ * 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, nspace::hash_compare > > watchentries; +#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED) + typedef nspace::hash_map, nspace::hash_compare > > watchentries; #else -typedef nspace::hash_map, nspace::hash > watchentries; + typedef nspace::hash_map, nspace::hash > watchentries; #endif typedef std::map watchlist; @@ -162,7 +162,7 @@ class CommandWatch : public Command wl->erase(n); } - if (!wl->size()) + if (wl->empty()) { user->Shrink("watchlist"); delete wl; @@ -177,16 +177,13 @@ class CommandWatch : public Command /* I'm no longer watching you... */ x->second.erase(n2); - if (!x->second.size()) + if (x->second.empty()) + /* nobody else is, either. */ whos_watching_me->erase(nick); } } - /* 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) @@ -251,7 +248,7 @@ class CommandWatch : public Command } } - return CMD_FAILURE; + return CMD_LOCALONLY; } CommandWatch (InspIRCd* Instance, unsigned int &maxwatch) : Command(Instance,"WATCH",0,0), MAX_WATCH(maxwatch) @@ -263,7 +260,7 @@ class CommandWatch : public Command CmdResult Handle (const std::vector ¶meters, User *user) { - if (!parameters.size()) + if (parameters.empty()) { watchlist* wl; if (user->GetExt("watchlist", wl)) @@ -298,8 +295,9 @@ class CommandWatch : public Command /* I'm no longer watching you... */ i2->second.erase(n); - if (!i2->second.size()) - whos_watching_me->erase(user->nick.c_str()); + if (i2->second.empty()) + /* nobody else is, either. */ + whos_watching_me->erase(i2); } } @@ -363,32 +361,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, maxwatch), sw(Me) { - 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 ¶meter) + virtual void OnRehash(User* user) { ConfigReader Conf(ServerInstance); maxwatch = Conf.ReadInteger("watch", "maxentries", 0, true); @@ -432,7 +427,7 @@ class Modulewatch : public Module { for (std::deque::iterator n = x->second.begin(); n != x->second.end(); n++) { - if (!user->Visibility || user->Visibility->VisibleTo(user)) + 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()); watchlist* wl; @@ -458,8 +453,9 @@ class Modulewatch : public Module /* I'm no longer watching you... */ i2->second.erase(n); - if (!i2->second.size()) - whos_watching_me->erase(user->nick.c_str()); + if (i2->second.empty()) + /* and nobody else is, either. */ + whos_watching_me->erase(i2); } } @@ -502,7 +498,7 @@ class Modulewatch : public Module { for (std::deque::iterator n = x->second.begin(); n != x->second.end(); n++) { - if (!user->Visibility || user->Visibility->VisibleTo(user)) + 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); watchlist* wl; @@ -525,7 +521,7 @@ class Modulewatch : public Module watchlist* wl; if ((*n)->GetExt("watchlist", wl)) { - if (!user->Visibility || user->Visibility->VisibleTo(user)) + 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); (*wl)[oldnick.c_str()] = ""; } @@ -540,7 +536,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(user)) + 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()); } } @@ -560,7 +556,7 @@ class Modulewatch : public Module virtual Version GetVersion() { - return Version(1, 2, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION); + return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION); } };