Exemplo n.º 1
0
void irc_timer()
{ 
  time_t present, delta;
  time(&present);
  sleep(30);

  while (1)
  {
    delta = present - IRC_LAST_ACTIVITY;

    if (delta >= NO_DATA_TIMEOUT) 
    {
      printf(".:. Timeout awaiting data from server .:. \n");
      irc_reconnect();
      time(&IRC_LAST_ACTIVITY);
    }
  }
}
Exemplo n.º 2
0
void receive_message(void* arg)
{
  int irc_socket = con_socket;

  char buffer[512];
  char nick[30];
  char body[256];
  char trash[288];
  while (1) 
  {
    if (socket_read(irc_socket, buffer, 512) > 0)
    {
      //fputs(buffer, stdout);

      if (!strncmp(buffer, "PING ", 5)) 
      {
        buffer[1] = 'O'; //replace char 'I' on 'O' inside 'PING'
        send(irc_socket, buffer, strlen(buffer), 0); //send 'PONG'
      }
      
      if (strstr(buffer, "PRIVMSG #") != NULL) 
      {
        if (sscanf(buffer,"%c%[^!]!%[^:]:%[^\n]\n",trash, nick, trash, body) > 0)
        {
          printf("From %s: %s\n", nick, body);
        }
      }

      if (!strncmp(strchr(buffer, ' ') + 1, "001", 3)) 
      {
        sprintf(buffer, "JOIN %s\r\n", IRC_CHANNEL);
        send(irc_socket, buffer, strlen(buffer), 0);
        printf(".:. Connected to the channel %s .:. \n", IRC_CHANNEL);
        printf(".:. You can send messages directly through the console .:. \n");
      }

      time(&IRC_LAST_ACTIVITY);
    } else 
      {
        irc_reconnect();
      }
  }
}
Exemplo n.º 3
0
static int handle_error(int type, struct irc_handler_info *info)
{
   irc_reconnect(NULL);

   return IRC_OK;
}