]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_whois.cpp
Change WriteChannelWithServ and it's _NoFormat to take a const char* servername rathe...
[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 void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long idle, const char* nick)
34 {
35         // bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
36         if (dest->registered == 7)
37         {
38                 WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
39                 if ((user == dest) || (*user->oper))
40                 {
41                         WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, inet_ntoa(dest->ip4));
42                 }
43                 std::string cl = chlist(dest,user);
44                 if (cl.length())
45                 {
46                         if (cl.length() > 400)
47                         {
48                                 split_chlist(user,dest,cl);
49                         }
50                         else
51                         {
52                                 WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, cl.c_str());
53                         }
54                 }
55                 if (*Config->HideWhoisServer && !(*user->oper))
56                 {
57                         WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, Config->HideWhoisServer, Config->Network);
58                 }
59                 else
60                 {
61                         WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, dest->server, GetServerDescription(dest->server).c_str());
62                 }
63                 if (*dest->awaymsg)
64                 {
65                         WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
66                 }
67                 if (*dest->oper)
68                 {
69                         WriteServ(user->fd,"313 %s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),dest->oper, Config->Network);
70                 }
71                 if ((!signon) && (!idle))
72                 {
73                         FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
74                 }
75                 if (!strcasecmp(user->server,dest->server))
76                 {
77                         // idle time and signon line can only be sent if youre on the same server (according to RFC)
78                         WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon);
79                 }
80                 else
81                 {
82                         if ((idle) || (signon))
83                                 WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
84                 }
85                 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
86         }
87         else
88         {
89                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, nick);
90                 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, nick);
91         }
92 }
93
94 void cmd_whois::Handle (char **parameters, int pcnt, userrec *user)
95 {
96         userrec *dest;
97         if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-1,0))
98                 return;
99         dest = Find(parameters[0]);
100         if (dest)
101         {
102                 do_whois(user,dest,0,0,parameters[0]);
103         }
104         else
105         {
106                 /* no such nick/channel */
107                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
108                 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, parameters[0]);
109         }
110 }