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 const char* Spacify(char* n)
35 static char x[MAXBUF];
37 for (char* y = x; *y; y++)
43 void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long idle, const char* nick)
45 // bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
46 if (dest->registered == 7)
48 WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
49 if ((user == dest) || (*user->oper))
51 WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, inet_ntoa(dest->ip4));
53 std::string cl = chlist(dest,user);
56 if (cl.length() > 400)
58 split_chlist(user,dest,cl);
62 WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, cl.c_str());
65 if (*Config->HideWhoisServer && !(*user->oper))
67 WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, Config->HideWhoisServer, Config->Network);
71 WriteServ(user->fd,"312 %s %s %s :%s",user->nick, dest->nick, dest->server, GetServerDescription(dest->server).c_str());
75 WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
79 WriteServ(user->fd,"313 %s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),Spacify(dest->oper), Config->Network);
81 if ((!signon) && (!idle))
83 FOREACH_MOD(I_OnWhois,OnWhois(user,dest));
85 if (!strcasecmp(user->server,dest->server))
87 // idle time and signon line can only be sent if youre on the same server (according to RFC)
88 WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon);
92 if ((idle) || (signon))
93 WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
95 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
99 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, nick);
100 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, nick);
104 void cmd_whois::Handle (char **parameters, int pcnt, userrec *user)
107 if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-1,0))
109 dest = Find(parameters[0]);
112 do_whois(user,dest,0,0,parameters[0]);
116 /* no such nick/channel */
117 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
118 WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, parameters[0]);