]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_who.cpp
m_dccallow Add config option to control max entries on a list
[user/henk/code/inspircd.git] / src / commands / cmd_who.cpp
index 6aac6eeea2cb451a1e3139b7e3b1ea9ecff24ec1..90c26a974d4b8c3676fe5b23f673b6753b5f8acf 100644 (file)
@@ -1,16 +1,23 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
  *
- * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 
 /** Handle /WHO. These command handlers can be reloaded by the core,
@@ -39,7 +46,7 @@ class CommandWho : public Command
        CommandWho ( Module* parent) : Command(parent,"WHO", 1) {
                syntax = "<server>|<nickname>|<channel>|<realname>|<host>|0 [ohurmMiaplf]";
        }
-       void SendWhoLine(User* user, const std::string &initial, Channel* ch, User* u, std::vector<std::string> &whoresults);
+       void SendWhoLine(User* user, const std::vector<std::string>& parms, const std::string &initial, Channel* ch, User* u, std::vector<std::string> &whoresults);
        /** Handle command.
         * @param parameters The parameters to the comamnd
         * @param pcnt The number of parameters passed to teh command
@@ -51,19 +58,16 @@ class CommandWho : public Command
 };
 
 
-static const std::string star = "*";
-
-static const std::string& get_first_visible_channel(User *u)
+static Channel* get_first_visible_channel(User *u)
 {
        UCListIter i = u->chans.begin();
        while (i != u->chans.end())
        {
                Channel* c = *i++;
                if (!c->IsModeSet('s'))
-                       return c->name;
+                       return c;
        }
-
-       return star;
+       return NULL;
 }
 
 bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
@@ -137,7 +141,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
                        long seconds = ServerInstance->Duration(matchtext);
 
                        // Okay, so time matching, we want all users connected `seconds' ago
-                       if (user->age >= ServerInstance->Time() - seconds)
+                       if (user->signon >= ServerInstance->Time() - seconds)
                                match = true;
                }
 
@@ -162,8 +166,6 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
        }
 }
 
-
-
 bool CommandWho::CanView(Channel* chan, User* user)
 {
        if (!user || !chan)
@@ -184,14 +186,19 @@ bool CommandWho::CanView(Channel* chan, User* user)
        return false;
 }
 
-void CommandWho::SendWhoLine(User* user, const std::string &initial, Channel* ch, User* u, std::vector<std::string> &whoresults)
+void CommandWho::SendWhoLine(User* user, const std::vector<std::string>& parms, const std::string &initial, Channel* ch, User* u, std::vector<std::string> &whoresults)
 {
-       const std::string& lcn = get_first_visible_channel(u);
-       Channel* chlast = ServerInstance->FindChan(lcn);
+       if (!ch)
+               ch = get_first_visible_channel(u);
 
-       std::string wholine =   initial + (ch ? ch->name : lcn) + " " + u->ident + " " + (opt_showrealhost ? u->host : u->dhost) + " " +
-                               ((!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")) ? ServerInstance->Config->HideWhoisServer : u->server) +
-                               " " + u->nick + " ";
+       std::string wholine = initial + (ch ? ch->name : "*") + " " + u->ident + " " +
+               (opt_showrealhost ? u->host : u->dhost) + " ";
+       if (!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex"))
+               wholine.append(ServerInstance->Config->HideWhoisServer);
+       else
+               wholine.append(u->server);
+       
+       wholine.append(" " + u->nick + " ");
 
        /* away? */
        if (IS_AWAY(u))
@@ -206,12 +213,15 @@ void CommandWho::SendWhoLine(User* user, const std::string &initial, Channel* ch
        /* oper? */
        if (IS_OPER(u))
        {
-               wholine.append("*");
+               wholine.push_back('*');
        }
 
-       wholine = wholine + (ch ? ch->GetPrefixChar(u) : (chlast ? chlast->GetPrefixChar(u) : "")) + " :0 " + u->fullname;
+       if (ch)
+               wholine.append(ch->GetPrefixChar(u));
+
+       wholine.append(" :0 " + u->fullname);
 
-       FOREACH_MOD(I_OnSendWhoLine, OnSendWhoLine(user, u, ch, wholine));
+       FOREACH_MOD(I_OnSendWhoLine, OnSendWhoLine(user, parms, u, wholine));
 
        if (!wholine.empty())
                whoresults.push_back(wholine);
@@ -241,7 +251,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
 
        Channel *ch = NULL;
        std::vector<std::string> whoresults;
-       std::string initial = "352 " + std::string(user->nick) + " ";
+       std::string initial = "352 " + user->nick + " ";
 
        char matchtext[MAXBUF];
        bool usingwildcards = false;
@@ -254,7 +264,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
 
        for (const char* check = matchtext; *check; check++)
        {
-               if (*check == '*' || *check == '?')
+               if (*check == '*' || *check == '?' || *check == '.')
                {
                        usingwildcards = true;
                        break;
@@ -340,7 +350,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                                continue;
                                }
 
-                               SendWhoLine(user, initial, ch, i->first, whoresults);
+                               SendWhoLine(user, parameters, initial, ch, i->first, whoresults);
                        }
                }
        }
@@ -358,11 +368,11 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                {
                                        if (!user->SharesChannelWith(oper))
                                        {
-                                               if (usingwildcards && (!oper->IsModeSet('i')) && (!user->HasPrivPermission("users/auspex")))
+                                               if (usingwildcards && (oper->IsModeSet('i')) && (!user->HasPrivPermission("users/auspex")))
                                                        continue;
                                        }
 
-                                       SendWhoLine(user, initial, NULL, oper, whoresults);
+                                       SendWhoLine(user, parameters, initial, NULL, oper, whoresults);
                                }
                        }
                }
@@ -378,7 +388,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                                        continue;
                                        }
 
-                                       SendWhoLine(user, initial, NULL, i->second, whoresults);
+                                       SendWhoLine(user, parameters, initial, NULL, i->second, whoresults);
                                }
                        }
                }