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"
22 #include "helperfuncs.h"
23 #include "commands/cmd_whois.h"
25 extern InspIRCd* ServerInstance;
29 const char* Spacify(char* n)
31 static char x[MAXBUF];
33 for (char* y = x; *y; y++)
39 void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long idle, const char* nick)
41 // bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
42 if (dest->registered == REG_ALL)
44 user->WriteServ("311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
45 if ((user == dest) || (*user->oper))
47 user->WriteServ("378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString());
49 std::string cl = dest->ChannelList(user);
52 if (cl.length() > 400)
54 user->SplitChanList(dest,cl);
58 user->WriteServ("319 %s %s :%s",user->nick, dest->nick, cl.c_str());
61 if (*ServerInstance->Config->HideWhoisServer && !(*user->oper))
63 user->WriteServ("312 %s %s %s :%s",user->nick, dest->nick, ServerInstance->Config->HideWhoisServer, ServerInstance->Config->Network);
67 user->WriteServ("312 %s %s %s :%s",user->nick, dest->nick, dest->server, ServerInstance->GetServerDescription(dest->server).c_str());
71 user->WriteServ("301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
75 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);
77 if ((!signon) && (!idle))
79 FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
81 if (!strcasecmp(user->server,dest->server))
83 // idle time and signon line can only be sent if youre on the same server (according to RFC)
84 user->WriteServ("317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon);
88 if ((idle) || (signon))
89 user->WriteServ("317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
91 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
95 user->WriteServ("401 %s %s :No such nick/channel",user->nick, nick);
96 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, nick);
100 void cmd_whois::Handle (const char** parameters, int pcnt, userrec *user)
103 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
106 dest = ServerInstance->FindNick(parameters[0]);
109 do_whois(user,dest,0,0,parameters[0]);
113 /* no such nick/channel */
114 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
115 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, parameters[0]);