X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_watch.cpp;h=a86483291805b8250a6320c768b18b48ecba3799;hb=748b3a0d89e7ecc9a766471b79fb78f63a5ca2bb;hp=ab32c674047ba31f5ccc2bb58019e9d019d0f16d;hpb=6d57bbe05c31c79eaad02fe81cfb9c1ed6b79c58;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index ab32c6740..a86483291 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -1,16 +1,25 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2005-2008 Craig Edwards + * Copyright (C) 2006-2008 Robin Burchell + * Copyright (C) 2007 Dennis Friis * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * --------------------------------------------------- + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #include "inspircd.h" /* $ModDesc: Provides support for the /WATCH command */ @@ -87,11 +96,8 @@ * 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 */ -#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED) - typedef nspace::hash_map, nspace::hash_compare > > watchentries; -#else - typedef nspace::hash_map, nspace::hash > watchentries; -#endif + +typedef nspace::hash_map, irc::hash> watchentries; typedef std::map watchlist; /* Who's watching each nickname. @@ -103,7 +109,7 @@ watchentries* whos_watching_me; class CommandSVSWatch : public Command { public: - CommandSVSWatch (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"SVSWATCH", 0, 2) + CommandSVSWatch(Module* Creator) : Command(Creator,"SVSWATCH", 2) { syntax = " [C|L|S]|[+|-]"; TRANSLATE3(TR_NICK, TR_TEXT, TR_END); /* we watch for a nick. not a UID. */ @@ -128,7 +134,10 @@ class CommandSVSWatch : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - return ROUTE_BROADCAST; + User* target = ServerInstance->FindNick(parameters[0]); + if (target) + return ROUTE_OPT_UCAST(target->server); + return ROUTE_LOCALONLY; } }; @@ -154,9 +163,6 @@ class CommandWatch : public Command /* Yup, is on my list */ watchlist::iterator n = wl->find(nick); - if (!wl) - return CMD_FAILURE; - if (n != wl->end()) { if (!n->second.empty()) @@ -205,7 +211,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; @@ -229,7 +235,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()); @@ -240,7 +246,7 @@ class CommandWatch : public Command } else { - (*wl)[nick] = ""; + (*wl)[nick].clear(); user->WriteNumeric(605, "%s %s * * 0 :is offline",user->nick.c_str(), nick); } } @@ -248,8 +254,7 @@ class CommandWatch : public Command return CMD_SUCCESS; } - CommandWatch (InspIRCd* Instance, Module* parent, unsigned int &maxwatch) - : Command(Instance,parent,"WATCH",0,0), MAX_WATCH(maxwatch), ext("watchlist", parent) + CommandWatch(Module* parent, unsigned int &maxwatch) : Command(parent,"WATCH", 0), MAX_WATCH(maxwatch), ext("watchlist", parent) { syntax = "[C|L|S]|[+|-]"; TRANSLATE2(TR_TEXT, TR_END); /* we watch for a nick. not a UID. */ @@ -308,10 +313,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); @@ -368,22 +373,25 @@ class Modulewatch : public Module CommandSVSWatch sw; public: - Modulewatch(InspIRCd* Me) - : Module(Me), maxwatch(32), cmdw(Me, this, maxwatch), sw(Me,this) + Modulewatch() + : maxwatch(32), cmdw(this, maxwatch), sw(this) { - OnRehash(NULL); whos_watching_me = new watchentries(); - ServerInstance->AddCommand(&cmdw); - ServerInstance->AddCommand(&sw); - Extensible::Register(&cmdw.ext); - Implementation eventlist[] = { I_OnRehash, I_OnGarbageCollect, I_OnCleanup, I_OnUserQuit, I_OnPostConnect, I_OnUserPostNick, I_On005Numeric, I_OnSetAway }; - ServerInstance->Modules->Attach(eventlist, this, 8); + } + + 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, sizeof(eventlist)/sizeof(Implementation)); } virtual void OnRehash(User* user) { - ConfigReader Conf(ServerInstance); - maxwatch = Conf.ReadInteger("watch", "maxentries", 0, true); + maxwatch = ServerInstance->Config->ConfValue("watch")->getInt("maxentries", 32); if (!maxwatch) maxwatch = 32; } @@ -395,12 +403,12 @@ class Modulewatch : public Module if (awaymsg.empty()) { - numeric = std::string(user->nick) + " " + user->ident + " " + user->dhost + " " + ConvToStr(ServerInstance->Time()) + " :is no longer away"; + numeric = user->nick + " " + user->ident + " " + user->dhost + " " + ConvToStr(ServerInstance->Time()) + " :is no longer away"; inum = 599; } else { - numeric = std::string(user->nick) + " " + user->ident + " " + user->dhost + " " + ConvToStr(ServerInstance->Time()) + " :" + awaymsg; + numeric = user->nick + " " + user->ident + " " + user->dhost + " " + ConvToStr(ServerInstance->Time()) + " :" + awaymsg; inum = 598; } @@ -409,7 +417,7 @@ class Modulewatch : public Module { for (std::deque::iterator n = x->second.begin(); n != x->second.end(); n++) { - (*n)->WriteNumeric(inum, numeric); + (*n)->WriteNumeric(inum, (*n)->nick + " " + numeric); } } @@ -428,7 +436,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(); } } @@ -497,7 +505,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(); } } } @@ -529,7 +537,7 @@ class Modulewatch : public Module virtual Version GetVersion() { - return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION); + return Version("Provides support for the /WATCH command", VF_OPTCOMMON | VF_VENDOR); } };