1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "configreader.h"
18 #include "commands/cmd_whois.h"
21 void do_whois(InspIRCd* ServerInstance, userrec* user, userrec* dest,unsigned long signon, unsigned long idle, const char* nick)
23 // bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
24 if (dest->registered == REG_ALL)
26 ServerInstance->SendWhoisLine(user, dest, 311, "%s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
27 if ((user == dest) || (*user->oper))
29 ServerInstance->SendWhoisLine(user, dest, 378, "%s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString());
31 std::string cl = dest->ChannelList(user);
34 if (cl.length() > 400)
36 user->SplitChanList(dest,cl);
40 ServerInstance->SendWhoisLine(user, dest, 319, "%s %s :%s",user->nick, dest->nick, cl.c_str());
43 if (*ServerInstance->Config->HideWhoisServer && !(*user->oper))
45 ServerInstance->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick, dest->nick, ServerInstance->Config->HideWhoisServer, ServerInstance->Config->Network);
49 ServerInstance->SendWhoisLine(user, dest, 312, "%s %s %s :%s",user->nick, dest->nick, dest->server, ServerInstance->GetServerDescription(dest->server).c_str());
53 ServerInstance->SendWhoisLine(user, dest, 301, "%s %s :%s",user->nick, dest->nick, dest->awaymsg);
57 ServerInstance->SendWhoisLine(user, dest, 313, "%s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),irc::Spacify(dest->oper), ServerInstance->Config->Network);
59 if ((!signon) && (!idle))
61 FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
63 if (!strcasecmp(user->server,dest->server))
65 // idle time and signon line can only be sent if youre on the same server (according to RFC)
66 ServerInstance->SendWhoisLine(user, dest, 317, "%s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-ServerInstance->Time()), dest->signon);
70 if ((idle) || (signon))
71 ServerInstance->SendWhoisLine(user, dest, 317, "%s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
73 ServerInstance->SendWhoisLine(user, dest, 318, "%s %s :End of /WHOIS list.",user->nick, dest->nick);
77 ServerInstance->SendWhoisLine(user, dest, 401, "%s %s :No such nick/channel",user->nick, *nick ? nick : "*");
78 ServerInstance->SendWhoisLine(user, dest, 318, "%s %s :End of /WHOIS list.",user->nick, *nick ? nick : "*");
84 extern "C" command_t* init_command(InspIRCd* Instance)
86 return new cmd_whois(Instance);
89 CmdResult cmd_whois::Handle (const char** parameters, int pcnt, userrec *user)
92 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
95 dest = ServerInstance->FindNick(parameters[0]);
98 do_whois(this->ServerInstance, user,dest,0,0,parameters[0]);
102 /* no such nick/channel */
103 user->WriteServ("401 %s %s :No such nick/channel",user->nick, *parameters[0] ? parameters[0] : "*");
104 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, *parameters[0] ? parameters[0] : "*");