]> jfr.im git - irc/quakenet/newserv.git/blobdiff - nick/nickhandlers.c
Merge default into chanserv-live.
[irc/quakenet/newserv.git] / nick / nickhandlers.c
index dad8520c2528374e35a0e5174920ddbcff477b0d..6ab0d93d554be131863ffbbef9d457b987566f1d 100644 (file)
@@ -29,11 +29,14 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
   char *fakehost;
   char *accountts;
   char *accountflags;
-  struct irc_in_addr ipaddress;
+  struct irc_in_addr ipaddress, ipaddress_canonical;
   char *accountid;
   unsigned long userid;
   
   if (cargc==2) { /* rename */
+    char oldnick[NICKLEN+1];
+    void *harg[2];
+
     /* Nyklon 1017697578 */
     timestamp=strtol(cargv[1],NULL,10);
     np=getnickbynumericstr(sender);
@@ -41,6 +44,12 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
       Error("nick",ERR_ERROR,"Rename from non-existent sender %s",sender);
       return CMD_OK;
     }
+
+    strncpy(oldnick,np->nick,NICKLEN);
+    oldnick[NICKLEN]='\0';
+    harg[0]=(void *)np;
+    harg[1]=(void *)oldnick;
+
     np2=getnickbynick(cargv[0]);
     if (np==np2) {
       /* The new and old nickname have the same hash, this means a rename to the same name in 
@@ -53,7 +62,7 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
       }
       strncpy(np->nick,cargv[0],NICKLEN);
       np->nick[NICKLEN]='\0';
-      triggerhook(HOOK_NICK_RENAME,np);        
+      triggerhook(HOOK_NICK_RENAME,harg);
       return CMD_OK;
     }
     if (np2!=NULL) {
@@ -84,7 +93,7 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     strncpy(np->nick,cargv[0],NICKLEN);
     np->nick[NICKLEN]='\0';
     addnicktohash(np);
-    triggerhook(HOOK_NICK_RENAME,np);
+    triggerhook(HOOK_NICK_RENAME,harg);
   } else if (cargc>=8) { /* new nick */
     /* Jupiler 2 1016645147 ~Jupiler www.iglobal.be +ir moo [FUTURE CRAP HERE] DV74O] BNBd7 :Jupiler */
     timestamp=strtol(cargv[2],NULL,10);
@@ -119,10 +128,6 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     }
 
     base64toip(cargv[cargc-3], &ipaddress);
-    if (!irc_in_addr_valid(&ipaddress)) {
-      Error("nick",ERR_ERROR,"Received NICK with invalid ipaddress for %s from %s.",cargv[0],sender);
-      return CMD_ERROR;
-    }
 
     /* At this stage the nick is cleared to proceed */
     np=newnick();
@@ -139,8 +144,10 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     np->realname->nicks=np;
     np->timestamp=timestamp;
 
-    base64toip(cargv[cargc-3], &ipaddress);
-    np->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS);
+    memcpy(&(np->ipaddress), &ipaddress, sizeof(ipaddress));
+
+    ip_canonicalize_tunnel(&ipaddress_canonical, &ipaddress);
+    np->ipnode = refnode(iptree, &ipaddress_canonical, PATRICIA_MAXBITS);
     node_increment_usercount(np->ipnode);
 
     np->away=NULL;
@@ -153,6 +160,9 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     np->authname=NULLAUTHNAME;
     np->auth=NULL;
     np->accountts=0;
+    np->cloak_count = 0;
+    np->cloak_extra = NULL;
+    np->message = NULL;
     if(cargc>=9) {
       int sethostarg = 6, opernamearg = 6, accountarg = 6;
 
@@ -274,6 +284,7 @@ int handleusermodemsg(void *source, int cargc, char **cargv) {
   nick *np;
   flag_t oldflags;
   char *fakehost;
+  void *args[2];
   
   if (cargc<2) {
     Error("nick",ERR_WARNING,"Mode message with too few parameters");
@@ -296,6 +307,10 @@ int handleusermodemsg(void *source, int cargc, char **cargv) {
     oldflags=np->umodes;
     setflags(&(np->umodes),UMODE_ALL,cargv[1],umodeflags,REJECT_NONE);
 
+    args[0] = np;
+    args[1] = (void *)oldflags;
+    triggerhook(HOOK_NICK_MODECHANGE, args);
+
     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)) {
@@ -395,7 +410,6 @@ int handleaccountmsg(void *source, int cargc, char **cargv) {
 
 int handleprivmsg(void *source, int cargc, char **cargv) {
   nick *sender;
-  char *message;
   void *args[3];
 
   if (cargc<2)
@@ -409,8 +423,6 @@ int handleprivmsg(void *source, int cargc, char **cargv) {
   if (!match2strings(cargv[0] + 1,myserver->content))
     return CMD_OK;
 
-  message=cargv[0];
-
   args[0]=sender;
   args[1]=cargv[0];
   args[2]=cargv[1];
@@ -439,3 +451,37 @@ int handleawaymsg(void *source, int cargc, char **cargv) {
 
   return CMD_OK;
 }
+
+int handleaddcloak(void *source, int cargc, char **cargv) {
+  nick *sender, *target;
+
+  /* Check source is a valid user */
+  if (!(sender=getnickbynumericstr(source))) {
+    return CMD_OK;
+  }
+
+  if (cargc < 1)
+    return CMD_OK;
+
+  if (!(target=getnickbynumericstr(cargv[0]))) {
+    return CMD_OK;
+  }
+
+  addcloaktarget(sender, target);
+
+  return CMD_OK;
+}
+
+int handleclearcloak(void *source, int cargc, char **cargv) {
+  nick *sender;
+
+  /* Check source is a valid user */
+  if (!(sender=getnickbynumericstr(source))) {
+    return CMD_OK;
+  }
+
+  clearcloaktargets(sender);
+
+  return CMD_OK;
+}
+