X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_watch.cpp;h=9cb31a6d88e3460bbc7fc042ce851d3bc2fe3cfd;hb=0e5fb98a6b82af738f6d5c3093d9597d470be3a6;hp=a2a458c33016097fd4c542cecedccb38157ee857;hpb=ac7defcd3e52695dcf5e5150e9fe3e1624205e64;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index a2a458c33..9cb31a6d8 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -22,8 +22,6 @@ #include "inspircd.h" -/* $ModDesc: Provides support for the /WATCH command */ - /* * Okay, it's nice that this was documented and all, but I at least understood very little @@ -92,12 +90,7 @@ * of users using WATCH. */ -/* - * 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 - */ - -typedef nspace::hash_map, irc::hash> watchentries; +typedef TR1NS::unordered_map, irc::hash> watchentries; typedef std::map watchlist; /* Who's watching each nickname. @@ -112,12 +105,12 @@ class CommandSVSWatch : public Command 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. */ + TRANSLATE2(TR_NICK, TR_TEXT); /* we watch for a nick. not a UID. */ } CmdResult Handle (const std::vector ¶meters, User *user) { - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) return CMD_FAILURE; User *u = ServerInstance->FindNick(parameters[0]); @@ -126,7 +119,7 @@ class CommandSVSWatch : public Command if (IS_LOCAL(u)) { - ServerInstance->Parser->CallHandler("WATCH", parameters, u); + ServerInstance->Parser.CallHandler("WATCH", parameters, u); } return CMD_SUCCESS; @@ -151,9 +144,9 @@ class CommandWatch : public Command CmdResult remove_watch(User* user, const char* nick) { // removing an item from the list - if (!ServerInstance->IsNick(nick, ServerInstance->Config->Limits.NickMax)) + if (!ServerInstance->IsNick(nick)) { - user->WriteNumeric(942, "%s %s :Invalid nickname", user->nick.c_str(), nick); + user->WriteNumeric(942, "%s :Invalid nickname", nick); return CMD_FAILURE; } @@ -163,15 +156,12 @@ 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()) - user->WriteNumeric(602, "%s %s %s :stopped watching", user->nick.c_str(), n->first.c_str(), n->second.c_str()); + user->WriteNumeric(602, "%s %s :stopped watching", n->first.c_str(), n->second.c_str()); else - user->WriteNumeric(602, "%s %s * * 0 :stopped watching", user->nick.c_str(), nick); + user->WriteNumeric(602, "%s * * 0 :stopped watching", nick); wl->erase(n); } @@ -201,9 +191,9 @@ class CommandWatch : public Command CmdResult add_watch(User* user, const char* nick) { - if (!ServerInstance->IsNick(nick, ServerInstance->Config->Limits.NickMax)) + if (!ServerInstance->IsNick(nick)) { - user->WriteNumeric(942, "%s %s :Invalid nickname",user->nick.c_str(),nick); + user->WriteNumeric(942, "%s :Invalid nickname", nick); return CMD_FAILURE; } @@ -214,9 +204,9 @@ 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); + user->WriteNumeric(512, "%s :Too many WATCH entries", nick); return CMD_FAILURE; } @@ -238,19 +228,19 @@ 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()); - if (IS_AWAY(target)) + user->WriteNumeric(604, "%s %s :is online", nick, (*wl)[nick].c_str()); + if (target->IsAway()) { - user->WriteNumeric(609, "%s %s %s %s %lu :is away", user->nick.c_str(), target->nick.c_str(), target->ident.c_str(), target->dhost.c_str(), (unsigned long) target->awaytime); + user->WriteNumeric(609, "%s %s %s %lu :is away", target->nick.c_str(), target->ident.c_str(), target->dhost.c_str(), (unsigned long) target->awaytime); } } else { (*wl)[nick].clear(); - user->WriteNumeric(605, "%s %s * * 0 :is offline",user->nick.c_str(), nick); + user->WriteNumeric(605, "%s * * 0 :is offline", nick); } } @@ -260,7 +250,6 @@ class CommandWatch : public Command 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. */ } CmdResult Handle (const std::vector ¶meters, User *user) @@ -273,10 +262,10 @@ class CommandWatch : public Command for (watchlist::iterator q = wl->begin(); q != wl->end(); q++) { if (!q->second.empty()) - user->WriteNumeric(604, "%s %s %s :is online", user->nick.c_str(), q->first.c_str(), q->second.c_str()); + user->WriteNumeric(604, "%s %s :is online", q->first.c_str(), q->second.c_str()); } } - user->WriteNumeric(607, "%s :End of WATCH list",user->nick.c_str()); + user->WriteNumeric(607, ":End of WATCH list"); } else if (parameters.size() > 0) { @@ -316,20 +305,20 @@ 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(604, "%s %s :is online", q->first.c_str(), q->second.c_str()); + if (targ->IsAway()) { - 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); + user->WriteNumeric(609, "%s %s %s %lu :is away", targ->nick.c_str(), targ->ident.c_str(), targ->dhost.c_str(), (unsigned long) targ->awaytime); } } else - user->WriteNumeric(605, "%s %s * * 0 :is offline", user->nick.c_str(), q->first.c_str()); + user->WriteNumeric(605, "%s * * 0 :is offline", q->first.c_str()); } } - user->WriteNumeric(607, "%s :End of WATCH list",user->nick.c_str()); + user->WriteNumeric(607, ":End of WATCH list"); } else if (!strcasecmp(nick,"S")) { @@ -349,9 +338,9 @@ class CommandWatch : public Command if (i2 != whos_watching_me->end()) youre_on = i2->second.size(); - user->WriteNumeric(603, "%s :You have %d and are on %d WATCH entries", user->nick.c_str(), you_have, youre_on); - user->WriteNumeric(606, "%s :%s",user->nick.c_str(), list.c_str()); - user->WriteNumeric(607, "%s :End of WATCH S",user->nick.c_str()); + user->WriteNumeric(603, ":You have %d and are on %d WATCH entries", you_have, youre_on); + user->WriteNumeric(606, ":%s", list.c_str()); + user->WriteNumeric(607, ":End of WATCH S"); } else if (nick[0] == '-') { @@ -382,24 +371,14 @@ class Modulewatch : public Module whos_watching_me = new watchentries(); } - void init() - { - OnRehash(NULL); - ServerInstance->AddCommand(&cmdw); - ServerInstance->AddCommand(&sw); - ServerInstance->Extensions.Register(&cmdw.ext); - Implementation eventlist[] = { I_OnRehash, I_OnGarbageCollect, I_OnUserQuit, I_OnPostConnect, I_OnUserPostNick, I_On005Numeric, I_OnSetAway }; - ServerInstance->Modules->Attach(eventlist, this, 7); - } - - virtual void OnRehash(User* user) + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { maxwatch = ServerInstance->Config->ConfValue("watch")->getInt("maxentries", 32); if (!maxwatch) maxwatch = 32; } - virtual ModResult OnSetAway(User *user, const std::string &awaymsg) + ModResult OnSetAway(User *user, const std::string &awaymsg) CXX11_OVERRIDE { std::string numeric; int inum; @@ -427,14 +406,14 @@ class Modulewatch : public Module return MOD_RES_PASSTHRU; } - virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) + void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE { watchentries::iterator x = whos_watching_me->find(user->nick.c_str()); if (x != whos_watching_me->end()) { for (std::deque::iterator n = x->second.begin(); n != x->second.end(); 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 %lu :went offline", user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) ServerInstance->Time()); watchlist* wl = cmdw.ext.get(*n); if (wl) @@ -467,7 +446,7 @@ class Modulewatch : public Module } } - virtual void OnGarbageCollect() + void OnGarbageCollect() { watchentries* old_watch = whos_watching_me; whos_watching_me = new watchentries(); @@ -478,14 +457,14 @@ class Modulewatch : public Module delete old_watch; } - virtual void OnPostConnect(User* user) + void OnPostConnect(User* user) CXX11_OVERRIDE { watchentries::iterator x = whos_watching_me->find(user->nick.c_str()); if (x != whos_watching_me->end()) { for (std::deque::iterator n = x->second.begin(); n != x->second.end(); 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 %lu :arrived online", user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) user->age); watchlist* wl = cmdw.ext.get(*n); if (wl) @@ -495,7 +474,7 @@ class Modulewatch : public Module } } - virtual void OnUserPostNick(User* user, const std::string &oldnick) + void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE { watchentries::iterator new_offline = whos_watching_me->find(oldnick.c_str()); watchentries::iterator new_online = whos_watching_me->find(user->nick.c_str()); @@ -507,7 +486,7 @@ class Modulewatch : public Module watchlist* wl = cmdw.ext.get(*n); 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); + (*n)->WriteNumeric(601, "%s %s %s %lu :went offline", oldnick.c_str(), user->ident.c_str(), user->dhost.c_str(), (unsigned long) user->age); (*wl)[oldnick.c_str()].clear(); } } @@ -521,28 +500,26 @@ class Modulewatch : public Module if (wl) { (*wl)[user->nick.c_str()] = std::string(user->ident).append(" ").append(user->dhost).append(" ").append(ConvToStr(user->age)); - (*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 :arrived online", user->nick.c_str(), (*wl)[user->nick.c_str()].c_str()); } } } } - virtual void On005Numeric(std::string &output) + void On005Numeric(std::map& tokens) CXX11_OVERRIDE { - // we don't really have a limit... - output = output + " WATCH=" + ConvToStr(maxwatch); + tokens["WATCH"] = ConvToStr(maxwatch); } - virtual ~Modulewatch() + ~Modulewatch() { delete whos_watching_me; } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { return Version("Provides support for the /WATCH command", VF_OPTCOMMON | VF_VENDOR); } }; MODULE_INIT(Modulewatch) -