]> jfr.im git - irc/quakenet/newserv.git/blobdiff - nick/nickhandlers.c
NICK: Add "away" functionality.
[irc/quakenet/newserv.git] / nick / nickhandlers.c
index 6ca637c9a26ce2eefb81a4eed142ca8aa6d0065d..282139f3070696df4583b82346e34c13b8a08265 100644 (file)
@@ -13,6 +13,7 @@
 #include "../parser/parser.h"
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 /*
  * handlenickmsg:
@@ -46,8 +47,8 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
        * different case, e.g. Flash -> flash.  In this case the timestamp for the change should
        * match the existing timestamp, and we can bypass all the collision checking and hash fettling. */
       if (np->timestamp!=timestamp) {
-        Error("nick",ERR_WARNING,"Rename to same nickname with different timestamp (%s(%d) -> %s(%d))",
-                            np->nick,np->timestamp,cargv[0],timestamp);
+        Error("nick",ERR_WARNING,"Rename to same nickname with different timestamp (%s(%jd) -> %s(%jd))",
+                            np->nick,(intmax_t)np->timestamp,cargv[0], (intmax_t)timestamp);
         np->timestamp=timestamp;
       }
       strncpy(np->nick,cargv[0],NICKLEN);
@@ -142,14 +143,16 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     np->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS);
     node_increment_usercount(np->ipnode);
 
+    np->away=NULL;
     np->shident=NULL;
     np->sethost=NULL;
     np->opername=NULL;
     np->umodes=0;
     np->marker=0;
     memset(np->exts, 0, MAXNICKEXTS * sizeof(void *));
-    np->authname[0]='\0';
+    np->authname=NULLAUTHNAME;
     np->auth=NULL;
+    np->accountts=0;
     if(cargc>=9) {
       int sethostarg = 6, opernamearg = 6, accountarg = 6;
 
@@ -166,29 +169,26 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
         sethostarg++;
 
         if ((accountts=strchr(cargv[accountarg],':'))) {
+          userid=0;
           *accountts++='\0';
           np->accountts=strtoul(accountts,&accountid,10);
           if(accountid) {
             userid=strtoul(accountid + 1,&accountflags,10);
-            if(!userid) {
-              np->auth=NULL;
-            } else {
+            if(userid) {
               np->auth=findorcreateauthname(userid, cargv[accountarg]);
+              np->authname=np->auth->name;
               np->auth->usercount++;
               np->nextbyauthname=np->auth->nicks;
               np->auth->nicks=np;
               if(accountflags)
-                np->auth->flags=strtoul(accountflags + 1,NULL,10);
+                np->auth->flags=strtoull(accountflags + 1,NULL,10);
             }
-          } else {
-            np->auth=NULL;
           }
-        } else {
-          np->accountts=0;
-          np->auth=NULL;
+          if(!userid) {
+            np->authname=malloc(strlen(cargv[accountarg]) + 1);
+            strcpy(np->authname,cargv[accountarg]);
+          }
         }        
-        strncpy(np->authname,cargv[accountarg],ACCOUNTLEN);
-        np->authname[ACCOUNTLEN]='\0';
       } 
       if (IsSetHost(np) && (fakehost=strchr(cargv[sethostarg],'@'))) {
        /* valid sethost */
@@ -302,6 +302,7 @@ int handleusermodemsg(void *source, int cargc, char **cargv) {
           np->opername = getsstring(cargv[2], ACCOUNTLEN);
         } else {
           freesstring(np->opername);
+          np->opername = NULL;
         }
       }
       if((np->umodes ^ oldflags) & UMODE_OPER)
@@ -388,8 +389,10 @@ int handlewhoismsg(void *source, int cargc, char **cargv) {
 int handleaccountmsg(void *source, int cargc, char **cargv) {
   nick *target;
   unsigned long userid;
-  
-  if (cargc<2) {
+  time_t accountts;
+  u_int64_t accountflags=0, oldflags;
+
+  if (cargc<4) {
     return CMD_OK;
   }
   
@@ -397,36 +400,48 @@ int handleaccountmsg(void *source, int cargc, char **cargv) {
     return CMD_OK;
   }
   
+  accountts=strtoul(cargv[2],NULL,10);
+  userid=strtoul(cargv[3],NULL,10);
+  if(cargc>=5)
+    accountflags=strtoull(cargv[4],NULL,10);
+
+  /* allow user flags to change if all fields match */
   if (IsAccount(target)) {
+    void *arg[2];
+
+    if (!target->auth || strcmp(target->auth->name,cargv[1]) || (target->auth->userid != userid) || (target->accountts != accountts)) {
+      return CMD_OK;
+    }
+
+    oldflags = target->auth->flags;
+    arg[0] = target->auth;
+    arg[1] = &oldflags;
+    
+    if (cargc>=5)
+      target->auth->flags=accountflags;
+
+    triggerhook(HOOK_AUTH_FLAGSUPDATED, (void *)arg);
+
     return CMD_OK;
   }
   
   SetAccount(target);
-  strncpy(target->authname,cargv[1],ACCOUNTLEN);
-  target->authname[ACCOUNTLEN]='\0';
-  
-  if (cargc>=3) {
-    target->accountts=strtoul(cargv[2],NULL,10);
-    if (cargc>=4) {
-      userid=strtoul(cargv[3],NULL,10);
-      if(!userid) {
-        target->auth=NULL;
-      } else {
-        target->auth=findorcreateauthname(userid, target->authname);
-        target->auth->usercount++;
-        target->nextbyauthname = target->auth->nicks;
-        target->auth->nicks = target;
-        if (cargc>=5)
-          target->auth->flags=strtoul(cargv[4],NULL,10);
-      }
-    } else {
-      target->auth=NULL;
-    }
-  } else {
-    target->accountts=0;
+  target->accountts=accountts;
+
+  if(!userid) {
     target->auth=NULL;
+    target->authname=malloc(strlen(cargv[1]) + 1);
+    strcpy(target->authname,cargv[1]);
+  } else {
+    target->auth=findorcreateauthname(userid, cargv[1]);
+    target->auth->usercount++;
+    target->authname=target->auth->name;
+    target->nextbyauthname = target->auth->nicks;
+    target->auth->nicks = target;
+    if (cargc>=5)
+      target->auth->flags=accountflags;
   }
-  
+
   triggerhook(HOOK_NICK_ACCOUNT, (void *)target);
 
   return CMD_OK;
@@ -475,7 +490,10 @@ int handlestatsmsg(void *source, int cargc, char **cargv) {
   case 'P':
     irc_send(":%s 217 %s P none 0 :0x2000",fromstring,replytarget);
     break;
-    
+   
+  case 'm':
+    stats_m(fromstring, replytarget);
+    break; 
   }
 
   irc_send(":%s 219 %s %c :End of /STATS report",fromstring,replytarget,cargv[0][0]);
@@ -510,3 +528,22 @@ int handleprivmsg(void *source, int cargc, char **cargv) {
   return CMD_OK;
 }
 
+int handleawaymsg(void *source, int cargc, char **cargv) {
+  nick *sender;
+    
+  /* Check source is a valid user */ 
+  if (!(sender=getnickbynumericstr(source))) {
+    return CMD_OK;
+  }
+
+  /* Done with the old away message either way */
+  freesstring(sender->away);
+  sender->away=NULL;
+  
+  /* If we have an arg and it isn't an empty string, this sets a new message */
+  if (cargc > 0 && *(cargv[0])) {
+    sender->away=getsstring(cargv[0], AWAYLEN);
+  }
+
+  return CMD_OK;
+}