xbot/src/main.c

49 lines
776 B
C
Raw Normal View History

2015-03-24 10:12:35 +00:00
/*
* xbot: Just another IRC bot
*
* Written by Aaron Blakely <aaron@ephasic.org>
**/
#include <stdio.h>
#include <string.h>
2015-04-07 18:18:24 +00:00
#include <stdlib.h>
2015-03-24 10:12:35 +00:00
#include <sys/select.h>
2015-04-07 18:18:24 +00:00
#include "config.h"
2015-03-24 10:12:35 +00:00
#include "irc.h"
2015-03-26 23:20:59 +00:00
#include "util.h"
#include "events.h"
2015-03-24 10:12:35 +00:00
int main()
{
fd_set rd;
struct irc_conn bot;
2015-03-26 23:20:59 +00:00
init_events();
2015-04-07 18:18:24 +00:00
// Read the config
bot = read_config(bot, "xbot.cfg");
2015-03-24 17:48:11 +00:00
2015-03-24 10:12:35 +00:00
// Connect to the server
printf("Connecting to %s...\n", bot.host);
irc_connect(&bot);
irc_auth(&bot);
for (;;)
{
FD_ZERO(&rd);
FD_SET(fileno(bot.srv_fd), &rd);
if (FD_ISSET(fileno(bot.srv_fd), &rd))
{
if (fgets(bot.in, sizeof bot.in, bot.srv_fd) == NULL)
{
eprint("xbot: remote host closed connection\n");
2015-04-18 15:51:15 +00:00
return 0;
2015-03-24 10:12:35 +00:00
}
irc_parse_raw(&bot, bot.in);
}
}
return 0;
}