]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_whois.cpp
Created new class irc::commasepstream.
[user/henk/code/inspircd.git] / src / cmd_whois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "inspircd.h"
18 #include "message.h"
19 #include "configreader.h"
20 #include "users.h"
21 #include "modules.h"
22 #include "commands.h"
23 #include "helperfuncs.h"
24 #include "commands/cmd_whois.h"
25
26 extern ServerConfig* Config;
27 extern InspIRCd* ServerInstance;
28 extern int MODCOUNT;
29 extern ModuleList modules;
30 extern FactoryList factory;
31 extern time_t TIME;
32
33 const char* Spacify(char* n)
34 {
35         static char x[MAXBUF];
36         strlcpy(x,n,MAXBUF);
37         for (char* y = x; *y; y++)
38                 if (*y == '_')
39                         *y = ' ';
40         return x;
41 }
42
43 void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long idle, const char* nick)
44 {
45         // bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
46         if (dest->registered == 7)
47         {
48                 WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
49                 if ((user == dest) || (*user->oper))
50                 {
51                         WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, inet_ntoa(dest->ip4));
52                 }
53                 std::string cl = chlist(dest,user);
54                 if (cl.length())
55                 {
56                         if (cl.length() > 400)
57                         {
58                                 split_chlist(user,dest,cl);
59                         }
60                         else
61                         {
62                                 WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, cl.c_str());
63                         }
64                 }
65                 if (*Config->HideWhoisServer && !(*user->oper))
66                 {
67                         WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, Config->HideWhoisServer, Config->Network);
68                 }
69                 else
70                 {
71                         WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, dest->server, GetServerDescription(dest->server).c_str());
72                 }
73                 if (*dest->awaymsg)
74                 {
75                         WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
76                 }
77                 if (*dest->oper)
78                 {
79                         WriteServ(user->fd,"313 %s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),Spacify(dest->oper), Config->Network);
80                 }
81                 if ((!signon) && (!idle))
82                 {
83                         FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
84                 }
85                 if (!strcasecmp(user->server,dest->server))
86                 {
87                         // idle time and signon line can only be sent if youre on the same server (according to RFC)
88                         WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon);
89                 }
90                 else
91                 {
92                         if ((idle) || (signon))
93                                 WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
94                 }
95                 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
96         }
97         else
98         {
99                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, nick);
100                 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, nick);
101         }
102 }
103
104 void cmd_whois::Handle (const char** parameters, int pcnt, userrec *user)
105 {
106         userrec *dest;
107         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
108                 return;
109
110         dest = Find(parameters[0]);
111         if (dest)
112         {
113                 do_whois(user,dest,0,0,parameters[0]);
114         }
115         else
116         {
117                 /* no such nick/channel */
118                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
119                 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, parameters[0]);
120         }
121 }