fork extscripts to increase performance & ignore messages coming from bots (NeonSpam)
authorpk910 <philipp@zoelle1.de>
Tue, 1 Nov 2011 15:12:56 +0000 (16:12 +0100)
committerpk910 <philipp@zoelle1.de>
Tue, 1 Nov 2011 15:12:56 +0000 (16:12 +0100)
src/cmd_neonserv_extscript.c
src/event_neonspam_chanmsg.c

index a2202f53d203af3e26b882ad4dba6380c8723a2d..2d7e0bd80c29e3fa9e625d2e89a41ff665c29794 100644 (file)
@@ -114,16 +114,26 @@ CMD_BIND(neonserv_cmd_extscript) {
     FILE *fp;
     fp = popen(command, "r");
     if (fp) {
-        char *a;
-        while (fgets(command, 1024, fp) != NULL) {
-            if((a = strchr(command, '\n'))) 
-                *a = '\0';
-            if(answere_channel) {
-                putsock(client, "PRIVMSG %s :%s", chan->name, command);
-            } else
-                reply(getTextBot(), user, "%s", command);
+        struct ClientSocket *textbot = getTextBot();
+        pid_t pID = fork();
+        if (pID == 0) { //We're the child process :D
+            char *a;
+            while (fgets(command, 1024, fp) != NULL) {
+                if((a = strchr(command, '\n'))) 
+                    *a = '\0';
+                if(answere_channel)
+                    putsock(client, "PRIVMSG %s :%s", chan->name, command);
+                else
+                    reply(textbot, user, "%s", command);
+            }
+            pclose(fp);
+            exit(0);
+        } else if (pID < 0) {
+            reply(getTextBot(), user, "internal bot error - please contact an administrator!");
+            pclose(fp);
+        } else {
+            //parent bot - continue program
         }
-        pclose(fp);
     } else {
         //error
         reply(getTextBot(), user, "internal bot error - please contact an administrator!");
index f5035966ea9680e42a25729acdfd86535d5382db..c20065f617361f13bcd5a2176998282b6a6a21ea 100644 (file)
@@ -36,7 +36,7 @@ struct neonspam_event_chanmsg_cache {
 
 static void neonspam_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
     struct ClientSocket *client = getChannelBot(chan, BOTID);
-    if(!client) return; //we can't "see" this event
+    if(!client || (user->flags & USERFLAG_ISBOT)) return; //we can't "see" this event
     loadNeonSpamSettings(chan);
     struct NeonSpamSettings *settings = chan->spam_settings;
     struct ChanUser *chanuser = getChanUser(user, chan);