From d48726ce802019f2e1573ebef7ae9f50a14f0a31 Mon Sep 17 00:00:00 2001 From: w00t Date: Sun, 30 Mar 2008 15:33:33 +0000 Subject: AWAY notification for WATCH. Numerics are now sent out when a user goes away (or returns from AWAY), as well as in WATCH L (if the user is online and away). git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9227 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/users.h | 5 +++++ src/commands/cmd_away.cpp | 1 + src/modules/m_spanningtree/main.cpp | 2 +- src/modules/m_watch.cpp | 43 +++++++++++++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/include/users.h b/include/users.h index 29db518b7..0fa51268d 100644 --- a/include/users.h +++ b/include/users.h @@ -556,6 +556,11 @@ class CoreExport User : public connection */ char awaymsg[MAXAWAY+1]; + /** Time the user last went away. + * This is ONLY RELIABLE if user IS_AWAY()! + */ + time_t awaytime; + /** Timestamp of current time + connection class timeout. * This user must send USER/NICK before this timestamp is * reached or they will be disconnected. diff --git a/src/commands/cmd_away.cpp b/src/commands/cmd_away.cpp index c49813b52..33e140beb 100644 --- a/src/commands/cmd_away.cpp +++ b/src/commands/cmd_away.cpp @@ -32,6 +32,7 @@ CmdResult CommandAway::Handle (const char* const* parameters, int pcnt, User *us if (MOD_RESULT != 0 && !IS_LOCAL(user)) return CMD_FAILURE; + user->awaytime = ServerInstance->Time(); strlcpy(user->awaymsg,parameters[0],MAXAWAY); user->WriteNumeric(306, "%s :You have been marked as being away",user->nick); } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 84771901e..b1f5d3153 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -54,7 +54,7 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me) I_OnOper, I_OnAddLine, I_OnDelLine, I_ProtoSendMode, I_OnMode, I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnPostCommand }; - ServerInstance->Modules->Attach(eventlist, this, 29); + ServerInstance->Modules->Attach(eventlist, this, 28); for (std::vector::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++) { diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index d94796a20..ac0b5affb 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -239,6 +239,10 @@ class CommandWatch : public Command (*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, nick, (*wl)[nick].c_str()); + if (IS_AWAY(target)) + { + user->WriteNumeric(609, "%s %s %s %s %ld :is away", user->nick, target->nick, target->ident, target->dhost, target->awaytime); + } } else { @@ -311,7 +315,14 @@ 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, 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 %ld :is away", user->nick, targ->nick, targ->ident, targ->dhost, targ->awaytime); + } + } else user->WriteNumeric(605, "%s %s * * 0 :is offline", user->nick, q->first.c_str()); } @@ -373,8 +384,8 @@ class Modulewatch : public Module ServerInstance->AddCommand(mycommand); sw = new CommandSVSWatch(ServerInstance); ServerInstance->AddCommand(sw); - Implementation eventlist[] = { I_OnRehash, I_OnGarbageCollect, I_OnCleanup, I_OnUserQuit, I_OnPostConnect, I_OnUserPostNick, I_On005Numeric }; - ServerInstance->Modules->Attach(eventlist, this, 7); + 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) @@ -385,6 +396,34 @@ class Modulewatch : public Module maxwatch = 32; } + virtual int OnSetAway(User *user, const std::string &awaymsg) + { + std::string numeric; + int inum; + + if (awaymsg.empty()) + { + numeric = std::string(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; + inum = 598; + } + + watchentries::iterator x = whos_watching_me->find(user->nick); + if (x != whos_watching_me->end()) + { + for (std::deque::iterator n = x->second.begin(); n != x->second.end(); n++) + { + if (!user->Visibility || user->Visibility->VisibleTo(user)) + (*n)->WriteNumeric(inum, numeric); + } + } + + return 0; + } virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) { -- cgit v1.2.3