]> jfr.im git - irc/quakenet/newserv.git/blobdiff - nick/nickhandlers.c
Move TS code around a bit.
[irc/quakenet/newserv.git] / nick / nickhandlers.c
index 540979b3cb67e536fee9c068c2982c17a67851f3..8d78e8d7dd275ca628749423d6fad27d203277f3 100644 (file)
@@ -27,7 +27,10 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
   nick **nh;
   char *fakehost;
   char *accountts;
+  char *accountflags;
   struct irc_in_addr ipaddress;
+  char *accountid;
+  unsigned long userid;
   
   if (cargc==2) { /* rename */
     /* Nyklon 1017697578 */
@@ -136,31 +139,59 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     np->timestamp=timestamp;
 
     base64toip(cargv[cargc-3], &ipaddress);
-    /* todo: use a single node for /64 prefixes */
-    np->ipnode = refnode(iptree, &ipaddress, irc_in_addr_is_ipv4(&ipaddress) ? PATRICIA_MAXBITS : 64);
+    np->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS);
+    node_increment_usercount(np->ipnode);
 
     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->auth=NULL;
+    np->accountts=0;
     if(cargc>=9) {
+      int sethostarg = 6, opernamearg = 6, accountarg = 6;
+
       setflags(&(np->umodes),UMODE_ALL,cargv[5],umodeflags,REJECT_NONE);
+
+      if(IsOper(np) && (serverlist[myhub].flags & SMODE_OPERNAME)) {
+        accountarg++;
+        sethostarg++;
+
+        np->opername=getsstring(cargv[opernamearg],ACCOUNTLEN);
+      }
+
       if (IsAccount(np)) {
-        if ((accountts=strchr(cargv[6],':'))) {
+        sethostarg++;
+
+        if ((accountts=strchr(cargv[accountarg],':'))) {
+          time_t accountts_t=strtoul(accountts,&accountid,10)
           *accountts++='\0';
-          np->accountts=strtoul(accountts,NULL,10);
-        } else {
-          np->accountts=0;
+          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 {
+              np->auth=findorcreateauthname(userid, cargv[accountarg]);
+              np->auth->usercount++;
+              np->nextbyauthname=np->auth->nicks;
+              np->auth->nicks=np;
+              if(accountflags)
+                np->auth->flags=strtoul(accountflags + 1,NULL,10);
+            }
+          }
         }        
-        strncpy(np->authname,cargv[6],ACCOUNTLEN);
-        np->authname[ACCOUNTLEN]='\0';
       } 
-      if (IsSetHost(np) && (fakehost=strchr(cargv[cargc-4],'@'))) {
+      if (IsSetHost(np) && (fakehost=strchr(cargv[sethostarg],'@'))) {
        /* valid sethost */
        *fakehost++='\0';
-       np->shident=getsstring(cargv[cargc-4],USERLEN);
+       np->shident=getsstring(cargv[sethostarg],USERLEN);
        np->sethost=getsstring(fakehost,HOSTLEN);
       }
     }
@@ -193,8 +224,8 @@ int handlequitmsg(void *source, int cargc, char **cargv) {
   nick *np;
   void *harg[2];
   
-  if (cargc>1) {
-    harg[1]=(void *)cargv[1];
+  if (cargc>0) {
+    harg[1]=(void *)cargv[0];
   } else {
     harg[1]="";
   } 
@@ -261,13 +292,20 @@ int handleusermodemsg(void *source, int cargc, char **cargv) {
       return CMD_OK;
     }
     oldflags=np->umodes;
-    if (strchr(cargv[1],'o')) {
-      void *harg[2];
-        harg[0]=np;
-        harg[1]=cargv[1];
-        triggerhook(HOOK_NICK_MODEOPER,harg);
-    }
     setflags(&(np->umodes),UMODE_ALL,cargv[1],umodeflags,REJECT_NONE);
+
+    if (strchr(cargv[1],'o')) { /* o always comes on its own when being set */
+      if(serverlist[myhub].flags & SMODE_OPERNAME) {
+        if((np->umodes & UMODE_OPER)) {
+          np->opername = getsstring(cargv[2], ACCOUNTLEN);
+        } else {
+          freesstring(np->opername);
+          np->opername = NULL;
+        }
+      }
+      if((np->umodes ^ oldflags) & UMODE_OPER)
+        triggerhook(HOOK_NICK_MODEOPER,np);
+    }
     if (strchr(cargv[1],'h')) { /* Have to allow +h twice.. */
       /* +-h: just the freesstring() calls for the -h case */
       freesstring(np->shident); /* freesstring(NULL) is OK */
@@ -348,8 +386,11 @@ int handlewhoismsg(void *source, int cargc, char **cargv) {
 
 int handleaccountmsg(void *source, int cargc, char **cargv) {
   nick *target;
-  
-  if (cargc<2) {
+  unsigned long userid;
+  time_t accountts;
+  flag_t accountflags;
+
+  if (cargc<4) {
     return CMD_OK;
   }
   
@@ -357,13 +398,46 @@ int handleaccountmsg(void *source, int cargc, char **cargv) {
     return CMD_OK;
   }
   
+  accountts=strtoul(cargv[2],NULL,10);
+  userid=strtoul(cargv[3],NULL,10);
+  if(cargv>=5)
+    accountflags=strtoul(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)) {
+      return CMD_OK;
+    }
+
+    arg[0] = (void *)target->auth;
+    arg[1] = (void *)(long)target->auth->flags;
+    
+    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;
+  } 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=accountflags;
+  }
 
   triggerhook(HOOK_NICK_ACCOUNT, (void *)target);
 
@@ -420,3 +494,31 @@ int handlestatsmsg(void *source, int cargc, char **cargv) {
 
   return CMD_OK;
 }
+
+int handleprivmsg(void *source, int cargc, char **cargv) {
+  nick *sender;
+  char *message;
+  void *args[3];
+
+  if (cargc<2)
+    return CMD_OK;
+
+  if (cargv[0][0]!='$')
+    return CMD_OK;
+
+  sender=getnickbynumericstr((char *)source);
+
+  if (!match2strings(cargv[0] + 1,myserver->content))
+    return CMD_OK;
+
+  message=cargv[0];
+
+  args[0]=sender;
+  args[1]=cargv[0];
+  args[2]=cargv[1];
+
+  triggerhook(HOOK_NICK_MASKPRIVMSG, (void *)args);
+
+  return CMD_OK;
+}
+