Просмотр исходного кода

* All dcc loops need to check for dcc[].type, as the table will now have gaps...

svn: 1460
Bryan Drewery 21 лет назад
Родитель
Сommit
ccb2750d36

+ 12 - 10
src/botcmd.c

@@ -372,7 +372,7 @@ static void remote_tell_who(int idx, char *nick, int chan)
 		       MISC_OWNER, MISC_MASTER, MISC_OP);
   }
   for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type->flags & DCT_REMOTEWHO)
+    if (dcc[i].type && dcc[i].type->flags & DCT_REMOTEWHO) {
       if (dcc[i].u.chat->channel == chan) {
 	k = sprintf(s, "  %c%-15s %s", (geticon(i) == '-' ? ' ' : geticon(i)),
 		    dcc[i].nick, dcc[i].host);
@@ -393,9 +393,10 @@ static void remote_tell_who(int idx, char *nick, int chan)
 	if (dcc[i].u.chat->away != NULL)
 	  botnet_send_priv(idx, conf.bot->nick, nick, NULL, "      %s: %s", MISC_AWAY, dcc[i].u.chat->away);
       }
+    }
   }
   for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_BOT) {
+    if (dcc[i].type && dcc[i].type == &DCC_BOT) {
       if (!ok) {
 	ok = 1;
 	botnet_send_priv(idx, conf.bot->nick, nick, NULL, "%s:", BOT_BOTSCONNECTED);
@@ -409,7 +410,7 @@ static void remote_tell_who(int idx, char *nick, int chan)
   }
   ok = 0;
   for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type->flags & DCT_REMOTEWHO) {
+    if (dcc[i].type && dcc[i].type->flags & DCT_REMOTEWHO) {
       if (dcc[i].u.chat->channel != chan) {
 	if (!ok) {
 	  ok = 1;
@@ -739,10 +740,9 @@ static void bot_traced(int idx, char *par)
       else
 	p2 = par + 1;
     }
-    for (i = 0; i < dcc_total; i++)
-      if ((dcc[i].type->flags & DCT_CHAT) &&
-	  (!egg_strcasecmp(dcc[i].nick, to)) &&
-	  ((sock == (-1)) || (sock == dcc[i].sock))) {
+    for (i = 0; i < dcc_total; i++) {
+      if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) && (!egg_strcasecmp(dcc[i].nick, to)) && 
+          ((sock == (-1)) || (sock == dcc[i].sock))) {
 	if (t) {
           int j=0;
           {
@@ -754,6 +754,7 @@ static void bot_traced(int idx, char *par)
 	} else
 	  dprintf(i, "%s -> %s\n", BOT_TRACERESULT, p);
       }
+    }
   } else {
     i = nextbot(p);
     if (p != to)
@@ -822,8 +823,8 @@ static void bot_reject(int idx, char *par)
       /* Kick someone here! */
       int ok = 0;
 
-      for (i = 0; (i < dcc_total) && (!ok); i++)
-	if ((!egg_strcasecmp(who, dcc[i].nick)) && (dcc[i].type->flags & DCT_CHAT)) {
+      for (i = 0; (i < dcc_total) && (!ok); i++) {
+	if (dcc[i].type && (!egg_strcasecmp(who, dcc[i].nick)) && (dcc[i].type->flags & DCT_CHAT)) {
 	  u = get_user_by_handle(userlist, dcc[i].nick);
 	  if (u && ((u->flags & USER_OWNER) && !(dcc[idx].user->flags & USER_ADMIN))) {
 	    add_note(from, conf.bot->nick, BOT_NOOWNERBOOT, -1, 0);
@@ -833,6 +834,7 @@ static void bot_reject(int idx, char *par)
 	  ok = 1;
 	  putlog(LOG_CMDS, "*", "#%s# boot %s (%s)", from, who, par[0] ? par : "No reason");
 	}
+     }
     } else {
       i = nextbot(destbot);
       *--destbot = '@';
@@ -1227,7 +1229,7 @@ static void bot_rsim(char *botnick, char *code, char *msg)
   }
 
   for (i = 0; i < dcc_total; i++) {
-   if (dcc[i].simul == ridx) {
+   if (dcc[i].type && dcc[i].simul == ridx) {
      putlog(LOG_DEBUG, "*", "Simul found old idx for %s: %d (ridx: %d)", nick, i, ridx);
      dcc[i].simultime = now;
      idx = i;

+ 2 - 2
src/botmsg.c

@@ -166,7 +166,7 @@ size_t simple_sprintf (char *buf, const char *format, ...)
 static void send_tand_but(int x, char *buf, size_t len)
 {
   for (int i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type == &DCC_BOT) && i != x) {
+    if (dcc[i].type && (dcc[i].type == &DCC_BOT) && i != x) {
       tputs(dcc[i].sock, buf, len);
     }
   }
@@ -591,7 +591,7 @@ int add_note(char *to, char *from, char *msg, int idx, int echo)
   iaway = 0;
   /* Online right now? */
   for (i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type->flags & DCT_GETNOTES) &&
+    if (dcc[i].type && (dcc[i].type->flags & DCT_GETNOTES) &&
 	((sock == (-1)) || (sock == dcc[i].sock)) &&
 	(!egg_strcasecmp(dcc[i].nick, to))) {
       int aok = 1;

+ 49 - 41
src/botnet.c

@@ -379,7 +379,7 @@ int nextbot(char *who)
     return -1;
 
   for (int j = 0; j < dcc_total; j++) {
-    if (bot->via && !egg_strcasecmp(bot->via->bot, dcc[j].nick) && (dcc[j].type == &DCC_BOT))
+    if (dcc[j].type && bot->via && !egg_strcasecmp(bot->via->bot, dcc[j].nick) && (dcc[j].type == &DCC_BOT))
       return j;
   }
 
@@ -414,13 +414,14 @@ void answer_local_whom(int idx, int chan)
 
   /* Find longest nick and botnick */
   nicklen = botnicklen = 0;
-  for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type == &DCC_CHAT) {
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && dcc[i].type == &DCC_CHAT) {
       if ((chan == (-1)) || ((chan >= 0) && (dcc[i].u.chat->channel == chan))) {
         t = strlen(dcc[i].nick); if(t > nicklen) nicklen = t;
         t = strlen(conf.bot->nick); if(t > botnicklen) botnicklen = t;
       }
     }
+  }
   for (i = 0; i < parties; i++) {
     if ((chan == (-1)) || ((chan >= 0) && (party[i].chan == chan))) {
       t = strlen(party[i].nick); if(t > nicklen) nicklen = t;
@@ -443,8 +444,8 @@ void answer_local_whom(int idx, int chan)
   dprintf(idx, format, "----------");
   egg_snprintf(format, sizeof format, "%%c%%-%us %%c %%s\n", nicklen);
 #endif /* HUB */
-  for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type == &DCC_CHAT) {
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && dcc[i].type == &DCC_CHAT) {
       if ((chan == (-1)) || ((chan >= 0) && (dcc[i].u.chat->channel == chan))) {
 	c = geticon(i);
 	if (c == '-')
@@ -477,6 +478,7 @@ void answer_local_whom(int idx, int chan)
 	  dprintf(idx, "   AWAY: %s\n", dcc[i].u.chat->away);
       }
     }
+  }
   for (i = 0; i < parties; i++) {
     if ((chan == (-1)) || ((chan >= 0) && (party[i].chan == chan))) {
       c = party[i].flag;
@@ -729,7 +731,7 @@ void dump_links(int z)
 
   /* Dump party line members */
   for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_CHAT) {
+    if (dcc[i].type && dcc[i].type == &DCC_CHAT) {
       if ((dcc[i].u.chat->channel >= 0) && (dcc[i].u.chat->channel < GLOBAL_CHANS)) {
         l = simple_sprintf(x, "j !%s %s %D %c%D %s\n", conf.bot->nick, dcc[i].nick, dcc[i].u.chat->channel, geticon(i), dcc[i].sock, dcc[i].host);
 	tputs(dcc[z].sock, x, l);
@@ -801,7 +803,7 @@ int botunlink(int idx, char *nick, char *reason)
   if (nick[0] == '*')
     dprintf(idx, "%s\n", BOT_UNLINKALL);
   for (i = 0; i < dcc_total; i++) {
-    if ((nick[0] == '*') || !egg_strcasecmp(dcc[i].nick, nick)) {
+    if (dcc[i].type && (nick[0] == '*') || !egg_strcasecmp(dcc[i].nick, nick)) {
       if (dcc[i].type == &DCC_FORK_BOT) {
 	if (idx >= 0)
 	  dprintf(idx, "%s: %s -> %s.\n", BOT_KILLLINKATTEMPT,
@@ -910,14 +912,15 @@ int botlink(char *linker, int idx, char *nick)
   } else {
     register int i;
 
-    for (i = 0; i < dcc_total; i++)
-      if ((dcc[i].user == u) &&
+    for (i = 0; i < dcc_total; i++) {
+      if (dcc[i].type && (dcc[i].user == u) &&
 	  ((dcc[i].type == &DCC_FORK_BOT) ||
 	   (dcc[i].type == &DCC_BOT_NEW))) {
 	if (idx >= 0)
 	  dprintf(idx, "%s\n", BOT_ALREADYLINKING);
 	return 0;
       }
+    }
     /* Address to connect to is in 'info' */
     struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
 
@@ -1053,10 +1056,11 @@ static void failed_tandem_relay(int idx)
 {
   int uidx = (-1), i;
 
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_PRE_RELAY) &&
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) &&
 	(dcc[i].u.relay->sock == dcc[idx].sock))
       uidx = i;
+  }
   if (uidx < 0) {
     putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
 	   dcc[idx].sock, dcc[idx].u.relay->sock);
@@ -1181,12 +1185,13 @@ static void tandem_relay_resolve_failure(int idx)
 {
   register int uidx = (-1), i;
 
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_PRE_RELAY) &&
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) &&
 	(dcc[i].u.relay->sock == dcc[idx].sock)) {
       uidx = i;
       break;
     }
+  }
   if (uidx < 0) {
     putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
 	   dcc[idx].sock, dcc[idx].u.relay->sock);
@@ -1239,20 +1244,22 @@ static void pre_relay(int idx, char *buf, register int len)
 {
   register int tidx = (-1), i;
 
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_FORK_RELAY) &&
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && (dcc[i].type == &DCC_FORK_RELAY) &&
 	(dcc[i].u.relay->sock == dcc[idx].sock)) {
       tidx = i;
       break;
     }
+  }
   if (tidx < 0) {
     /* Now try to find it among the DNSWAIT sockets instead. */
-    for (i = 0; i < dcc_total; i++)
-      if ((dcc[i].type == &DCC_DNSWAIT) &&
+    for (i = 0; i < dcc_total; i++) {
+      if (dcc[i].type && (dcc[i].type == &DCC_DNSWAIT) &&
 	  (dcc[i].sock == dcc[idx].u.relay->sock)) {
 	tidx = i;
 	break;
       }
+    }
   }
   if (tidx < 0) {
     putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
@@ -1285,20 +1292,22 @@ static void failed_pre_relay(int idx)
 {
   register int tidx = (-1), i;
 
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_FORK_RELAY) &&
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && (dcc[i].type == &DCC_FORK_RELAY) &&
 	(dcc[i].u.relay->sock == dcc[idx].sock)) {
       tidx = i;
       break;
     }
+  }
   if (tidx < 0) {
     /* Now try to find it among the DNSWAIT sockets instead. */
-    for (i = 0; i < dcc_total; i++)
-      if ((dcc[i].type == &DCC_DNSWAIT) &&
+    for (i = 0; i < dcc_total; i++) {
+      if (dcc[i].type && (dcc[i].type == &DCC_DNSWAIT) &&
 	  (dcc[i].sock == dcc[idx].u.relay->sock)) {
 	tidx = i;
 	break;
       }
+    }
   }
   if (tidx < 0) {
     putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
@@ -1330,10 +1339,10 @@ static void cont_tandem_relay(int idx, char *buf, register int len)
 {
   register int uidx = (-1), i;
 
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_PRE_RELAY) &&
-	(dcc[i].u.relay->sock == dcc[idx].sock))
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && (dcc[i].type == &DCC_PRE_RELAY) && (dcc[i].u.relay->sock == dcc[idx].sock))
       uidx = i;
+  }
   if (uidx < 0) {
     putlog(LOG_MISC, "*", "%s  %d -> %d", BOT_CANTFINDRELAYUSER,
 	   dcc[i].sock, dcc[i].u.relay->sock);
@@ -1369,7 +1378,7 @@ static void eof_dcc_relay(int idx)
   register int j;
 
   for (j = 0; j < dcc_total; j++)
-    if (dcc[j].sock == dcc[idx].u.relay->sock)
+    if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock)
       break;
   if (j == dcc_total) {
     killsock(dcc[idx].sock);
@@ -1590,31 +1599,30 @@ void check_botnet_pings()
   tand_t *bot = NULL;
 
   for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_BOT)
-      if (dcc[i].status & STAT_PINGED) {
-	char s[1024] = "";
-
-	putlog(LOG_BOTS, "*", "%s: %s", BOT_PINGTIMEOUT, dcc[i].nick);
-	bot = findbot(dcc[i].nick);
-	bots = bots_in_subtree(bot);
-	users = users_in_subtree(bot);
-	simple_sprintf(s, "%s: %s (lost %d bot%s and %d user%s)", BOT_PINGTIMEOUT,
+    if (dcc[i].type && dcc[i].type == &DCC_BOT && (dcc[i].status & STAT_PINGED)) {
+      char s[1024] = "";
+
+      putlog(LOG_BOTS, "*", "%s: %s", BOT_PINGTIMEOUT, dcc[i].nick);
+      bot = findbot(dcc[i].nick);
+      bots = bots_in_subtree(bot);
+      users = users_in_subtree(bot);
+      simple_sprintf(s, "%s: %s (lost %d bot%s and %d user%s)", BOT_PINGTIMEOUT,
 		       dcc[i].nick, bots, (bots != 1) ? "s" : "",
 		       users, (users != 1) ? "s" : "");
-	chatout("*** %s\n", s);
-	botnet_send_unlinked(i, dcc[i].nick, s);
-	killsock(dcc[i].sock);
-	lostdcc(i);
-      }
+      chatout("*** %s\n", s);
+      botnet_send_unlinked(i, dcc[i].nick, s);
+      killsock(dcc[i].sock);
+      lostdcc(i);
+    }
   }
   for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_BOT) {
+    if (dcc[i].type && dcc[i].type == &DCC_BOT) {
       botnet_send_ping(i);
       dcc[i].status |= STAT_PINGED;
     }
   }
   for (i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type == &DCC_BOT) && (dcc[i].status & STAT_LEAF)) {
+    if (dcc[i].type && (dcc[i].type == &DCC_BOT) && (dcc[i].status & STAT_LEAF)) {
       tand_t *via = findbot(dcc[i].nick);
 
       for (bot = tandbot; bot; bot = bot->next) {

+ 23 - 22
src/cmds.c

@@ -75,13 +75,13 @@ static void tell_who(int idx, int chan)
   /* calculate max nicklen */
   nicklen = 0;
   for (i = 0; i < dcc_total; i++) {
-      if(strlen(dcc[i].nick) > nicklen)
+      if(dcc[i].type && strlen(dcc[i].nick) > nicklen)
           nicklen = strlen(dcc[i].nick);
   }
   if(nicklen < 9) nicklen = 9;
   
   for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type == &DCC_CHAT)
+    if (dcc[i].type && dcc[i].type == &DCC_CHAT)
       if (dcc[i].u.chat->channel == chan) {
 	if (atr & USER_OWNER) {
 	  egg_snprintf(format, sizeof format, "  [%%.2lu]  %%c%%-%us %%s", nicklen);
@@ -117,7 +117,7 @@ static void tell_who(int idx, int chan)
 	  dprintf(idx, "      AWAY: %s\n", dcc[i].u.chat->away);
       }
   for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type == &DCC_BOT) {
+    if (dcc[i].type && dcc[i].type == &DCC_BOT) {
       if (!ok) {
 	ok = 1;
 	dprintf(idx, "Bots connected:\n");
@@ -141,7 +141,7 @@ static void tell_who(int idx, int chan)
     }
   ok = 0;
   for (i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
+    if (dcc[i].type && (dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
       if (!ok) {
 	ok = 1;
 	dprintf(idx, "Other people on the bot:\n");
@@ -485,7 +485,7 @@ static void cmd_lagged(int idx, char *par)
   /* Lists botnet lag to *directly connected* bots */
   putlog(LOG_CMDS, "*", "#%s# lagged %s", dcc[idx].nick, par);
   for (int i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_BOT) {
+    if (dcc[i].type && dcc[i].type == &DCC_BOT) {
       dprintf(idx, "%9s - %li seconds\n", dcc[i].nick, (dcc[i].pingtime > 120) ? (now - dcc[i].pingtime) : dcc[i].pingtime);
     }
   }
@@ -505,7 +505,7 @@ static void cmd_me(int idx, char *par)
   if (dcc[idx].u.chat->away != NULL)
     not_away(idx);
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type->flags & DCT_CHAT) && (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
+    if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) && (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
 	((i != idx) || (dcc[i].status & STAT_ECHO)))
       dprintf(i, "* %s %s\n", dcc[idx].nick, par);
 
@@ -1165,9 +1165,8 @@ static void cmd_boot(int idx, char *par)
 	     who, par[0] ? par : dcc[idx].nick);
     return;
   }
-  for (i = 0; i < dcc_total; i++)
-    if (!egg_strcasecmp(dcc[i].nick, who)
-        && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && !egg_strcasecmp(dcc[i].nick, who) && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
       u2 = get_user_by_handle(userlist, dcc[i].nick);
       if (u2 && (u2->flags & USER_OWNER)
           && egg_strcasecmp(dcc[idx].nick, who)) {
@@ -1183,6 +1182,7 @@ static void cmd_boot(int idx, char *par)
       do_boot(i, dcc[idx].nick, par);
       ok = 1;
     }
+  }
   if (!ok)
     dprintf(idx, "Who?  No such person on the party line.\n");
 }
@@ -1209,12 +1209,12 @@ static void cmd_console(int idx, char *par)
    * he doesn't use IRCnet ++rtc.
    */
   if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
-    for (i = 0; i < dcc_total; i++)
-      if (!egg_strcasecmp(nick, dcc[i].nick) &&
-	  (dcc[i].type == &DCC_CHAT) && (!ok)) {
+    for (i = 0; i < dcc_total; i++) {
+      if (dcc[i].type && !egg_strcasecmp(nick, dcc[i].nick) && (dcc[i].type == &DCC_CHAT) && (!ok)) {
 	ok = 1;
 	dest = i;
       }
+    }
     if (!ok) {
       dprintf(idx, "No such user on the party line!\n");
       return;
@@ -2101,15 +2101,15 @@ static void cmd_simul(int idx, char *par)
 
   bool ok = 0;
 
-  for (int i = 0; i < dcc_total; i++)
-    if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
-	(dcc[i].type->flags & DCT_SIMUL)) {
+  for (int i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && !egg_strcasecmp(nick, dcc[i].nick) && !ok && (dcc[i].type->flags & DCT_SIMUL)) {
       putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
       if (dcc[i].type && dcc[i].type->activity) {
 	dcc[i].type->activity(i, par, strlen(par));
 	ok = 1;
       }
     }
+  }
   if (!ok)
     dprintf(idx, "No such user on the party line.\n");
 }
@@ -2255,6 +2255,7 @@ int check_dcc_attrs(struct userrec *u, flag_t oatr)
   int stat;
 
   for (int i = 0; i < dcc_total; i++) {
+   if (dcc[i].type) {
 #ifdef LEAF
     if (dcc[i].type && dcc[i].type == &DCC_CHAT && !ischanhub() && u == conf.bot->u) {
       dprintf(i, "I am no longer a chathub..\n\n");
@@ -2352,6 +2353,7 @@ int check_dcc_attrs(struct userrec *u, flag_t oatr)
       }
 #endif /* HUB */
     }
+   }
   }
   return u->flags;
 }
@@ -2365,8 +2367,7 @@ int check_dcc_chanattrs(struct userrec *u, char *chname, flag_t chflags, flag_t
   struct chanset_t *chan = NULL;
 
   for (int i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type->flags & DCT_MASTER) &&
-	!egg_strcasecmp(u->handle, dcc[i].nick)) {
+    if (dcc[i].type && (dcc[i].type->flags & DCT_MASTER) && !egg_strcasecmp(u->handle, dcc[i].nick)) {
       if ((dcc[i].type == &DCC_CHAT) &&
 	  ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
 	   != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
@@ -2972,12 +2973,12 @@ static void cmd_strip(int idx, char *par)
   int dest = 0, i, pls, md, ok = 0;
 
   if ((nick[0] != '+') && (nick[0] != '-') &&dcc[idx].user && (dcc[idx].user->flags & USER_MASTER)) {
-    for (i = 0; i < dcc_total; i++)
-      if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
-	  !ok) {
+    for (i = 0; i < dcc_total; i++) {
+      if (dcc[i].type && !egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT && !ok) {
 	ok = 1;
 	dest = i;
       }
+    }
     if (!ok) {
       dprintf(idx, "No such user on the party line!\n");
       return;
@@ -3422,8 +3423,8 @@ static void cmd_mns_user(int idx, char *par)
     int idx2;
 
     for (idx2 = 0; idx2 < dcc_total; idx2++)
-      if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
-          !egg_strcasecmp(dcc[idx2].nick, handle))
+      if (dcc[idx2].type && dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT && 
+                 !egg_strcasecmp(dcc[idx2].nick, handle))
         break;
     if (idx2 != dcc_total) {
       dprintf(idx, "You can't remove a directly linked bot.\n");

+ 12 - 10
src/dcc.c

@@ -128,7 +128,7 @@ send_timesync(int idx)
 
     sprintf(s, "ts %li\n", timesync + now);
     for (int i = 0; i < dcc_total; i++) {
-      if ((dcc[i].type == &DCC_BOT) && (bot_aggressive_to(dcc[i].user))) {
+      if (dcc[i].type && (dcc[i].type == &DCC_BOT) && (bot_aggressive_to(dcc[i].user))) {
         dprintf(i, s);
       }
     }
@@ -171,7 +171,7 @@ greet_new_bot(int idx)
   dprintf(idx, "si %s %s %s", conf.username ? conf.username : "*", un.sysname ? un.sysname : "*",
           un.nodename ? un.nodename : "*");
   for (int i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_FORK_BOT) {
+    if (dcc[i].type && dcc[i].type == &DCC_FORK_BOT) {
       killsock(dcc[i].sock);
       lostdcc(i);
     }
@@ -286,7 +286,7 @@ cont_link(int idx, char *buf, int ii)
 
     /* If we're already connected somewhere, unlink and idle a sec */
     for (int i = 0; i < dcc_total; i++) {
-      if ((dcc[i].type == &DCC_BOT) && (!bot_aggressive_to(dcc[i].user))) {
+      if (dcc[i].type && (dcc[i].type == &DCC_BOT) && (!bot_aggressive_to(dcc[i].user))) {
         putlog(LOG_BOTS, "*", "Unlinking %s - restructure", dcc[i].nick);
         botnet_send_unlinked(i, dcc[i].nick, "Restructure");
         killsock(dcc[i].sock);
@@ -1066,6 +1066,7 @@ dcc_chat(int idx, char *buf, int len)
       if ((buf[1] == 'm') && (buf[2] == 'e') && buf[3] == ' ')
         me = 1;
       for (i = 0; i < dcc_total; i++) {
+       if (dcc[i].type) {
         int ok = 0;
 
         if (dcc[i].type->flags & DCT_MASTER) {
@@ -1083,6 +1084,7 @@ dcc_chat(int idx, char *buf, int len)
               dprintf(i, "-%s-> %s\n", dcc[idx].nick, buf + 1);
           }
         }
+       }
       }
     } else if (buf[0] == '\'') {
       int me = 0;
@@ -1090,7 +1092,7 @@ dcc_chat(int idx, char *buf, int len)
       if ((buf[1] == 'm') && (buf[2] == 'e') && ((buf[3] == ' ') || (buf[3] == '\'') || (buf[3] == ',')))
         me = 1;
       for (i = 0; i < dcc_total; i++) {
-        if (dcc[i].type->flags & DCT_CHAT) {
+        if (dcc[i].type && dcc[i].type->flags & DCT_CHAT) {
           if (me)
             dprintf(i, "=> %s%s\n", dcc[idx].nick, buf + 3);
           else
@@ -1280,7 +1282,7 @@ dcc_telnet_hostresolved(int i)
     strncpyz(dcc[i].host, dcc[i].u.dns->host, UHOSTLEN);
 
   for (idx = 0; idx < dcc_total; idx++)
-    if ((dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.dns->ibuf)) {
+    if (dcc[i].type && (dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.dns->ibuf)) {
       break;
     }
 
@@ -1451,7 +1453,7 @@ dupwait_notify(const char *who)
 {
   Assert(who);
   for (register int idx = 0; idx < dcc_total; idx++)
-    if ((dcc[idx].type == &DCC_DUPWAIT) && !egg_strcasecmp(dcc[idx].nick, who)) {
+    if (dcc[idx].type && (dcc[idx].type == &DCC_DUPWAIT) && !egg_strcasecmp(dcc[idx].nick, who)) {
       dcc_telnet_pass(idx, dcc[idx].u.dupwait->atr);
       break;
     }
@@ -1711,7 +1713,7 @@ eof_dcc_identwait(int idx)
 {
   putlog(LOG_MISC, "*", DCC_LOSTCONN, dcc[idx].host, dcc[idx].port);
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_IDENT) && (dcc[i].u.ident_sock == dcc[idx].sock)) {
+    if (dcc[i].type && (dcc[i].type == &DCC_IDENT) && (dcc[i].u.ident_sock == dcc[idx].sock)) {
       killsock(dcc[i].sock);    /* Cleanup ident socket */
       dcc[i].u.other = 0;
       lostdcc(i);
@@ -1755,7 +1757,7 @@ dcc_ident(int idx, char *buf, int len)
   rmspace(uid);
   uid[20] = 0;                  /* 20 character ident max */
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
+    if (dcc[i].type && (dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
       simple_sprintf(buf1, "%s@%s", uid, dcc[idx].host);
       dcc_telnet_got_ident(i, buf1);
     }
@@ -1770,7 +1772,7 @@ eof_dcc_ident(int idx)
   char buf[UHOSTLEN] = "";
 
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
+    if (dcc[i].type && (dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
       putlog(LOG_MISC, "*", DCC_EOFIDENT);
       simple_sprintf(buf, "telnet@%s", dcc[idx].host);
       dcc_telnet_got_ident(i, buf);
@@ -1805,7 +1807,7 @@ dcc_telnet_got_ident(int i, char *host)
   int idx;
 
   for (idx = 0; idx < dcc_total; idx++)
-    if ((dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.ident_sock))
+    if (dcc[i].type && (dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.ident_sock))
       break;
   dcc[i].u.other = 0;
   if (dcc_total == idx) {

+ 7 - 5
src/dccutil.c

@@ -237,7 +237,7 @@ void chatout(const char *format, ...)
     *p++ = 0;
 
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_CHAT) && !(dcc[i].simul))
+    if (dcc[i].type && (dcc[i].type == &DCC_CHAT) && !(dcc[i].simul))
       if (dcc[i].u.chat->channel >= 0)
         dprintf(i, "%s\n", s);
 }
@@ -257,7 +257,7 @@ void chanout_but(int x, int chan, const char *format, ...)
     *p = 0;
 
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_CHAT) && (i != x) && !(dcc[i].simul))
+    if (dcc[i].type && (dcc[i].type == &DCC_CHAT) && (i != x) && !(dcc[i].simul))
       if (dcc[i].u.chat->channel == chan)
         dprintf(i, "%s\n", s);
 }
@@ -390,7 +390,7 @@ static void removedcc(int n)
 void dcc_remove_lost(void)
 {
   for (int i = 0; i < dcc_total; i++) {
-    if (dcc[i].type == &DCC_LOST) {
+    if (dcc[i].type && dcc[i].type == &DCC_LOST) {
       dcc[i].type = NULL;
       dcc[i].sock = -1;
       removedcc(i);
@@ -423,7 +423,7 @@ void tell_dcc(int idx)
 
   /* calculate max nicklen */
   for (i = 0; i < dcc_total; i++) {
-      if(strlen(dcc[i].nick) > (unsigned) nicklen)
+      if(dcc[i].type && strlen(dcc[i].nick) > (unsigned) nicklen)
           nicklen = strlen(dcc[i].nick);
   }
   if(nicklen < 9) 
@@ -438,6 +438,7 @@ void tell_dcc(int idx)
 
   dprintf(idx, "dns_idx: %d, servidx: %d\n", dns_idx, servidx);
   for (i = 0; i < dcc_total; i++) {
+   if (dcc[i].type) {
     j = strlen(dcc[i].host);
     if (j > 40)
       j -= 40;
@@ -452,6 +453,7 @@ void tell_dcc(int idx)
     if (dcc[i].type == &DCC_LOST)
       dprintf(idx, "LOST:\n");
     dprintf(idx, format, dcc[i].sock, i, dcc[i].addr, dcc[i].port, dcc[i].nick, dcc[i].host + j, other);
+   }
   }
 }
 
@@ -655,7 +657,7 @@ port_t listen_all(port_t lport, bool off)
     }
 
   for (int ii = 0; ii < dcc_total; ii++) {
-    if ((dcc[ii].type == &DCC_TELNET) && (dcc[ii].port == port)) {
+    if (dcc[ii].type && (dcc[ii].type == &DCC_TELNET) && (dcc[ii].port == port)) {
       idx = ii;
 
       if (off) {

+ 2 - 2
src/dns.c

@@ -81,7 +81,7 @@ struct dcc_table DCC_DNSWAIT =
 static void dns_dcchostbyip(in_addr_t ip, char *hostn, int ok, void *other)
 {
   for (int idx = 0; idx < dcc_total; idx++) {
-    if ((dcc[idx].type == &DCC_DNSWAIT) &&
+    if (dcc[idx].type && (dcc[idx].type == &DCC_DNSWAIT) &&
         (dcc[idx].u.dns->dns_type == RES_HOSTBYIP) &&
         (dcc[idx].u.dns->ip == ip)) {
       if (dcc[idx].u.dns->host)
@@ -102,7 +102,7 @@ static void dns_dcchostbyip(in_addr_t ip, char *hostn, int ok, void *other)
 static void dns_dccipbyhost(in_addr_t ip, char *hostn, int ok, void *other)
 {
   for (int idx = 0; idx < dcc_total; idx++) {
-    if ((dcc[idx].type == &DCC_DNSWAIT) &&
+    if (dcc[idx].type && (dcc[idx].type == &DCC_DNSWAIT) &&
         (dcc[idx].u.dns->dns_type == RES_IPBYHOST) &&
         !egg_strcasecmp(dcc[idx].u.dns->host, hostn)) {
       dcc[idx].u.dns->ip = ip;

+ 1 - 1
src/log.c

@@ -197,7 +197,7 @@ void putlog(int type, const char *chname, const char *format, ...)
   }
 
   for (idx = 0; idx < dcc_total; idx++) {
-    if ((dcc[idx].type == &DCC_CHAT && !dcc[idx].simul) && (dcc[idx].u.chat->con_flags & type)) {
+    if (dcc[idx].type && (dcc[idx].type == &DCC_CHAT && !dcc[idx].simul) && (dcc[idx].u.chat->con_flags & type)) {
       if ((chname[0] == '@') || (chname[0] == '*') || (dcc[idx].u.chat->con_chan[0] == '*') ||
           (!rfc_casecmp(chname, dcc[idx].u.chat->con_chan)))
         dprintf(idx, "%s\n", out);

+ 6 - 6
src/main.c

@@ -165,7 +165,7 @@ void fatal(const char *s, int recoverable)
 #endif /* HUB */
 
   for (int i = 0; i < dcc_total; i++)
-    if (dcc[i].sock >= 0)
+    if (dcc[i].type && dcc[i].sock >= 0)
       killsock(dcc[i].sock);
 
   if (!recoverable) {
@@ -194,7 +194,7 @@ static void check_expired_dcc()
 /* this also expires irc dcc_cmd auths */
 static void expire_simuls() {
   for (int idx = 0; idx < dcc_total; idx++) {
-    if (dcc[idx].simul > 0) {
+    if (dcc[idx].type && dcc[idx].simul > 0) {
       if ((now - dcc[idx].simultime) >= 100) { /* expire simuls after 100 seconds (re-uses idx, so it wont fill up) */
         dcc[idx].simul = -1;
         lostdcc(idx);
@@ -945,7 +945,7 @@ printf("out: %s\n", out);
 
     if (xx >= 0) {		/* Non-error */
       for (idx = 0; idx < dcc_total; idx++) {
-	if (dcc[idx].sock == xx) {
+	if (dcc[idx].type && dcc[idx].sock == xx) {
 	  if (dcc[idx].type && dcc[idx].type->activity) {
 	    /* Traffic stats */
 	    if (dcc[idx].type->name) {
@@ -976,8 +976,8 @@ printf("out: %s\n", out);
       if (i == STDOUT && !backgrd)
 	fatal("END OF FILE ON TERMINAL", 0);
       for (idx = 0; idx < dcc_total; idx++) {
-	if (dcc[idx].sock == i) {
-	  if (dcc[idx].type && dcc[idx].type->eof)
+	if (dcc[idx].type && dcc[idx].sock == i) {
+	  if (dcc[idx].type->eof)
 	    dcc[idx].type->eof(idx);
 	  else {
 	    putlog(LOG_MISC, "*",
@@ -997,7 +997,7 @@ printf("out: %s\n", out);
     } else if (xx == -2 && errno != EINTR) {	/* select() error */
       putlog(LOG_MISC, "*", "* Socket error #%d; recovering.", errno);
       for (i = 0; i < dcc_total; i++) {
-	if (dcc[i].sock != -1 && (fcntl(dcc[i].sock, F_GETFD, 0) == -1) && (errno = EBADF)) {
+	if (dcc[i].type && dcc[i].sock != -1 && (fcntl(dcc[i].sock, F_GETFD, 0) == -1) && (errno = EBADF)) {
 	  putlog(LOG_MISC, "*",
 		 "DCC socket %d (type %s, name '%s') expired -- pfft",
 		 dcc[i].sock, dcc[i].type->name, dcc[i].nick);

+ 1 - 1
src/mod/channels.mod/cmdschan.c

@@ -1066,7 +1066,7 @@ static void mns_chan(int idx, char *par, char *bot)
 
   if (!bot) {
     for (i = 0; i < dcc_total; i++)
-      if ((dcc[i].type->flags & DCT_CHAT) && !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
+      if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) && !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
         dprintf(i, "%s is no longer a valid channel, changing your console to '*'\n", chname);
         strcpy(dcc[i].u.chat->con_chan, "*");
       } 

+ 1 - 1
src/mod/console.mod/console.c

@@ -162,7 +162,7 @@ console_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
   e->u.extra = ci;
   /* now let's propogate to the dcc list */
   for (int i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type == &DCC_CHAT) && !strcmp(dcc[i].user->handle, u->handle)) {
+    if (dcc[i].type && (dcc[i].type == &DCC_CHAT) && !strcmp(dcc[i].user->handle, u->handle)) {
       if (ci->channel && ci->channel[0])
         strcpy(dcc[i].u.chat->con_chan, ci->channel);
       dcc[i].u.chat->con_flags = ci->conflags;

+ 3 - 2
src/mod/ctcp.mod/ctcp.c

@@ -363,7 +363,8 @@ static void ctcp_minutely()
 
   if (listen_time <= 0) {
     for (int i = 0; i < dcc_total; i++) {
-      if ((dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)") || !strcmp(dcc[i].nick, "(telnet6)"))) {
+      if (dcc[i].type && (dcc[i].type->flags & DCT_LISTEN) && 
+           (!strcmp(dcc[i].nick, "(telnet)") || !strcmp(dcc[i].nick, "(telnet6)"))) {
         putlog(LOG_DEBUG, "*", "Closing listening port %d %s", dcc[i].port, dcc[i].nick);
 
         killsock(dcc[i].sock);
@@ -582,7 +583,7 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
     int ix = -1;
 
     for (int i = 0; i < dcc_total; i++) {
-      if ((dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
+      if (dcc[i].type && (dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
         ix = i;
     }
     if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0)) < 0))

+ 1 - 1
src/mod/irc.mod/msgcmds.c

@@ -474,7 +474,7 @@ static int msgc_test(char *nick, char *host, struct userrec *u, char *chname, ch
     chan++;
 
   for (i = 0; i < dcc_total; i++) {
-   if (dcc[i].msgc && ((chan && !strcmp(dcc[i].simulbot, chname) && !strcmp(dcc[i].nick, u->handle)) || 
+   if (dcc[i].type && dcc[i].msgc && ((chan && !strcmp(dcc[i].simulbot, chname) && !strcmp(dcc[i].nick, u->handle)) || 
       (!chan && !strcmp(dcc[i].simulbot, nick)))) {
      putlog(LOG_DEBUG, "*", "Simul found old idx for %s/%s: %d", nick, chname, i);
      dcc[i].simultime = now;

+ 4 - 2
src/mod/notes.mod/notes.c

@@ -620,7 +620,7 @@ static int msg_notes(char *nick, char *host, struct userrec *u, char *par)
       return 1;
     }
     for (i = 0; i < dcc_total; i++) {
-      if ((!egg_strcasecmp(dcc[i].nick, to)) &&
+      if (dcc[i].type && (!egg_strcasecmp(dcc[i].nick, to)) &&
 	  (dcc[i].type->flags & DCT_GETNOTES)) {
 	int aok = 1;
 
@@ -680,7 +680,7 @@ static void notes_hourly()
 	if (u) {
 	  k = num_notes(u->handle);
 	  for (l = 0; l < dcc_total; l++)
-	    if ((dcc[l].type->flags & DCT_CHAT) &&
+	    if (dcc[l].type && (dcc[l].type->flags & DCT_CHAT) &&
 		!egg_strcasecmp(dcc[l].nick, u->handle)) {
 	      k = 0;		/* They already know they have notes */
 	      break;
@@ -695,11 +695,13 @@ static void notes_hourly()
       }
     }
     for (l = 0; l < dcc_total; l++) {
+     if (dcc[l].type) {
       k = num_notes(dcc[l].nick);
       if ((k > 0) && (dcc[l].type->flags & DCT_CHAT)) {
 	dprintf(l, NOTES_WAITING2, k, k == 1 ? "" : "s");
 	dprintf(l, NOTES_DCC_USAGE_READ2);
       }
+     }
     }
   }
 }

+ 3 - 3
src/mod/server.mod/servmsg.c

@@ -1112,7 +1112,7 @@ irc_whois(char *nick, char *format, ...)
   va_end(va);
 
   for (int idx = 0; idx < dcc_total; idx++)
-    if (dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois))
+    if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois))
       dprintf(idx, "%s\n", va_out);
 }
 
@@ -1242,7 +1242,7 @@ static int got318_369(char *from, char *msg, int whowas)
 
   irc_whois(nick, "%s", msg);
   for (int idx = 0; idx < dcc_total; idx++) {
-    if (dcc[idx].whois[0] && !rfc_casecmp(dcc[idx].whois, nick) &&
+    if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(dcc[idx].whois, nick) &&
        ((!whowas && !dcc[idx].whowas) || (whowas && dcc[idx].whowas))) {
       dcc[idx].whois[0] = 0;
       dcc[idx].whowas = 0;
@@ -1262,7 +1262,7 @@ static int got401(char *from, char *msg)
   fixcolon(msg);
   irc_whois(nick, "%s", msg);
   for (int idx = 0; idx < dcc_total; idx++)
-    if (dcc[idx].whois[0] && !rfc_casecmp(dcc[idx].whois, nick))
+    if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(dcc[idx].whois, nick))
       dcc[idx].whowas = 1;
 
   dprintf(DP_SERVER, "WHOWAS %s %s\n", nick, from);

+ 16 - 13
src/mod/share.mod/share.c

@@ -1009,7 +1009,7 @@ share_userfileq(int idx, char *par)
     bool ok = 1;
 
     for (int i = 0; i < dcc_total; i++)
-      if (dcc[i].type->flags & DCT_BOT) {
+      if (dcc[i].type && dcc[i].type->flags & DCT_BOT) {
         if ((dcc[i].status & STAT_SHARE) && (dcc[i].status & STAT_AGGRESSIVE) && (i != idx)) {
           ok = 0;
           break;
@@ -1104,7 +1104,7 @@ hook_read_userfile()
 {
   if (!noshare) {
     for (int i = 0; i < dcc_total; i++) {
-      if ((dcc[i].type->flags & DCT_BOT) && (dcc[i].status & STAT_SHARE) && !(dcc[i].status & STAT_AGGRESSIVE)
+      if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) && (dcc[i].status & STAT_SHARE) && !(dcc[i].status & STAT_AGGRESSIVE)
           && (1)) {
         /* Cancel any existing transfers */
         if (dcc[i].status & STAT_SENDING)
@@ -1213,7 +1213,8 @@ shareout(const char *format, ...)
   va_end(va);
 
   for (int i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type->flags & DCT_BOT) && (dcc[i].status & STAT_SHARE) && !(dcc[i].status & (STAT_GETTING | STAT_SENDING))) {
+    if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) && 
+         (dcc[i].status & STAT_SHARE) && !(dcc[i].status & (STAT_GETTING | STAT_SENDING))) {
       tputs(dcc[i].sock, s, l + 2);
     }
   }
@@ -1234,7 +1235,7 @@ shareout_but(int x, const char *format, ...)
   va_end(va);
 
   for (int i = 0; i < dcc_total; i++)
-    if ((dcc[i].type->flags & DCT_BOT) && (i != x) &&
+    if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) && (i != x) &&
         (dcc[i].status & STAT_SHARE) && (!(dcc[i].status & STAT_GETTING)) &&
         (!(dcc[i].status & STAT_SENDING))) {
       tputs(dcc[i].sock, s, l + 2);
@@ -1249,7 +1250,7 @@ check_expired_tbufs()
 {
   /* Resend userfile requests */
   for (int i = 0; i < dcc_total; i++) {
-    if (dcc[i].type->flags & DCT_BOT) {
+    if (dcc[i].type && dcc[i].type->flags & DCT_BOT) {
       if (dcc[i].status & STAT_OFFERED) {
         if (now - dcc[i].timeval > 120) {
           if (dcc[i].user && bot_aggressive_to(dcc[i].user))
@@ -1310,7 +1311,7 @@ finish_share(int idx)
   int i, j = -1;
 
   for (i = 0; i < dcc_total; i++)
-    if (!egg_strcasecmp(dcc[i].nick, dcc[idx].host) && (dcc[i].type->flags & DCT_BOT))
+    if (dcc[i].type && !egg_strcasecmp(dcc[i].nick, dcc[idx].host) && (dcc[i].type->flags & DCT_BOT))
       j = i;
   if (j == -1)
     return;
@@ -1367,7 +1368,8 @@ finish_share(int idx)
    * to NULL directly.
    */
   for (i = 0; i < dcc_total; i++)
-    dcc[i].user = NULL;
+    if (dcc[i].type)
+      dcc[i].user = NULL;
   for (i = 0; i < auth_total; i++)
     auth[i].user = NULL;
 
@@ -1390,7 +1392,8 @@ finish_share(int idx)
     clear_chanlist();           /* Remove all user references from the
                                  * channel lists.                       */
     for (i = 0; i < dcc_total; i++)
-      dcc[i].user = get_user_by_handle(ou, dcc[i].nick);
+      if (dcc[i].type)
+        dcc[i].user = get_user_by_handle(ou, dcc[i].nick);
     for (i = 0; i < auth_total; i++)
       if (auth[i].hand[0])
         auth[i].user = get_user_by_handle(ou, auth[i].hand);
@@ -1505,7 +1508,7 @@ cancel_user_xfer(int idx, void *x)
     if (dcc[idx].status & STAT_GETTING) {
       j = 0;
       for (i = 0; i < dcc_total; i++)
-        if (!egg_strcasecmp(dcc[i].host, dcc[idx].nick) &&
+        if (dcc[i].type && !egg_strcasecmp(dcc[i].host, dcc[idx].nick) &&
             ((dcc[i].type->flags & (DCT_FILETRAN | DCT_FILESEND)) == (DCT_FILETRAN | DCT_FILESEND)))
           j = i;
       if (j != 0) {
@@ -1518,7 +1521,7 @@ cancel_user_xfer(int idx, void *x)
     if (dcc[idx].status & STAT_SENDING) {
       j = 0;
       for (i = 0; i < dcc_total; i++)
-        if ((!egg_strcasecmp(dcc[i].host, dcc[idx].nick)) &&
+        if (dcc[i].type && (!egg_strcasecmp(dcc[i].host, dcc[idx].nick)) &&
             ((dcc[i].type->flags & (DCT_FILETRAN | DCT_FILESEND))
              == DCT_FILETRAN))
           j = i;
@@ -1541,12 +1544,12 @@ share_report(int idx, int details)
 
   if (details) {
     for (i = 0; i < dcc_total; i++)
-      if (dcc[i].type == &DCC_BOT) {
+      if (dcc[i].type && dcc[i].type == &DCC_BOT) {
         if (dcc[i].status & STAT_GETTING) {
           int ok = 0;
 
           for (j = 0; j < dcc_total; j++)
-            if (((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
+            if (dcc[j].type && ((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
                  == (DCT_FILETRAN | DCT_FILESEND)) && !egg_strcasecmp(dcc[j].host, dcc[i].nick)) {
               dprintf(idx, "Downloading userlist from %s (%d%% done)\n",
                       dcc[i].nick, (int) (100.0 * ((float) dcc[j].status) / ((float) dcc[j].u.xfer->length)));
@@ -1558,7 +1561,7 @@ share_report(int idx, int details)
 #ifdef HUB
         } else if (dcc[i].status & STAT_SENDING) {
           for (j = 0; j < dcc_total; j++) {
-            if (((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
+            if (dcc[j].type && ((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
                  == DCT_FILETRAN)
                 && !egg_strcasecmp(dcc[j].host, dcc[i].nick)) {
               if (dcc[j].type == &DCC_GET)

+ 23 - 22
src/mod/transfer.mod/transfer.c

@@ -64,13 +64,14 @@ static void wipe_tmp_filename(char *fn, int idx)
 
   if (!copy_to_tmp)
     return;
-  for (i = 0; i < dcc_total; i++)
-    if (i != idx)
-      if (dcc[i].type == &DCC_GET || dcc[i].type == &DCC_GET_PENDING)
-	if (!strcmp(dcc[i].u.xfer->filename, fn)) {
-	  ok = 0;
-	  break;
-	}
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && i != idx && dcc[i].type == &DCC_GET || dcc[i].type == &DCC_GET_PENDING) {
+      if (!strcmp(dcc[i].u.xfer->filename, fn)) {
+        ok = 0;
+        break;
+      }
+    }
+  }
   if (ok)
     unlink(fn);
 }
@@ -82,7 +83,7 @@ static int at_limit(char *nick)
   int i, x = 0;
 
   for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type == &DCC_GET || dcc[i].type == &DCC_GET_PENDING)
+    if (dcc[i].type && dcc[i].type == &DCC_GET || dcc[i].type == &DCC_GET_PENDING)
       if (!egg_strcasecmp(dcc[i].nick, nick))
 	x++;
   return (x >= dcc_limit);
@@ -279,7 +280,7 @@ void eof_dcc_fork_send(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if ((!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
+      if (dcc[x].type && (!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
 	  (dcc[x].type->flags & DCT_BOT)) {
 	y = x;
 	break;
@@ -294,7 +295,7 @@ void eof_dcc_fork_send(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if ((!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
+      if (dcc[x].type && (!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
 	  (dcc[x].type->flags & DCT_BOT)) {
 	y = x;
 	break;
@@ -378,7 +379,7 @@ static void eof_dcc_send(int idx)
     free(ofn);
     free(nfn);
     for (j = 0; j < dcc_total; j++)
-      if (!ok && (dcc[j].type->flags & (DCT_GETNOTES)) &&
+      if (dcc[j].type && !ok && (dcc[j].type->flags & (DCT_GETNOTES)) &&
 	  !egg_strcasecmp(dcc[j].nick, hand)) {
 	ok = 1;
 	dprintf(j,TRANSFER_THANKS);
@@ -395,7 +396,7 @@ static void eof_dcc_send(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if ((!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
+      if (dcc[x].type && (!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     if (y) {
@@ -425,7 +426,7 @@ static void eof_dcc_send(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if ((!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
+      if (dcc[x].type && (!egg_strcasecmp(dcc[x].nick, dcc[idx].host)) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     if (y) {
@@ -599,7 +600,7 @@ void dcc_get(int idx, char *buf, int len)
       int x, y = 0;
 
       for (x = 0; x < dcc_total; x++)
-	if (!egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
+	if (dcc[x].type && !egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
 	    (dcc[x].type->flags & DCT_BOT))
 	  y = x;
       if (y != 0)
@@ -614,7 +615,7 @@ void dcc_get(int idx, char *buf, int len)
       int x, y = 0;
 
       for (x = 0; x < dcc_total; x++)
-	if (!egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
+	if (dcc[x].type && !egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
 	    (dcc[x].type->flags & DCT_BOT))
 	  y = x;
       if (y != 0) {
@@ -659,7 +660,7 @@ void eof_dcc_get(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if (!egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
+      if (dcc[x].type && !egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     putlog(LOG_BOTS, "*", TRANSFER_ABORT_USERFILE);
@@ -683,7 +684,7 @@ void eof_dcc_get(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if (!egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
+      if (dcc[x].type && !egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     putlog(LOG_BOTS, "*", "Lost binary transfer; aborting.");
@@ -769,7 +770,7 @@ static void transfer_get_timeout(int i)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if ((!egg_strcasecmp(dcc[x].nick, dcc[i].host)) &&
+      if (dcc[x].type && (!egg_strcasecmp(dcc[x].nick, dcc[i].host)) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     if (y != 0) {
@@ -796,7 +797,7 @@ static void transfer_get_timeout(int i)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if ((!egg_strcasecmp(dcc[x].nick, dcc[i].host)) &&
+      if (dcc[x].type && (!egg_strcasecmp(dcc[x].nick, dcc[i].host)) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     if (y != 0) {
@@ -845,7 +846,7 @@ void tout_dcc_send(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if (!egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
+      if (dcc[x].type && !egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     if (y != 0) {
@@ -858,7 +859,7 @@ void tout_dcc_send(int idx)
     int x, y = 0;
 
     for (x = 0; x < dcc_total; x++)
-      if (!egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
+      if (dcc[x].type && !egg_strcasecmp(dcc[x].nick, dcc[idx].host) &&
 	  (dcc[x].type->flags & DCT_BOT))
 	y = x;
     if (y != 0) {
@@ -1205,7 +1206,7 @@ static int ctcp_DCC_RESUME(char *nick, char *from, char *handle, char *object, c
   offset = my_atoul(newsplit(&msg));
   // Search for existing SEND 
   for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_GET_PENDING) &&
+    if (dcc[i].type && (dcc[i].type == &DCC_GET_PENDING) &&
 	(!rfc_casecmp(dcc[i].nick, nick)) && (dcc[i].port == port))
       break;
   // No matching transfer found?

+ 5 - 5
src/mod/update.mod/update.c

@@ -371,7 +371,7 @@ static void check_updates()
     cnt = 0;
 
     for (i = 0; i < dcc_total; i++) {
-      if (dcc[i].type->flags & DCT_BOT && (dcc[i].status & STAT_SHARE) &&
+      if (dcc[i].type && dcc[i].type->flags & DCT_BOT && (dcc[i].status & STAT_SHARE) &&
           !(dcc[i].status & STAT_SENDINGU) && !(dcc[i].status & STAT_OFFEREDU) &&
           !(dcc[i].status & STAT_UPDATED)) { /* only offer binary to bots that are sharing */
         bot = findbot(dcc[i].nick);
@@ -398,12 +398,12 @@ void update_report(int idx, int details)
 
   if (details) {
     for (i = 0; i < dcc_total; i++)
-      if (dcc[i].type == &DCC_BOT) {
+      if (dcc[i].type && dcc[i].type == &DCC_BOT) {
 	if (dcc[i].status & STAT_GETTINGU) {
 	  int ok = 0;
 
 	  for (j = 0; j < dcc_total; j++)
-	    if (((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
+	    if (dcc[j].type && ((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
 		 == (DCT_FILETRAN | DCT_FILESEND)) &&
 		!egg_strcasecmp(dcc[j].host, dcc[i].nick)) {
 	      dprintf(idx, "Downloading binary from %s (%d%% done)\n",
@@ -419,7 +419,7 @@ void update_report(int idx, int details)
 #ifdef HUB
 	} else if (dcc[i].status & STAT_SENDINGU) {
 	  for (j = 0; j < dcc_total; j++) {
-	    if (((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
+	    if (dcc[j].type && ((dcc[j].type->flags & (DCT_FILETRAN | DCT_FILESEND))
 		 == DCT_FILETRAN)
 		&& !egg_strcasecmp(dcc[j].host, dcc[i].nick)) {
 	      if (dcc[j].type == &DCC_GET)
@@ -443,7 +443,7 @@ void update_report(int idx, int details)
 static void cmd_bupdate(int idx, char *par)
 {
   for (int i = 0; i < dcc_total; i++) {
-    if (!egg_strcasecmp(dcc[i].nick, par)) {
+    if (dcc[i].type && !egg_strcasecmp(dcc[i].nick, par)) {
       dprintf(i, "sb u?\n");
       dcc[i].status &= ~(STAT_SENDINGU | STAT_UPDATED);
       dcc[i].status |= STAT_OFFEREDU;

+ 2 - 2
src/net.c

@@ -1472,7 +1472,7 @@ void tputs(register int z, char *s, size_t len)
   for (register int i = 0; i < MAXSOCKS; i++) {
     if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == z)) {
       for (idx = 0; idx < dcc_total; idx++) {
-        if ((dcc[idx].sock == z) && dcc[idx].type && dcc[idx].type->name) {
+        if (dcc[idx].type && (dcc[idx].sock == z) && dcc[idx].type->name) {
           if (!strncmp(dcc[idx].type->name, "BOT", 3))
                 traffic.out_today.bn += len;
           else if (!strcmp(dcc[idx].type->name, "SERVER"))
@@ -1584,7 +1584,7 @@ int findanyidx(register int sock)
 
   if (sock != -1)
     for (j = 0; j < dcc_total; j++)
-      if (dcc[j].sock == sock)
+      if (dcc[j].type && dcc[j].sock == sock)
         return j;
 
   return -1;

+ 5 - 4
src/userrec.c

@@ -54,7 +54,7 @@ int count_users(struct userrec *bu)
 static struct userrec *check_dcclist_hand(char *handle)
 {
   for (int i = 0; i < dcc_total; i++)
-    if (!egg_strcasecmp(dcc[i].nick, handle))
+    if (dcc[i].type && !egg_strcasecmp(dcc[i].nick, handle))
       return dcc[i].user;
   return NULL;
 }
@@ -141,7 +141,8 @@ void clear_userlist(struct userrec *bu)
     struct chanset_t *cst = NULL;
 
     for (int i = 0; i < dcc_total; i++)
-      dcc[i].user = NULL;
+      if (dcc[i].type)
+        dcc[i].user = NULL;
 
     conf.bot->u = NULL;
 
@@ -423,7 +424,7 @@ int change_handle(struct userrec *u, char *newh)
   strncpyz(s, u->handle, sizeof s);
   strncpyz(u->handle, newh, sizeof u->handle);
   for (int i = 0; i < dcc_total; i++)
-    if (dcc[i].type != &DCC_BOT && !egg_strcasecmp(dcc[i].nick, s)) {
+    if (dcc[i].type && dcc[i].type != &DCC_BOT && !egg_strcasecmp(dcc[i].nick, s)) {
       strncpyz(dcc[i].nick, newh, sizeof dcc[i].nick);
       if (dcc[i].type == &DCC_CHAT && dcc[i].u.chat->channel >= 0) {
 	chanout_but(-1, dcc[i].u.chat->channel, "*** Handle change: %s -> %s\n", s, newh);
@@ -550,7 +551,7 @@ int deluser(char *handle)
   if (!noshare && (handle[0] != '*'))
     shareout("k %s\n", handle);
   for (fnd = 0; fnd < dcc_total; fnd++)
-    if (dcc[fnd].user == u)
+    if (dcc[fnd].type && dcc[fnd].user == u)
       dcc[fnd].user = NULL;	/* Clear any dcc users for this entry null is safe-ish */
   clear_chanlist();
   freeuser(u);

+ 5 - 1
src/users.c

@@ -959,7 +959,7 @@ int readuserfile(const char *file, struct userrec **ret)
 
 	      u = get_user_by_handle(bu, code);
 	      for (i = 0; i < dcc_total; i++)
-		if (!egg_strcasecmp(code, dcc[i].nick))
+		if (dcc[i].type && !egg_strcasecmp(code, dcc[i].nick))
 		  dcc[i].user = u;
         
               if (!egg_strcasecmp(code, conf.bot->nick))
@@ -1080,6 +1080,7 @@ void autolink_cycle(char *start)
   link_pref_val(conf.bot->u, myval);
   strcpy(bestval, myval);
   for (int i = 0; i < dcc_total; i++) {
+   if (dcc[i].type) {
     if (dcc[i].type == &DCC_BOT_NEW)
       return;
     if (dcc[i].type == &DCC_FORK_BOT)
@@ -1117,6 +1118,7 @@ void autolink_cycle(char *start)
   	  botunlink(-2, dcc[i].nick, "Linked but not sharing?");
       }
     }
+   }
   }
 
   struct userrec *u = NULL;
@@ -1168,12 +1170,14 @@ void autolink_cycle(char *start)
   } 
 
   for (int i = 0; i < dcc_total; i++) {
+   if (dcc[i].type) {
     if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
       return;
     if (dcc[i].type == &DCC_BOT) {
       strcpy(curhub, dcc[i].nick);
       break;
     }
+   }
   }
 
   if (curhub[0]) {