]> jfr.im git - irc/quakenet/newserv.git/blobdiff - nick/nickhandlers.c
NICK: Add "away" functionality.
[irc/quakenet/newserv.git] / nick / nickhandlers.c
index 8d78e8d7dd275ca628749423d6fad27d203277f3..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,13 +143,14 @@ 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) {
@@ -167,25 +169,25 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
         sethostarg++;
 
         if ((accountts=strchr(cargv[accountarg],':'))) {
-          time_t accountts_t=strtoul(accountts,&accountid,10)
+          userid=0;
           *accountts++='\0';
+          np->accountts=strtoul(accountts,&accountid,10);
           if(accountid) {
-            strncpy(np->authname,cargv[accountarg],ACCOUNTLEN);
-            np->authname[ACCOUNTLEN]='\0';
-            np->accountts=accountts_t;
-
             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);
             }
           }
+          if(!userid) {
+            np->authname=malloc(strlen(cargv[accountarg]) + 1);
+            strcpy(np->authname,cargv[accountarg]);
+          }
         }        
       } 
       if (IsSetHost(np) && (fakehost=strchr(cargv[sethostarg],'@'))) {
@@ -388,7 +390,7 @@ int handleaccountmsg(void *source, int cargc, char **cargv) {
   nick *target;
   unsigned long userid;
   time_t accountts;
-  flag_t accountflags;
+  u_int64_t accountflags=0, oldflags;
 
   if (cargc<4) {
     return CMD_OK;
@@ -400,39 +402,40 @@ int handleaccountmsg(void *source, int cargc, char **cargv) {
   
   accountts=strtoul(cargv[2],NULL,10);
   userid=strtoul(cargv[3],NULL,10);
-  if(cargv>=5)
-    accountflags=strtoul(cargv[4],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->authname,cargv[1]) || (target->auth->userid != userid) || (target->accountts != accountts)) {
+    if (!target->auth || strcmp(target->auth->name,cargv[1]) || (target->auth->userid != userid) || (target->accountts != accountts)) {
       return CMD_OK;
     }
 
-    arg[0] = (void *)target->auth;
-    arg[1] = (void *)(long)target->auth->flags;
+    oldflags = target->auth->flags;
+    arg[0] = target->auth;
+    arg[1] = &oldflags;
     
     if (cargc>=5)
       target->auth->flags=accountflags;
 
     triggerhook(HOOK_AUTH_FLAGSUPDATED, (void *)arg);
 
-    /* TODO: trigger flag update hook */
     return CMD_OK;
   }
   
   SetAccount(target);
-  strncpy(target->authname,cargv[1],ACCOUNTLEN);
-  target->authname[ACCOUNTLEN]='\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, target->authname);
+    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)
@@ -487,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]);
@@ -522,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;
+}