Updates, now working again.

This commit is contained in:
Aaron Blakely 2016-02-21 22:40:41 -06:00
parent e7f3aba195
commit f96b0e7695
4 changed files with 41 additions and 8 deletions

View File

@ -13,8 +13,6 @@ struct irc_conn
{
FILE *srv_fd;
char nick[32];
char *admin;
char host[256];

View File

@ -59,8 +59,9 @@ void irc_connect(struct irc_conn *bot)
void irc_auth(struct irc_conn *bot)
{
irc_raw(bot, "NICK %s", bot->nick);
irc_raw(bot, "USER %s localhost %s :xbot (v0.1) - developed by @Dark_Aaron", bot->nick, bot->host);
irc_raw(bot, "USER %s \" %s :xbot (v0.1) - developed by @Dark_Aaron", bot->nick, bot->host);
fflush(bot->srv_fd);
setbuf(bot->srv_fd, NULL);
}
void irc_notice(struct irc_conn *bot, char *to, char *fmt, ...)

View File

@ -8,15 +8,22 @@
#include <string.h>
#include <stdlib.h>
#include <sys/select.h>
#include <time.h>
#include <errno.h>
#include "config.h"
#include "irc.h"
#include "util.h"
#include "events.h"
static time_t trespond;
int main()
{
int n;
fd_set rd;
struct irc_conn bot;
struct timeval tv;
init_events();
@ -31,8 +38,34 @@ int main()
for (;;)
{
FD_ZERO(&rd);
FD_SET(0, &rd);
FD_SET(fileno(bot.srv_fd), &rd);
tv.tv_sec = 120;
tv.tv_usec = 0;
n = select(fileno(bot.srv_fd) + 1, &rd, 0, 0, &tv);
if (n < 0)
{
if (errno == EINTR)
continue;
eprint("xbot: error on select()\n");
return 0;
}
else if (n == 0)
{
if (time(NULL) - trespond >= 300)
{
eprint("xbot shutting down: parse timeout\n");
return -1;
}
irc_raw(&bot, "PING %s", bot.host);
continue;
}
if (FD_ISSET(fileno(bot.srv_fd), &rd))
{
if (fgets(bot.in, sizeof bot.in, bot.srv_fd) == NULL)
@ -42,6 +75,7 @@ int main()
}
irc_parse_raw(&bot, bot.in);
trespond = time(NULL);
}
}

View File

@ -10,7 +10,7 @@ bot:
server:
{
host = "irc.alphachat.net";
host = "irc-nb.bbsn.ca";
port = "6667";
};
@ -20,5 +20,5 @@ mods:
blacklist = ();
# config option for mods/autojoin.so
mod_autojoin = ("#ircbots");
mod_autojoin = ("#drones");
};