]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_ison.cpp
Make User:: nick/ident/dhost/fullname and some other things std::string instead of...
[user/henk/code/inspircd.git] / src / commands / cmd_ison.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "commands/cmd_ison.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandIson(Instance);
20 }
21
22 /** Handle /ISON
23  */
24 CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         std::map<User*,User*> ison_already;
27         User *u;
28         std::string reply = std::string("303 ") + user->nick + " :";
29
30         for (unsigned int i = 0; i < parameters.size(); i++)
31         {
32                 u = ServerInstance->FindNick(parameters[i]);
33                 if (ison_already.find(u) != ison_already.end())
34                         continue;
35
36                 if (u)
37                 {
38                         if (u->Visibility && !u->Visibility->VisibleTo(user))
39                                 continue;
40
41                         reply.append(u->nick).append(" ");
42                         if (reply.length() > 450)
43                         {
44                                 user->WriteServ(reply);
45                                 reply = std::string("303 ") + user->nick + " :";
46                         }
47                         ison_already[u] = u;
48                 }
49                 else
50                 {
51                         if ((i == parameters.size() - 1) && (parameters[i].find(' ') != std::string::npos))
52                         {
53                                 /* Its a space seperated list of nicks (RFC1459 says to support this)
54                                  */
55                                 irc::spacesepstream list(parameters[i]);
56                                 std::string item;
57
58                                 while (list.GetToken(item))
59                                 {
60                                         u = ServerInstance->FindNick(item);
61                                         if (ison_already.find(u) != ison_already.end())
62                                                 continue;
63
64                                         if (u)
65                                         {
66                                                 if (u->Visibility && !u->Visibility->VisibleTo(user))
67                                                         continue;
68
69                                                 reply.append(u->nick).append(" ");
70                                                 if (reply.length() > 450)
71                                                 {
72                                                         user->WriteServ(reply);
73                                                         reply = std::string("303 ") + user->nick + " :";
74                                                 }
75                                                 ison_already[u] = u;
76                                         }
77                                 }
78                         }
79                 }
80         }
81
82         if (!reply.empty())
83                 user->WriteServ(reply);
84
85         return CMD_SUCCESS;
86 }
87