]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_ison.cpp
Fix for bug #376 - FEATURE - (sorry w00t) - not backporting to stable.
[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                         if (u->Visibility && !u->Visibility->VisibleTo(user))
40                                 continue;
41
42                         reply.append(u->nick).append(" ");
43                         if (reply.length() > 450)
44                         {
45                                 user->WriteServ(reply);
46                                 reply = std::string("303 ") + user->nick + " :";
47                         }
48                         ison_already[u] = u;
49                 }
50                 else
51                 {
52                         if ((i == pcnt-1) && (strchr(parameters[i],' ')))
53                         {
54                                 /* Its a space seperated list of nicks (RFC1459 says to support this)
55                                  */
56                                 irc::spacesepstream list(parameters[i]);
57                                 std::string item;
58
59                                 while (list.GetToken(item))
60                                 {
61                                         u = ServerInstance->FindNick(item);
62                                         if (ison_already.find(u) != ison_already.end())
63                                                 continue;
64
65                                         if (u)
66                                         {
67                                                 if (u->Visibility && !u->Visibility->VisibleTo(user))
68                                                         continue;
69
70                                                 reply.append(u->nick).append(" ");
71                                                 if (reply.length() > 450)
72                                                 {
73                                                         user->WriteServ(reply);
74                                                         reply = std::string("303 ") + user->nick + " :";
75                                                 }
76                                                 ison_already[u] = u;
77                                         }
78                                 }
79                         }
80                 }
81         }
82
83         if (!reply.empty())
84                 user->WriteServ(reply);
85
86         return CMD_SUCCESS;
87 }
88