From 711b65bb2a2470b1b3b8fee9bf8dd45b56361a1a Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 9 May 2007 21:00:06 +0000 Subject: Add extra matches to /WHO. flags aiMp, away, ident, metadata, port number git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6926 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/commands/cmd_who.h | 7 ++++- src/cmd_who.cpp | 65 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/include/commands/cmd_who.h b/include/commands/cmd_who.h index 4448ddcef..864dd6cb7 100644 --- a/include/commands/cmd_who.h +++ b/include/commands/cmd_who.h @@ -32,10 +32,15 @@ class cmd_who : public command_t bool opt_unlimit; bool opt_realname; bool opt_mode; + bool opt_ident; + bool opt_metadata; + bool opt_port; + bool opt_away; public: - cmd_who (InspIRCd* Instance) : command_t(Instance,"WHO",0,1) { syntax = "|||||0 [ohurm]"; } + cmd_who (InspIRCd* Instance) : command_t(Instance,"WHO",0,1) { syntax = "|||||0 [ohurmMiap]"; } void SendWhoLine(userrec* user, const std::string &initial, chanrec* ch, userrec* u, std::vector &whoresults); CmdResult Handle(const char** parameters, int pcnt, userrec *user); + bool whomatch(userrec* user, const char* matchtext); }; #endif diff --git a/src/cmd_who.cpp b/src/cmd_who.cpp index 914d46cef..39169b4ac 100644 --- a/src/cmd_who.cpp +++ b/src/cmd_who.cpp @@ -30,11 +30,16 @@ static char *getlastchanname(userrec *u) return "*"; } -bool whomatch(userrec* user, const char* matchtext, bool opt_realname, bool opt_showrealhost, bool opt_mode) +bool cmd_who::whomatch(userrec* user, const char* matchtext) { bool realhost = false; bool realname = false; bool positive = true; + bool metadata = false; + bool ident = false; + bool away = false; + bool port = false; + char* dummy = NULL; if (user->registered != REG_ALL) return false; @@ -58,14 +63,38 @@ bool whomatch(userrec* user, const char* matchtext, bool opt_realname, bool opt_ } return true; } + else + { - if (opt_realname) - realname = match(user->fullname, matchtext); - - if (opt_showrealhost) - realhost = match(user->host, matchtext); - - return ((realname) || (realhost) || (match(user->dhost, matchtext)) || (match(user->nick, matchtext)) || (match(user->server, matchtext))); + if (opt_metadata) + metadata = user->GetExt(matchtext, dummy); + else + { + if (opt_realname) + realname = match(user->fullname, matchtext); + else + { + if (opt_showrealhost) + realhost = match(user->host, matchtext); + else + { + if (opt_ident) + ident = match(user->ident, matchtext); + else + { + if (opt_port) + port = (user->GetPort() == ConvToInt(matchtext)); + else + { + if (opt_away) + away = match(user->awaymsg, matchtext); + } + } + } + } + } + return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (match(user->dhost, matchtext)) || (match(user->nick, matchtext)) || (match(user->server, matchtext))); + } } @@ -141,6 +170,10 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user) opt_unlimit = false; opt_realname = false; opt_mode = false; + opt_ident = false; + opt_metadata = false; + opt_port = false; + opt_away = false; chanrec *ch = NULL; std::vector whoresults; @@ -179,6 +212,18 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user) case 'm': opt_mode = true; break; + case 'M': + opt_metadata = true; + break; + case 'i': + opt_ident = true; + break; + case 'p': + opt_port = true; + break; + case 'a': + opt_away = true; + break; } *iter++; @@ -223,7 +268,7 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user) { userrec* oper = *i; - if (whomatch(oper, matchtext, opt_realname, opt_showrealhost, opt_mode)) + if (whomatch(oper, matchtext)) { if (!oper->IsModeSet('i')) SendWhoLine(user, initial, NULL, oper, whoresults); @@ -234,7 +279,7 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user) { for (user_hash::iterator i = ServerInstance->clientlist->begin(); i != ServerInstance->clientlist->end(); i++) { - if (whomatch(i->second, matchtext, opt_realname, opt_showrealhost, opt_mode)) + if (whomatch(i->second, matchtext)) { if (!i->second->IsModeSet('i')) SendWhoLine(user, initial, NULL, i->second, whoresults); -- cgit v1.2.3