]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_ison.cpp
Add comments
[user/henk/code/inspircd.git] / src / cmd_ison.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "users.h"
16 #include "commands/cmd_ison.h"
17
18 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
19 {
20         return new cmd_ison(Instance);
21 }
22
23 /** Handle /ISON
24  */
25 CmdResult cmd_ison::Handle (const char** parameters, int pcnt, userrec *user)
26 {
27         std::map<userrec*,userrec*> ison_already;
28         userrec *u;
29         std::string reply = std::string("303 ") + user->nick + " :";
30
31         for (int i = 0; i < pcnt; i++)
32         {
33                 u = ServerInstance->FindNick(parameters[i]);
34                 if (ison_already.find(u) != ison_already.end())
35                         continue;
36
37                 if (u)
38                 {
39                         reply.append(u->nick).append(" ");
40                         if (reply.length() > 450)
41                         {
42                                 user->WriteServ(reply);
43                                 reply = std::string("303 ") + user->nick + " :";
44                         }
45                         ison_already[u] = u;
46                 }
47                 else
48                 {
49                         if ((i == pcnt-1) && (strchr(parameters[i],' ')))
50                         {
51                                 /* Its a space seperated list of nicks (RFC1459 says to support this)
52                                  */
53                                 irc::spacesepstream list(parameters[i]);
54                                 std::string item = "*";
55                                 while (((item = list.GetToken()) != ""))
56                                 {
57                                         u = ServerInstance->FindNick(item);
58                                         if (ison_already.find(u) != ison_already.end())
59                                                 continue;
60
61                                         if (u)
62                                         {
63                                                 if (u->Visibility && !u->Visibility->VisibleTo(user))
64                                                         continue;
65
66                                                 reply.append(u->nick).append(" ");
67                                                 if (reply.length() > 450)
68                                                 {
69                                                         user->WriteServ(reply);
70                                                         reply = std::string("303 ") + user->nick + " :";
71                                                 }
72                                                 ison_already[u] = u;
73                                         }
74                                 }
75                         }
76                         /* There will only be one of these, we can bail after. */
77                         break;
78                 }
79         }
80
81         if (!reply.empty())
82                 user->WriteServ(reply);
83
84         return CMD_SUCCESS;
85 }
86