Пример #1
0
/*
	bot_log
	 - forwards to all hubs linked directly if a hub (excluding the one who sent it)
	 - leaf bots display and do not pass along.
*/
static void bot_log(int idx, char *par)
{
  char *from = newsplit(&par);
  int i = nextbot(from);

  if (i != idx) {
    fake_alert(idx, "direction", from, "log");
    return;
  }

  if (egg_isdigit(par[0])) {
    int type = atoi(newsplit(&par));

    if (conf.bot->hub || conf.bot->localhub)
      botnet_send_log(idx, from, type, par);

    if (conf.bot->hub)
      putlog(type, "@", "(%s) %s", from, par);

  } else {
    putlog(LOG_ERRORS, "*", "Malformed HL line from %s: %s", from, par);
  }

} 
Пример #2
0
void putlog(int type, const char *chname, const char *format, ...)
{
  char va_out[LOGLINEMAX + 1] = "";
  va_list va;

  va_start(va, format);
  egg_vsnprintf(va_out, sizeof(va_out), format, va);
  va_end(va);

  if (!va_out[0]) {
    putlog(LOG_ERRORS, "*", "Empty putlog() detected");
    return;
  }

  if (!log_repeated) {
    if (type == last_type && 
        !egg_strncasecmp(chname, last_chname, sizeof(last_chname)) && 
        !egg_strncasecmp(va_out, last_log, sizeof(last_log))) {
      ++log_repeats;

      return;
    }
    if (log_repeats) {
      log_repeated = 1;
      putlog(type, last_chname, "Last message repeated %d times.\n", log_repeats);
      log_repeats = 0;
    }
    strlcpy(last_log, va_out, sizeof(last_log));
    last_type = type;
    strlcpy(last_chname, chname, sizeof(last_chname));
  } else
    log_repeated = 0;

  char *p = NULL;

  if ((p = strchr(va_out, '\n')))		/* make sure no trailing newline */
     *p = 0;

  int idx = 0;
  char out[LOGLINEMAX + 1] = "";

  if (conf.bot && conf.bot->hub) {
    char stamp[34] = "";
    struct tm *t = gmtime(&now);

    egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
    /* Place the timestamp in the string to be printed */
    strlcpy(out, stamp, sizeof(out));
    strlcat(out, " ", sizeof(out));
    strlcat(out, va_out, sizeof(out));
  } else
    strlcpy(out, va_out, sizeof(out));

  /* strcat(out, "\n"); */

#ifdef no
  /* FIXME: WRITE LOG HERE */
  int logfile_masks = LOG_CMDS|LOG_ERRORS|LOG_WARN|LOG_BOTS|LOG_MISC;

  if (logfile_masks && (logfile_masks & type))
    logfile(type, out);
#endif
  /* broadcast to hubs */
  if (chname[0] == '*' && conf.bot && conf.bot->nick)
    botnet_send_log(-1, conf.bot->nick, type, out);

  for (idx = 0; idx < dcc_total; idx++) {
    if (dcc[idx].type && (dcc[idx].type == &DCC_CHAT && dcc[idx].simul == -1) && (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);
    }
  }

  if ((!backgrd) && (!term_z)) {
    dprintf(DP_STDOUT, "%s\n", out);
  } else if ((type & LOG_ERRORS || type & LOG_MISC) && use_stderr) {
    dprintf(DP_STDERR, "%s\n", va_out);
  }
}