1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "configreader.h"
23 #include "helperfuncs.h"
24 #include "commands/cmd_whois.h"
26 extern ServerConfig* Config;
27 extern InspIRCd* ServerInstance;
29 extern ModuleList modules;
30 extern FactoryList factory;
33 void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long idle, char* nick)
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)
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))
41 WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, inet_ntoa(dest->ip4));
43 std::string cl = chlist(dest,user);
46 if (cl.length() > 400)
48 split_chlist(user,dest,cl);
52 WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, cl.c_str());
55 if (*Config->HideWhoisServer && !(*user->oper))
57 WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, Config->HideWhoisServer, Config->Network);
61 WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, dest->server, GetServerDescription(dest->server).c_str());
65 WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
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);
71 if ((!signon) && (!idle))
73 FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
75 if (!strcasecmp(user->server,dest->server))
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);
82 if ((idle) || (signon))
83 WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
85 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
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);
94 void cmd_whois::Handle (char **parameters, int pcnt, userrec *user)
97 if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-1,0))
99 dest = Find(parameters[0]);
102 do_whois(user,dest,0,0,parameters[0]);
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]);