]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_ison.cpp
This needs some general QA-ing. Add support to new parser (introduced in 1.1) for...
[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 "users.h"
15 #include "inspircd.h"
16 #include "commands/cmd_ison.h"
17
18 extern "C" 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                                                 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                                 }
72                         }
73                         /* There will only be one of these, we can bail after. */
74                         break;
75                 }
76         }
77
78         if (!reply.empty())
79                 user->WriteServ(reply);
80
81         return CMD_SUCCESS;
82 }
83