Cleanup code so it builds with C++ again
[ircu2.10.12-pk.git] / ircd / m_whois.c
index eb041e13af21ef89bcdd77816abcd16d204387c7..b817e3a26a6c79b48aedb2747ce64a35c37ede22 100644 (file)
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
 #include "channel.h"
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_features.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "match.h"
 /*
  * Send whois information for acptr to sptr
  */
-static void do_whois(struct Client* sptr, struct Client *acptr)
+static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
 {
   struct Client *a2cptr=0;
   struct Channel *chptr=0;
@@ -139,18 +134,18 @@ static void do_whois(struct Client* sptr, struct Client *acptr)
   int len;
   static char buf[512];
   
-  const struct User* user = acptr->user;
-  const char* name = (!*acptr->name) ? "?" : acptr->name;  
+  const struct User* user = cli_user(acptr);
+  const char* name = (!*(cli_name(acptr))) ? "?" : cli_name(acptr);  
   a2cptr = user->server;
   assert(user);
   send_reply(sptr, RPL_WHOISUSER, name, user->username, user->host,
-                  acptr->info);
+                  cli_info(acptr));
 
   /* Display the channels this user is on. */
   if (!IsChannelService(acptr))
   {
     struct Membership* chan;
-    mlen = strlen(me.name) + strlen(sptr->name) + 12 + strlen(name);
+    mlen = strlen(cli_name(&me)) + strlen(cli_name(sptr)) + 12 + strlen(name);
     len = 0;
     *buf = '\0';
     for (chan = user->channel; chan; chan = chan->next_channel)
@@ -187,23 +182,39 @@ static void do_whois(struct Client* sptr, struct Client *acptr)
      if (buf[0] != '\0')
         send_reply(sptr, RPL_WHOISCHANNELS, name, buf);
   }
-  send_reply(sptr, RPL_WHOISSERVER, name, a2cptr->name, a2cptr->info);
+
+  if (feature_bool(FEAT_HIS_WHOIS_SERVERNAME) && !IsAnOper(sptr) &&
+      sptr != acptr)
+    send_reply(sptr, RPL_WHOISSERVER, name, feature_str(FEAT_HIS_SERVERNAME),
+               feature_str(FEAT_HIS_SERVERINFO));
+  else
+    send_reply(sptr, RPL_WHOISSERVER, name, cli_name(a2cptr),
+              cli_info(a2cptr));
 
   if (user)
   {
     if (user->away)
        send_reply(sptr, RPL_AWAY, name, user->away);
 
-    if (IsAnOper(acptr))
+    if (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) ||
+                           HasPriv(sptr, PRIV_SEE_OPERS)))
        send_reply(sptr, RPL_WHOISOPERATOR, name);
-   
+
+    if (IsAccount(acptr))
+      send_reply(sptr, RPL_WHOISACCOUNT, name, user->account);
+
+    if (HasHiddenHost(acptr) && (IsAnOper(sptr) || acptr == sptr))
+      send_reply(sptr, RPL_WHOISACTUALLY, name, user->username,
+                 user->realhost, ircd_ntoa((const char*) &(cli_ip(acptr))));
+    
     /* Hint: if your looking to add more flags to a user, eg +h, here's
      *       probably a good place to add them :)
      */
      
-    if (MyConnect(acptr))
+    if (MyConnect(acptr) && (!feature_bool(FEAT_HIS_WHOIS_IDLETIME) ||
+                             (sptr == acptr || IsAnOper(sptr) || parc >= 3)))
        send_reply(sptr, RPL_WHOISIDLE, name, CurrentTime - user->last, 
-                  acptr->firsttime);
+                  cli_firsttime(acptr));
   }
 }
 
@@ -212,11 +223,11 @@ static void do_whois(struct Client* sptr, struct Client *acptr)
  * returns the number of people found (or, obviously, 0, if none where
  * found).
  */
-static int do_wilds(struct Client* sptr,char *nick,int count)
+static int do_wilds(struct Client* sptr, char *nick, int count, int parc)
 {
   struct Client *acptr; /* Current client we're concidering */
   struct User *user;   /* the user portion of the client */
-  char *name;          /* the name of this client */
+  const char *name;    /* the name of this client */
   struct Membership* chan; 
   int invis;           /* does +i apply? */
   int member;          /* Is this user on any channels? */
@@ -225,7 +236,7 @@ static int do_wilds(struct Client* sptr,char *nick,int count)
   
   /* Ech! This is hidious! */
   for (acptr = GlobalClientList; (acptr = next_client(acptr, nick));
-      acptr = acptr->next)
+      acptr = cli_next(acptr))
   {
     if (!IsRegistered(acptr)) 
       continue;
@@ -239,7 +250,7 @@ static int do_wilds(struct Client* sptr,char *nick,int count)
      *         hack?
      */
     if (IsMe(acptr)) {
-      assert(!acptr->next);
+      assert(!cli_next(acptr));
       break;
     }
     
@@ -253,8 +264,8 @@ static int do_wilds(struct Client* sptr,char *nick,int count)
      * - only send replies about common or public channels
      *   the target user(s) are on;
      */
-    user = acptr->user;
-    name = (!*acptr->name) ? "?" : acptr->name;
+    user = cli_user(acptr);
+    name = (!*(cli_name(acptr))) ? "?" : cli_name(acptr);
     assert(user);
 
     invis = (acptr != sptr) && IsInvisible(acptr);
@@ -264,7 +275,7 @@ static int do_wilds(struct Client* sptr,char *nick,int count)
     /* Should we show this person now? */
     if (showperson) {
        found++;
-       do_whois(sptr,acptr);
+       do_whois(sptr, acptr, parc);
        if (count+found>MAX_WHOIS_LINES)
          return found;
        continue;
@@ -306,7 +317,7 @@ static int do_wilds(struct Client* sptr,char *nick,int count)
     if (!showperson)
       continue;
       
-    do_whois(sptr,acptr);
+    do_whois(sptr, acptr, parc);
     found++;
     if (count+found>MAX_WHOIS_LINES)
        return found;  
@@ -342,17 +353,31 @@ int m_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   if (parc > 2)
   {
-    struct Client *acptr;
     /* For convenience: Accept a nickname as first parameter, by replacing
      * it with the correct servername - as is needed by hunt_server().
      * This is the secret behind the /whois nick nick trick.
      */
-    acptr = FindUser(parv[1]);
-    if (acptr)
-      parv[1] = acptr->user->server->name;
+    if (feature_int(FEAT_HIS_REMOTE))
+    {
+      /* If remote queries are disabled, then use the *second* parameter of
+       * of whois, so /whois nick nick still works.
+       */
+      if (!IsAnOper(sptr))
+      {
+        if (!FindUser(parv[2]))
+        {
+          send_reply(sptr, ERR_NOSUCHNICK, parv[2]);
+          send_reply(sptr, RPL_ENDOFWHOIS, parv[2]);
+          return 0;
+        }
+        parv[1] = parv[2];
+      }
+    }
+
     if (hunt_server_cmd(sptr, CMD_WHOIS, cptr, 0, "%C :%s", 1, parc, parv) !=
-        HUNTED_ISME)
-      return 0;
+       HUNTED_ISME)
+    return 0;
+    
     parv[1] = parv[2];
   }
 
@@ -370,12 +395,12 @@ int m_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       /* No wildcards */
       acptr = FindUser(nick);
       if (acptr && !IsServer(acptr)) {
-        do_whois(sptr,acptr);
+        do_whois(sptr, acptr, parc);
         found = 1;
       }
     }
     else /* wilds */
-       found=do_wilds(sptr,nick,total);
+       found=do_wilds(sptr, nick, total, parc);
 
     if (!found)
       send_reply(sptr, ERR_NOSUCHNICK, nick);
@@ -419,14 +444,6 @@ int ms_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   if (parc > 2)
   {
-    struct Client *acptr;
-    /* For convenience: Accept a nickname as first parameter, by replacing
-     * it with the correct servername - as is needed by hunt_server().
-     * This is the secret behind the /whois nick nick trick.
-     */
-    acptr = FindUser(parv[1]);
-    if (acptr)
-      parv[1] = acptr->user->server->name;
     if (hunt_server_cmd(sptr, CMD_WHOIS, cptr, 0, "%C :%s", 1, parc, parv) !=
         HUNTED_ISME)
       return 0;
@@ -447,7 +464,7 @@ int ms_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     acptr = FindUser(nick);
     if (acptr && !IsServer(acptr)) {
       found++;
-      do_whois(sptr,acptr);
+      do_whois(sptr, acptr, parc);
     }
 
     if (!found)
@@ -467,3 +484,4 @@ int ms_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   return 0;
 }
+