fixed crash in modcmd.c (bots could be destroyed inside a function)
authorpk910 <philipp@zoelle1.de>
Wed, 21 Dec 2011 23:24:24 +0000 (00:24 +0100)
committerpk910 <philipp@zoelle1.de>
Wed, 21 Dec 2011 23:29:00 +0000 (00:29 +0100)
src/modcmd.c

index 058612a2b353cd09887d543c67d5ddf000389947..aca47f66a14682780e54fe289904bf28fabd771a 100644 (file)
@@ -531,6 +531,7 @@ static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *mess
     struct ClientSocket *client;
     FD_ZERO(&fds);
     FD_ZERO(&fds2);
+    got_chanmsg_loop1:
     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
         if(isUserOnChan(client->user, chan) && (client->flags & SOCKET_FLAG_PREFERRED) && ((client->botid == 0 && !FD_ISSET(client->clientid, &fds)) || (client->botid && !FD_ISSET(client->botid, &fds2))))  {
             FD_SET(client->clientid, &fds);
@@ -538,16 +539,19 @@ static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *mess
             trigger = get_channel_trigger(client->botid, client->clientid, chan);
             if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
                 handle_command(client, user, chan, message + strlen(trigger));
+                goto got_chanmsg_loop1; //Thats really really bad, i know... But we can't count on the "getBots" list anymore after executing a command
             }
         }
     }
+    got_chanmsg_loop2:
     for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
         if(isUserOnChan(client->user, chan) && ((client->botid == 0 && !FD_ISSET(client->clientid, &fds)) || (client->botid && !FD_ISSET(client->botid, &fds2)))) {
-            FD_SET(client->botid, &fds);
+            FD_SET(client->clientid, &fds);
             FD_SET(client->botid, &fds2);
             trigger = get_channel_trigger(client->botid, client->clientid, chan);
             if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
                 handle_command(client, user, chan, message + strlen(trigger));
+                goto got_chanmsg_loop2; //Thats really really bad, i know... But we can't count on the "getBots" list anymore after executing a command
             }
         }
     }