]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/cmd_who.cpp
Bad w00tie bad, /who isnt checking +s for channel /who!
[user/henk/code/inspircd.git] / src / cmd_who.cpp
index 367bdb326715335ccd4570d4ae165381c39badab..508956c44f166c051c10ac8749f10699569df717 100644 (file)
@@ -37,14 +37,35 @@ static char *getlastchanname(userrec *u)
        return "*";
 }
 
-bool whomatch(userrec* user, const char* matchtext, bool opt_realname, bool opt_showrealhost)
+bool whomatch(userrec* user, const char* matchtext, bool opt_realname, bool opt_showrealhost, bool opt_mode)
 {
        bool realhost = false;
        bool realname = false;
+       bool positive = true;
 
        if (user->registered != REG_ALL)
                return false;
 
+       if (opt_mode)
+       {
+               for (const char* n = matchtext; *n; n++)
+               {
+                       if (*n == '+')
+                       {
+                               positive = true;
+                               continue;
+                       }
+                       else if (*n == '-')
+                       {
+                               positive = false;
+                               continue;
+                       }
+                       if (user->IsModeSet(*n) != positive)
+                               return false;
+               }
+               return true;
+       }
+
        if (opt_realname)
                realname = match(user->fullname, matchtext);
 
@@ -61,6 +82,19 @@ extern "C" command_t* init_command(InspIRCd* Instance)
        return new cmd_who(Instance);
 }
 
+bool cmd_who::CanView(chanrec* chan, userrec* user)
+{
+       /* Execute items in fastest-to-execute first order */
+       if (*user->oper)
+               return true;
+       else if (!chan->IsModeSet('s') && !chan->IsModeSet('p'))
+               return true;
+       else if (chan->HasUser(user))
+               return true;
+
+       return false;
+}
+
 CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
 {
        /*
@@ -75,6 +109,7 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
        bool opt_showrealhost = false;
        bool opt_unlimit = false;
        bool opt_realname = false;
+       bool opt_mode = false;
 
        chanrec *ch = NULL;
        std::vector<std::string> whoresults;
@@ -110,6 +145,9 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
                                case 'r':
                                        opt_realname = true;
                                break;
+                               case 'm':
+                                       opt_mode = true;
+                               break;
                        }
 
                        *iter++;
@@ -120,7 +158,7 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
        /* who on a channel? */
        ch = ServerInstance->FindChan(matchtext);
 
-       if (ch)
+       if ((ch) && (CanView(ch,user)))
        {
                /* who on a channel. */
                CUList *cu = ch->GetUsers();
@@ -168,7 +206,7 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
                        {
                                userrec* oper = *i;
 
-                               if (whomatch(oper, matchtext, opt_realname, opt_showrealhost))
+                               if (whomatch(oper, matchtext, opt_realname, opt_showrealhost, opt_mode))
                                {
                                        std::string wholine = initial;
        
@@ -202,7 +240,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))
+                               if (whomatch(i->second, matchtext, opt_realname, opt_showrealhost, opt_mode))
                                {
                                        std::string wholine = initial;