Răsfoiți Sursa

* grrrrrrrah
* Rewrote putlog()
* Fixed a check_bind/"bot" bug... need to implement 1.7 get_words()


svn: 718

Bryan Drewery 22 ani în urmă
părinte
comite
1e88e6e6cd
7 a modificat fișierele cu 70 adăugiri și 49 ștergeri
  1. 25 11
      src/botcmd.c
  2. 11 10
      src/botmsg.c
  3. 1 1
      src/dcc.c
  4. 1 1
      src/debug.c
  5. 28 23
      src/log.c
  6. 2 1
      src/misc.c
  7. 2 2
      src/net.c

+ 25 - 11
src/botcmd.c

@@ -977,11 +977,19 @@ static void bot_thisbot(int idx, char *par)
   strcpy(dcc[idx].nick, par);
 }
 
-static void bot_hublog(char *botnick, char *code, char *par)
+static void bot_hublog(char *botnick, char *code, char *msg)
 {
 #ifdef HUB
-  int type = atoi(newsplit(&par));
-  putlog(type, "@", "(%s) %s", botnick, par);
+  char *par = NULL, *parp;
+  par = parp = strdup(msg);
+  if (egg_isdigit(par[0])) {
+    int type = atoi(newsplit(&par));
+
+    putlog(type, "@", "(%s) %s", botnick, par);
+  } else {
+    putlog(LOG_ERRORS, "*", "Malformed HL line from %s: %s %s", botnick, code, par);
+  }
+  free(parp);
 #endif /* HUB */
 }
 
@@ -1351,12 +1359,13 @@ void send_remote_simul(int idx, char *bot, char *cmd, char *par)
 }
 
 /* idx nick conmask cmd par */
-static void bot_rsim(char *botnick, char *code, char *par)
+static void bot_rsim(char *botnick, char *code, char *msg)
 {
   int ridx = -1, idx = -1, i = 0, rconmask;
   unsigned long status = 0;
-  char *nick = NULL, *cmd = NULL, *rconchan = NULL, buf[UHOSTMAX] = "";
+  char *nick = NULL, *cmd = NULL, *rconchan = NULL, buf[UHOSTMAX] = "", *par = NULL, *parp = NULL;
 
+  par = parp = strdup(msg);
   ridx = atoi(newsplit(&par));
   nick = newsplit(&par);
   rconmask = atoi(newsplit(&par));
@@ -1364,8 +1373,10 @@ static void bot_rsim(char *botnick, char *code, char *par)
   if (egg_isdigit(par[0]))
     status = (unsigned long) atoi(newsplit(&par));
   cmd = newsplit(&par);
-  if (ridx < 0 || !nick || !cmd)
+  if (ridx < 0 || !nick || !cmd) {
+    free(parp);
     return;
+  }
 
   for (i = 0; i < dcc_total; i++) {
    if (dcc[i].simul == ridx) {
@@ -1396,6 +1407,7 @@ static void bot_rsim(char *botnick, char *code, char *par)
   }
   rmspace(par);
   check_bind_dcc(cmd, idx, par);
+  free(parp);
 }
 
 void bounce_simul(int idx, char *buf)
@@ -1410,13 +1422,15 @@ void bounce_simul(int idx, char *buf)
 }
 
 #ifdef HUB
-static void bot_rsimr(char *botnick, char *code, char *par)
+static void bot_rsimr(char *botnick, char *code, char *msg)
 {
-  int idx = atoi(newsplit(&par));
+  if (msg[0]) {
+    char *par = strdup(msg), *parp = par;
+    int idx = atoi(newsplit(&par));
 
-  if (!par[0])
-    return;
-  dprintf(idx, "[%s] %s\n", botnick, par);
+    dprintf(idx, "[%s] %s\n", botnick, par);
+    free(parp);
+  }
 }
 #endif /* HUB */
 

+ 11 - 10
src/botmsg.c

@@ -436,6 +436,17 @@ void botnet_send_zapf(int idx, char *a, char *b, char *c)
   l = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
   tputs(dcc[idx].sock, OBUF, l);
 }
+
+void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
+{
+  int l;
+
+  if (tands > 0) {
+    l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
+    send_tand_but(idx, OBUF, l);
+  }
+}
+
 void botnet_send_cfg(int idx, struct cfg_entry * entry) {
   int l;
 
@@ -451,16 +462,6 @@ void botnet_send_cfg_broad(int idx, struct cfg_entry * entry) {
   }
 }
 
-void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
-{
-  int l;
-
-  if (tands > 0) {
-    l = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
-    send_tand_but(idx, OBUF, l);
-  }
-}
-
 void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
 {
   int l;

+ 1 - 1
src/dcc.c

@@ -500,7 +500,7 @@ static void dcc_bot(int idx, char *code, int i)
       if (code[0] == 's')
         putlog(LOG_BOTSHARE, "@", "{%s} %s", dcc[idx].nick, code + 2);
       else
-        putlog(LOG_BOTNET, "@", "[%s] %s", dcc[idx].nick, code);
+        putlog(LOG_BOTNET, "@", "<-[%s] %s", dcc[idx].nick, code);
 /*     } */
   }
   msg = strchr(code, ' ');

+ 1 - 1
src/debug.c

@@ -94,7 +94,7 @@ void sdprintf (char *format, ...)
     if (!backgrd)
       dprintf(DP_STDOUT, "[D:%d] %s%s%s\n", getpid(), BOLD(-1), s, BOLD_END(-1));
     else
-      putlog(LOG_MISC, "*", "[D:%d] %s%s%s", getpid(), BOLD(-1), s, BOLD_END(-1));
+      printf("[D:%d] %s%s%s\n", getpid(), BOLD(-1), s, BOLD_END(-1));
   }
 }
 

+ 28 - 23
src/log.c

@@ -224,12 +224,13 @@ char *maskname(int x)
  */
 void putlog(int type, char *chname, char *format, ...)
 {
-  int idx, tsl = 0;
-  char s[LOGLINELEN] = "", *out = NULL, stamp[34] = "";
-  va_list va;
+  int idx = 0;
+  char va_out[LOGLINEMAX + 1] = "", out[LOGLINEMAX + 1] = "", *p = NULL;
 #ifdef HUB
+  char stamp[34] = "";
   struct tm *t = NULL;
 #endif /* HUB */
+  va_list va;
 
   va_start(va, format);
 #ifdef HUB
@@ -239,42 +240,47 @@ void putlog(int type, char *chname, char *format, ...)
   t = localtime(&now);
 # endif /* S_UTCTIME */
 
-  egg_strftime(stamp, sizeof(stamp) - 2, LOG_TS, t);
-  strcat(stamp, " ");
-  tsl = strlen(stamp);
+  egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
 #endif /* HUB */
 
-  /* Format log entry at offset 'tsl,' then i can prepend the timestamp */
-  out = s + tsl;
-
   /* No need to check if out should be null-terminated here,
    * just do it! <cybah>
    */
-
-  egg_vsnprintf(out, LOGLINEMAX - tsl, format, va);
+  egg_vsnprintf(va_out, LOGLINEMAX, format, va);
   va_end(va);
 
-  out[LOGLINEMAX - tsl] = 0;
+  if (!va_out[0]) {
+    putlog(LOG_ERRORS, "*", "Empty putlog() detected");
+    return;
+  }
+
+  if ((p = strchr(va_out, '\n')))		/* make sure no trailing newline */
+     *p = 0;
 
+
+#ifdef HUB
   /* Place the timestamp in the string to be printed */
-  if (out[0]) {
-    strncpy(s, stamp, tsl);
-    out = s;
-  }
+  if (stamp[0])
+    egg_snprintf(out, sizeof out, "%s %s", stamp, va_out);
+#endif /* HUB */
+#ifdef LEAF
+  egg_snprintf(out, sizeof out, "%s", va_out);
+#endif /* LEAF */
+
+  /* strcat(out, "\n"); */
 
-  strcat(out, "\n");
   /* FIXME: WRITE LOG HERE */
 
   /* broadcast to hubs */
   if (chname[0] == '*' && conf.bot && conf.bot->nick) {
-    char outbuf[LOGLINEMAX] = "";
+    char outbuf[LOGLINEMAX + 1] = "";
 
     egg_snprintf(outbuf, sizeof outbuf, "hl %d %s", type, out);
     if (userlist && !loading) {
       tand_t *bot = NULL;
       struct userrec *ubot = NULL;
 
-      for (bot = tandbot ; bot; bot = bot->next) {
+      for (bot = tandbot; bot; bot = bot->next) {
         if ((ubot = get_user_by_handle(userlist, bot->bot))) {
           if (bot_hublevel(ubot) < 999)
             putbot(ubot->handle, outbuf);
@@ -289,15 +295,14 @@ void putlog(int type, char *chname, char *format, ...)
     if ((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", out);
+        dprintf(idx, "%s\n", out);
     }
   }
 
   if ((!backgrd) && (!term_z)) {
-    dprintf(DP_STDOUT, "%s", out);
+    dprintf(DP_STDOUT, "%s\n", out);
   } else if ((type & LOG_ERRORS || type & LOG_MISC) && use_stderr) {
-    out += tsl;
-    dprintf(DP_STDERR, "%s", s);
+    dprintf(DP_STDERR, "%s\n", va_out);
   }
 }
 

+ 2 - 1
src/misc.c

@@ -1348,7 +1348,8 @@ char *color(int idx, int type, int color)
   /* if user is connected over TELNET or !backgrd, show ANSI
    * if they are relaying, they are most likely on an IRC client and should have mIRC codes
    */
-  if ((idx && ((dcc[idx].type != &DCC_RELAYING) && (dcc[idx].status & STAT_TELNET))) || (idx == -1 || !backgrd)) ansi++;
+  if ((idx && (idx != -1 && (dcc[idx].type != &DCC_RELAYING) && (dcc[idx].status & STAT_TELNET))) 
+     || (idx == -1 || !backgrd)) ansi++;
 
   if (type == BOLD_OPEN) {
     return ansi ? "\033[1m" : "\002";

+ 2 - 2
src/net.c

@@ -1267,8 +1267,8 @@ char *botlink_encrypt(int snum, char *src)
 {
   char *srcbuf = NULL, *buf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
   int bufpos = 0, i = 0;
-  
-  srcbuf = malloc(strlen(src) + 9 + 1);
+
+  srcbuf = calloc(1, strlen(src) + 9 + 1);
   strcpy(srcbuf, src);
   line = srcbuf;
   if (!line) {