]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/cmd_who.cpp
Jesus, look who's the commit whore today. More header updates, and removal of namespa...
[user/henk/code/inspircd.git] / src / cmd_who.cpp
index 81145a91c13659d9305393eff20df1f5c7f6e100..bd9457d6f01fa77bba4786b25082d7dd272f3947 100644 (file)
@@ -1,15 +1,12 @@
-/*   +------------------------------------+
- *   | Inspire Internet Relay Chat Daemon |
- *   +------------------------------------+
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *   E-mail:
- *<brain@chatspike.net>
- *<Craig@chatspike.net>
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
  *
- * Written by Craig Edwards, Craig McLure, and others.
  * This program is free but copyrighted software; see
- *the file COPYING for details.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 /* get the last 'visible' chan of a user */
 static char *getlastchanname(userrec *u)
 {
-       for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
+       UCListIter i = u->chans.begin();
+       if (i != u->chans.end())
        {
-               ucrec* temp = (ucrec*)*v;
-
-               if (temp->channel)
-               {
-                       if (!temp->channel->IsModeSet('s'))
-                               return temp->channel->name;
-               }
+               if (!i->first->IsModeSet('s'))
+                       return i->first->name;
        }
 
        return "*";
@@ -82,6 +75,22 @@ extern "C" command_t* init_command(InspIRCd* Instance)
        return new cmd_who(Instance);
 }
 
+bool cmd_who::CanView(chanrec* chan, userrec* user)
+{
+       if (!user || !chan)
+               return false;
+
+       /* 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)
 {
        /*
@@ -145,7 +154,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();