Exemplo n.º 1
0
/*
 **************************************************************************************************
 * log_command
 **************************************************************************************************
 *   Write a log entry for a command in the mySQL database.
 *
 *   If serv == LOG_SERVICES, command is ignored, and the paramters are passed on to
 *   log_write, although prefixed with a timestamp, hence use of log_write is
 *   depreceted, and all logging should use log_command.
 *   
 **************************************************************************************************
 * Params:
 *   [IN]  log_type serv      - the services who the command was for (nickserv, chanserv etc)
 *   [IN]  dbase_nicks *from  - The user who issued the command
 *   [IN]  char *command      - The command used
 *   [IN]  char *param        - Parameters to command
 *   [IN]  ...                - variables to param
 **************************************************************************************************
 */
void log_command(log_type serv, dbase_nicks *from, const char *command, const char *param, ...)
{
  char tables[5][15] = {"-", "log_nickserv", "log_chanserv", "log_operserv", "log_multiserv"};
  char modes[5] = {'x', 'v', 'w', 'x', 'y'};
  char buf[BUFFER_SIZE], buf2[2*BUFFER_SIZE];
  
  char rnick_buf[12] = "Not authed", nick_buf[12] = "Services";
  char *rnick = rnick_buf, *nick = nick_buf, *username = nick_buf, *host = NULL;
  
  va_list arglist;
  
  va_start(arglist, param);
  vsnprintf(buf, BUFFER_SIZE, param, arglist);
  va_end(arglist);
  
  if (conf)
    host = conf->host;
    
  if (from)
  {
    nick = from->nick;
    username = from->username;
    host = from->host;
    if (from->nickserv) rnick = from->nickserv->nick;
  }
  
  if (serv == LOG_SERVICES)
  {
    time_t t;
    struct tm *td;
    
#ifdef HAVE_TM_ZONE
    const char *tz;

    t = time(0);
    td = localtime(&t);
    
    tz = td->tm_zone;
#else
    const char *tz = "GMT";

    t = time(0);
    td = gmtime(&t);
#endif    


    log_write("[%2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d (%s)] %s\n", td->tm_mday, (td->tm_mon +1), (td->tm_year + 1900), td->tm_hour, td->tm_min, td->tm_sec, tz, buf);
    return;
  }
 
  if (conf) 
  {
    char *nicks[5] = {conf->os->nick, conf->ns->nick, conf->cs->nick, conf->os->nick, conf->ms->nick};
    dcc_console_text(modes[serv], "[%s!%s!%s@%s] %s: %s %s", rnick, nick, username, host, nicks[serv], command, buf);
  }

  snprintf(buf2, 2*BUFFER_SIZE, "INSERT INTO %s (cmd_date,nick,userhost,command,params) VALUES (%lu,'%s','%s!%s@%s','%s','%s')", tables[serv], (unsigned long)time(0), rnick, nick, username, host, command, buf);
  queue_add(buf2);
}
Exemplo n.º 2
0
void *dcc_init(void *arg)
{
  dcc_init_arg *args = (dcc_init_arg*)arg;
  sock_info *sock;
  dbase_nicks *from;
  
  from = nicks_getinfo(args->num, NULL, -1);
  
  if (!from)
  {
    xfree(args->num);
    xfree(args);
    return 0;
  }
  
  if (!(sock = com_sock_create(SOCK_DCC)))
  {
    xfree(args->num);
    xfree(args);
    return 0;
  }
  
  if (!dcc_init_connect(sock, args->ip, args->port))
  {
    com_free(sock);
    xfree(args->num);
    xfree(args);
    return 0;
  }
  
  sock->from = from;
    
  com_message(sock, conf->os->numeric, from->numeric, MODE_NOTICE, "Welcome to %s DCC interface.", conf->host);
  com_message(sock, conf->os->numeric, from->numeric, MODE_NOTICE, "Compiled %s on %s", build_date, os_name);
  
  dcc_console_text('c', "[%s] connected to the DCC interface...", sock->from->nickserv->nick);

  xfree(args->num);
  xfree(args);
  return 0;
}
Exemplo n.º 3
0
void dcc_on_free(sock_info *sock)
{
  if (!sock) return;
  if (!sock->from) return;
  dcc_console_text('c', "[%s] disconnected from the DCC interface...", sock->from->nickserv->nick);
}