]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_ison.cpp
Attempt to revert r11734
[user/henk/code/inspircd.git] / src / commands / cmd_ison.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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
16 #ifndef __CMD_ISON_H__
17 #define __CMD_ISON_H__
18
19 // include the common header files
20
21 #include "users.h"
22 #include "channels.h"
23
24 /** Handle /ISON. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandIson : public Command
30 {
31  public:
32         /** Constructor for ison.
33          */
34         CommandIson ( Module* parent) : Command(parent,"ISON",0,0) { syntax = "<nick> {nick}"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
42 };
43
44 #endif
45
46
47 /** Handle /ISON
48  */
49 CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User *user)
50 {
51         std::map<User*,User*> ison_already;
52         User *u;
53         std::string reply = std::string("303 ") + user->nick + " :";
54
55         for (unsigned int i = 0; i < parameters.size(); i++)
56         {
57                 u = ServerInstance->FindNick(parameters[i]);
58                 if (ison_already.find(u) != ison_already.end())
59                         continue;
60
61                 if (u)
62                 {
63                         reply.append(u->nick).append(" ");
64                         if (reply.length() > 450)
65                         {
66                                 user->WriteServ(reply);
67                                 reply = std::string("303 ") + user->nick + " :";
68                         }
69                         ison_already[u] = u;
70                 }
71                 else
72                 {
73                         if ((i == parameters.size() - 1) && (parameters[i].find(' ') != std::string::npos))
74                         {
75                                 /* Its a space seperated list of nicks (RFC1459 says to support this)
76                                  */
77                                 irc::spacesepstream list(parameters[i]);
78                                 std::string item;
79
80                                 while (list.GetToken(item))
81                                 {
82                                         u = ServerInstance->FindNick(item);
83                                         if (ison_already.find(u) != ison_already.end())
84                                                 continue;
85
86                                         if (u)
87                                         {
88                                                 reply.append(u->nick).append(" ");
89                                                 if (reply.length() > 450)
90                                                 {
91                                                         user->WriteServ(reply);
92                                                         reply = std::string("303 ") + user->nick + " :";
93                                                 }
94                                                 ison_already[u] = u;
95                                         }
96                                 }
97                         }
98                 }
99         }
100
101         if (!reply.empty())
102                 user->WriteServ(reply);
103
104         return CMD_SUCCESS;
105 }
106
107
108 COMMAND_INIT(CommandIson)