]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/cmd_who.cpp
Add comments
[user/henk/code/inspircd.git] / src / cmd_who.cpp
index 39169b4ac4365e82fc32bf1b2b440a03152030fd..66a94cfd668bc6eec514e7dae82032624c287d76 100644 (file)
@@ -11,6 +11,7 @@
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include "configreader.h"
 #include "users.h"
 #include "modules.h"
@@ -44,6 +45,11 @@ bool cmd_who::whomatch(userrec* user, const char* matchtext)
        if (user->registered != REG_ALL)
                return false;
 
+       if (opt_local && !IS_LOCAL(user))
+               return false;
+       else if (opt_far && IS_LOCAL(user))
+               return false;
+
        if (opt_mode)
        {
                for (const char* n = matchtext; *n; n++)
@@ -83,7 +89,13 @@ bool cmd_who::whomatch(userrec* user, const char* matchtext)
                                        else
                                        {
                                                if (opt_port)
-                                                       port = (user->GetPort() == ConvToInt(matchtext));
+                                               {
+                                                       irc::portparser portrange(matchtext, false);
+                                                       long portno = -1;
+                                                       while ((portno = portrange.GetToken()))
+                                                               if (portno == user->GetPort())
+                                                                       port = true;
+                                               }
                                                else
                                                {
                                                        if (opt_away)
@@ -99,7 +111,7 @@ bool cmd_who::whomatch(userrec* user, const char* matchtext)
 
 
 
-extern "C" command_t* init_command(InspIRCd* Instance)
+extern "C" DllExport command_t* init_command(InspIRCd* Instance)
 {
        return new cmd_who(Instance);
 }
@@ -112,7 +124,7 @@ bool cmd_who::CanView(chanrec* chan, userrec* user)
        /* Execute items in fastest-to-execute first order */
 
        /* Opers see all */
-       if (*user->oper)
+       if (IS_OPER(user))
                return true;
        else if (!chan->IsModeSet('s') && !chan->IsModeSet('p'))
                return true;
@@ -132,11 +144,11 @@ void cmd_who::SendWhoLine(userrec* user, const std::string &initial, chanrec* ch
                return;
 
        std::string wholine =   initial + (ch ? ch->name : lcn) + " " + u->ident + " " + (opt_showrealhost ? u->host : u->dhost) + " " +
-                               ((*ServerInstance->Config->HideWhoisServer && !*user->oper) ? ServerInstance->Config->HideWhoisServer : u->server) +
+                               ((*ServerInstance->Config->HideWhoisServer && !IS_OPER(user)) ? ServerInstance->Config->HideWhoisServer : u->server) +
                                " " + u->nick + " ";
 
        /* away? */
-       if (*u->awaymsg)
+       if (IS_AWAY(u))
        {
                wholine.append("G");
        }
@@ -146,7 +158,7 @@ void cmd_who::SendWhoLine(userrec* user, const std::string &initial, chanrec* ch
        }
 
        /* oper? */
-       if (*u->oper)
+       if (IS_OPER(u))
        {
                wholine.append("*");
        }
@@ -174,6 +186,8 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
        opt_metadata = false;
        opt_port = false;
        opt_away = false;
+       opt_local = false;
+       opt_far = false;
 
        chanrec *ch = NULL;
        std::vector<std::string> whoresults;
@@ -199,11 +213,11 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
                                        opt_viewopersonly = true;
                                break;
                                case 'h':
-                                       if (*user->oper)
+                                       if (IS_OPER(user))
                                                opt_showrealhost = true;
                                break;
                                case 'u':
-                                       if (*user->oper)
+                                       if (IS_OPER(user))
                                                opt_unlimit = true;
                                break;
                                case 'r':
@@ -224,6 +238,12 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
                                case 'a':
                                        opt_away = true;
                                break;
+                               case 'l':
+                                       opt_local = true;
+                               break;
+                               case 'f':
+                                       opt_far = true;
+                               break;
                        }
 
                        *iter++;
@@ -246,14 +266,14 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
                        for (CUList::iterator i = cu->begin(); i != cu->end(); i++)
                        {
                                /* opers only, please */
-                               if (opt_viewopersonly && !*(i->second)->oper)
+                               if (opt_viewopersonly && !IS_OPER(i->first))
                                        continue;
        
                                /* If we're not inside the channel, hide +i users */
-                               if (i->second->IsModeSet('i') && !inside)
+                               if (i->first->IsModeSet('i') && !inside)
                                        continue;
        
-                               SendWhoLine(user, initial, ch, i->second, whoresults);
+                               SendWhoLine(user, initial, ch, i->first, whoresults);
                        }
                }
        }
@@ -270,8 +290,10 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
 
                                if (whomatch(oper, matchtext))
                                {
-                                       if (!oper->IsModeSet('i'))
-                                               SendWhoLine(user, initial, NULL, oper, whoresults);
+                                       if ((!oper->IsModeSet('i')) && (!IS_OPER(user)))
+                                               continue;
+
+                                       SendWhoLine(user, initial, NULL, oper, whoresults);
                                }
                        }
                }
@@ -281,8 +303,10 @@ CmdResult cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
                        {
                                if (whomatch(i->second, matchtext))
                                {
-                                       if (!i->second->IsModeSet('i'))
-                                               SendWhoLine(user, initial, NULL, i->second, whoresults);
+                                       if ((i->second->IsModeSet('i')) && (!IS_OPER(user)))
+                                               continue;
+
+                                       SendWhoLine(user, initial, NULL, i->second, whoresults);
                                }
                        }
                }