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 * ---------------------------------------------------
18 #include "configreader.h"
21 #include "commands/cmd_whois.h"
23 const char* Spacify(char* n)
25 static char x[MAXBUF];
27 for (char* y = x; *y; y++)
33 void do_whois(InspIRCd* ServerInstance, userrec* user, userrec* dest,unsigned long signon, unsigned long idle, const 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 == REG_ALL)
38 user->WriteServ("311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
39 if ((user == dest) || (*user->oper))
41 user->WriteServ("378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString());
43 std::string cl = dest->ChannelList(user);
46 if (cl.length() > 400)
48 user->SplitChanList(dest,cl);
52 user->WriteServ("319 %s %s :%s",user->nick, dest->nick, cl.c_str());
55 if (*ServerInstance->Config->HideWhoisServer && !(*user->oper))
57 user->WriteServ("312 %s %s %s :%s",user->nick, dest->nick, ServerInstance->Config->HideWhoisServer, ServerInstance->Config->Network);
61 user->WriteServ("312 %s %s %s :%s",user->nick, dest->nick, dest->server, ServerInstance->GetServerDescription(dest->server).c_str());
65 user->WriteServ("301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
69 user->WriteServ("313 %s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),Spacify(dest->oper), ServerInstance->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 user->WriteServ("317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-ServerInstance->Time()), dest->signon);
82 if ((idle) || (signon))
83 user->WriteServ("317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
85 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
89 user->WriteServ("401 %s %s :No such nick/channel",user->nick, *nick ? nick : "*");
90 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, *nick ? nick : "*");
94 void cmd_whois::Handle (const char** parameters, int pcnt, userrec *user)
97 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
100 dest = ServerInstance->FindNick(parameters[0]);
103 do_whois(this->ServerInstance, user,dest,0,0,parameters[0]);
107 /* no such nick/channel */
108 user->WriteServ("401 %s %s :No such nick/channel",user->nick, *parameters[0] ? parameters[0] : "*");
109 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, *parameters[0] ? parameters[0] : "*");