src/main.c
changeset 33 56571d34d754
parent 31 bbcb8a3366b4
child 47 a689b6a8e6ed
--- a/src/main.c
+++ b/src/main.c
@@ -14,6 +14,7 @@
 
 #include <mcbot.h>
 #include <config.h>
+#include "common.h"
 
 #ifndef CONFIG_FILE
 #define CONFIG_FILE "/var/lib/mcbot/.mcbotrc"
@@ -35,7 +36,7 @@
 {
     UC uc;
     MSG message;
-    char buf[513];
+    char buf[DEFAULT_BUF_SIZE];
     char *msg;
     char *command;
     int len;
@@ -91,17 +92,15 @@
     }
 
     while (!feof (message.stream)) {
-        *buf = '\0';
-        fgets (buf, 512, message.stream);
+        fgets (buf, sizeof (buf), message.stream);
 
         if (!active)            /* the bot was killed with SIGTERM */
             break;
 
         if ((command = irc_parsemessage (buf, &message))) {
+            if (!strcmp (command, "ERROR") || !strcmp (command, "ENOMEM"))
+                break;
             printf ("%10s %s %s\n", command, message.channel, message.line);
-            if (!strcmp (command, "ERROR") || !strcmp (command, "ENOMEM")) {
-                break;
-            }
         } else {
             if ((msg = parse (&message)) != NULL) {
                 fprintf (message.stream, "%s\r\n", msg);
@@ -109,6 +108,7 @@
                 printf ("%10s %s", "WRITE", msg);
             }
         }
+        fflush (stdout);
     }
     printf ("\n\nClosing Connection\n\n");
     fclose (message.stream);