]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/usercmds/whois.c
CHANSERV: Added various hooks to Q commands (mainly for achievement
[irc/quakenet/newserv.git] / chanserv / usercmds / whois.c
index aa71887b8c7ec6bb34204ad1cc5d4a9bf17f2b54..7726a00fc34d6126ee173d5d9fb1f6ef4b90f300 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "../chanserv.h"
 #include "../../lib/irc_string.h"
+#include "../../lib/strlfunc.h"
+#include "../../lib/ccassert.h"
 #include <stdio.h>
 #include <string.h>
 
@@ -23,13 +25,14 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
   reguser *rup=getreguserfromnick(sender), *target;
   char buf[200];
   char nbpos=0;
-  struct tm *tmp;
   regchanuser *rcup, *rcup2;
   flag_t flagmask, flags;
   int doneheader=0;
   authname *anp;
   nick *tnp;
 
+  CCASSERT(sizeof(buf) > TIMELEN);
+
   if (!(rup=getreguserfromnick(sender)))
     return CMD_ERROR;
   
@@ -63,6 +66,56 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
     flagmask=QUFLAG_ALL & ~(QUFLAG_SUSPENDED | QUFLAG_GLINE | QUFLAG_DELAYEDGLINE);
     if (UIsDev(rup))
       flagmask=QUFLAG_ALL;
+
+    if (UHasSuspension(target)) {
+      char expiresbuf[100];
+      char *reason, *suspendtype, *whom;
+
+      CCASSERT(sizeof(expiresbuf) > TIMELEN);
+
+      if(UIsDelayedGline(target)) {
+        suspendtype = "delayed gline";
+      } else if(UIsGline(target)) {
+        suspendtype = "gline";
+      } else if(UIsSuspended(target)) {
+        suspendtype = "suspended";
+      } else {
+        suspendtype = "???";
+      }
+
+      if(target->suspendexp) {
+        if(time(NULL) >= target->suspendexp) {
+          strlcpy(expiresbuf, "(next auth)", sizeof(expiresbuf));
+        } else {
+          q9strftime(expiresbuf, sizeof(expiresbuf), target->suspendexp);
+        }
+      } else {
+        strlcpy(expiresbuf, "(never)", sizeof(expiresbuf));
+      }
+
+      if(cs_privcheck(QPRIV_VIEWSUSPENDEDBY, sender)) {
+        reguser *trup = findreguserbyID(target->suspendby);
+        if(trup) {
+          whom = trup->username;
+        } else {
+          whom = "(unknown)";
+        }
+      } else {
+        whom = "(hidden)";
+      }
+
+      if(target->suspendreason && target->suspendreason->content) {
+        reason = target->suspendreason->content;
+      } else {
+        reason = "(none)";
+      }
+
+      chanservstdmessage(sender, QM_USERSUSPENDEDTYPE, suspendtype);
+      chanservstdmessage(sender, QM_USERSUSPENDEDBY, whom);
+      chanservstdmessage(sender, QM_USERSUSPENDEDREASON, reason);
+      chanservstdmessage(sender, QM_USERSUSPENDEDAT, target->suspendtime);
+      chanservstdmessage(sender, QM_USERSUSPENDEDEXPIRY, expiresbuf);
+    }
   } else {  
     /* Incidentally none of the QM_USERIS* mesages take parameters.  Just thought I'd mention it.. */
     if (UIsAdmin(target))
@@ -103,22 +156,19 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
     }
   }
 
-  if (target->created) {
-    tmp=gmtime(&(target->created));
-    strftime(buf,15,"%d/%m/%y %H:%M",tmp);
-    
-    chanservstdmessage(sender, QM_WHOIS_CREATED, buf);
-  }
+  if (target->created)
+    chanservstdmessage(sender, QM_WHOIS_CREATED, target->created);
 
   if (target->lastauth == 0) {
     snprintf(buf,sizeof(buf),"(never)");
   } else {
-    tmp=gmtime(&(target->lastauth));
-    strftime(buf,15,"%d/%m/%y %H:%M",tmp);
+    q9strftime(buf,sizeof(buf),target->lastauth);
   }
   chanservstdmessage(sender, QM_WHOIS_LASTAUTH, buf);
   
-  if (target->lastuserhost && (rup==target || cs_privcheck(QPRIV_VIEWFULLWHOIS, sender))) {
+  /* The third clause of this hides user@host of opers from non-opered staff. */
+  if (target->lastuserhost && (rup==target || cs_privcheck(QPRIV_VIEWFULLWHOIS, sender)) &&
+      (!UHasOperPriv(target) || UHasOperPriv(rup)) ) {
 /* Commenting out language until we implement some - splidge 
     chanservstdmessage(sender, QM_WHOIS_USERLANG, cslanguages[target->languageid] ?
                       cslanguages[target->languageid]->name->content : "(unknown)");  */
@@ -128,10 +178,10 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
   if (target->email && (rup==target || cs_privcheck(QPRIV_VIEWEMAIL, sender))) {
     chanservstdmessage(sender, QM_WHOIS_EMAIL, target->email->content);
 
-    tmp=gmtime(&(target->lastemailchange));
-    strftime(buf,15,"%d/%m/%y %H:%M",tmp);
-    
-    chanservstdmessage(sender, QM_WHOIS_EMAILSET, buf);    
+    if (target->lastemailchange)
+      chanservstdmessage(sender, QM_WHOIS_EMAILSET, target->lastemailchange);
+    if (target->lastpasschange)
+      chanservstdmessage(sender, QM_WHOIS_PASSSET, target->lastpasschange);
   }
 
   if (target->info && *target->info->content) {
@@ -173,8 +223,13 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
     chanservsendmessage(sender, " %-30s %s",rcup->chan->index->name->content,printflags(flags, rcuflags));
   }
 
-  if (doneheader)
-    chanservstdmessage(sender, QM_ENDOFLIST);
+  chanservstdmessage(sender, QM_ENDOFLIST);
+
+  if (rup==target) {
+    triggerhook(HOOK_CHANSERV_WHOAMI, sender);
+  } else {
+    triggerhook(HOOK_CHANSERV_WHOIS, sender);
+  }
 
   return CMD_OK;
 }