Kaynağa Gözat

* Recoded some of cmd_chaddr
Still need to rewrite botaddr_unpack in userent.c


svn: 768

Bryan Drewery 22 yıl önce
ebeveyn
işleme
f0a57148dd
2 değiştirilmiş dosya ile 23 ekleme ve 27 silme
  1. 2 0
      doc/UPDATES
  2. 21 27
      src/cmds.c

+ 2 - 0
doc/UPDATES

@@ -7,6 +7,8 @@ This is a summary of ChangeLog basically.
 4.Remote idx's now set their socket to -1 (shouldnt cause any problems)
 5.Removed 'ppid: ' from startup.
 6.Fixed colors being shown even if .color was set to OFF.
+7.Fixed a segfault in cmd_chaddr (ipv6 ips still not supported)
+8.Changed format for ADDRESS display again.
 
 1.1.1
 1.Fixed a problem with using /DCC CHAT <bot>

+ 21 - 27
src/cmds.c

@@ -759,7 +759,7 @@ static void cmd_nohelp(struct userrec *u, int idx, char *par)
   int i;
   char *buf = NULL;
 
-  buf = malloc(1);
+  buf = calloc(1, 1);
 
   qsort(cmdlist, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
   
@@ -1693,38 +1693,35 @@ static void cmd_chaddr(struct userrec *u, int idx, char *par)
   bi->hublevel = obi->hublevel;
 
   q = strchr(addr, ':');
+
+  /* no port */
   if (!q) {
     bi->address = strdup(addr);
     bi->telnet_port = telnet_port;
     bi->relay_port = relay_port;
+
+  /* with a port, or ipv6 ip */
   } else {
 #ifdef USE_IPV6
-    r = strchr(addr, '[');
-    if (r) { /* ipv6 notation [3ffe:80c0:225::] */
-      *addr++;
-      r = strchr(addr, ']');
-      bi->address = calloc(1, r - addr + 1);
-      strcpy(bi->address, addr);
-      addr = r;
-      *addr++;
+    if ((r = strchr(addr, '['))) {		/* ipv6 notation [3ffe:80c0:225::] */
+      addr++;					/* lose the '[' */
+      r = strchr(addr, ']');			/* pointer to the ending ']' */
+
+      bi->address = calloc(1, r - addr + 1);	/* alloc and copy the addr */
+      strncpyz(bi->address, addr, r - addr + 1);
+
+//      addr = r;					/* move up addr to the ']' */
+//      addr++;					/* move up addr tot he ':' */
+      q = r + 1;				/* set q to ':' at addr */
     } else {
+#endif /* !USE_IPV6 */
       bi->address = calloc(1, q - addr + 1);
-      strcpy(bi->address, addr);
-    }
-    q = strchr(addr, ':');
-    if (q) {
-      p = q + 1;
-      bi->telnet_port = atoi(p);
-      q = strchr(p, '/');
-      if (!q) {
-        bi->relay_port = telnet_port;
-      } else {
-        bi->relay_port = atoi(q + 1);
-      }
+      strncpyz(bi->address, addr, q - addr + 1);
+#ifdef USE_IPV6
     }
-#else /* !USE_IPV6 */
-    bi->address = calloc(1, q - addr + 1);
-    strncpyz(bi->address, addr, q - addr + 1);
+#endif /* USE_IPV6 */
+
+    /* port */
     p = q + 1;
     bi->telnet_port = atoi(p);
     q = strchr(p, '/');
@@ -1732,12 +1729,9 @@ static void cmd_chaddr(struct userrec *u, int idx, char *par)
       bi->relay_port = bi->telnet_port;
     else
       bi->relay_port = atoi(q + 1);
-#endif /* USE_IPV6 */
   }
   set_user(&USERENTRY_BOTADDR, u1, bi);
-#ifdef HUB
   write_userfile(idx);
-#endif /* HUB */
 }
 #endif /* HUB */