From f96b0e769500d7b09c95e90f5a65609e4e838853 Mon Sep 17 00:00:00 2001 From: Aaron Blakely Date: Sun, 21 Feb 2016 22:40:41 -0600 Subject: [PATCH] Updates, now working again. --- lib/irc.h | 4 +--- src/irc.c | 5 +++-- src/main.c | 36 +++++++++++++++++++++++++++++++++++- xbot.cfg | 4 ++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/irc.h b/lib/irc.h index dadda5a..ccd4759 100644 --- a/lib/irc.h +++ b/lib/irc.h @@ -13,8 +13,6 @@ struct irc_conn { FILE *srv_fd; - - char nick[32]; char *admin; char host[256]; @@ -34,4 +32,4 @@ void irc_privmsg(struct irc_conn *bot, char *to, char *fmt, ...); void irc_raw(struct irc_conn *bot, char *fmt, ...); void irc_parse_raw(struct irc_conn *bot, char *raw); -#endif \ No newline at end of file +#endif diff --git a/src/irc.c b/src/irc.c index b2e7ac6..8ce7a76 100644 --- a/src/irc.c +++ b/src/irc.c @@ -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, ...) @@ -163,4 +164,4 @@ void irc_parse_raw(struct irc_conn *bot, char *raw) strlcpy(bot->nick, text, sizeof bot->nick); } } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c index af12ee1..5f4c90f 100644 --- a/src/main.c +++ b/src/main.c @@ -8,15 +8,22 @@ #include #include #include +#include +#include #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,8 +75,9 @@ int main() } irc_parse_raw(&bot, bot.in); + trespond = time(NULL); } } return 0; -} \ No newline at end of file +} diff --git a/xbot.cfg b/xbot.cfg index 611764a..8f04c54 100644 --- a/xbot.cfg +++ b/xbot.cfg @@ -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"); };