From d885a6cb64765a9dff58db7cddd2dd86d9619a84 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 19 Jun 2015 10:30:41 +0200 Subject: don't join channels til we are authed --- sircbot.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sircbot.c') diff --git a/sircbot.c b/sircbot.c index 1f3e04f..13531ba 100644 --- a/sircbot.c +++ b/sircbot.c @@ -53,6 +53,7 @@ struct sircbot_session { int numchan; time_t last_ping; int runhooks; + int authed; }; struct sircbot_socket_callback { @@ -161,7 +162,7 @@ int init_channel_socket(struct sircbot_channel *chan) goto err_close; if (listen(chan->listen_fd, 8) < 0) - goto err_close; + goto err_close; return 0; @@ -241,7 +242,10 @@ int handle_response(struct sircbot_session *sb, char *user, char *cmd, printf("DEBUG: handling response: user=%s, cmd=%s, data=%s\n", user ? user : "(null)", cmd, data ? data : "(null)"); - if (strncmp(cmd, "PING", 4) == 0) { + if (strncmp(cmd, "001", 3) == 0) { + sb->authed = 1; + printf("DEBUG: authed\n"); + } else if (strncmp(cmd, "PING", 4) == 0) { return irc_send(sb->sess, "PONG", data); } else if (strncmp(cmd, "PONG", 4) == 0) { sb->sess->last_pong = time(NULL); @@ -524,8 +528,6 @@ static int irc_loop(struct sircbot_session *sb) tv.tv_sec = 1; tv.tv_nsec = 0; while (!sigterm) { - if (join_channels(sb) < 0) - goto ret_err; n = irc_reset_pollfds(sb, fds, cbs, maxfds); r = ppoll(fds, n, &tv, &sigmask); if (r < 0) { @@ -553,6 +555,8 @@ static int irc_loop(struct sircbot_session *sb) return r; } + if (sb->authed && join_channels(sb) < 0) + goto ret_err; } return 0; @@ -669,6 +673,7 @@ int main(int argc, char *argv[]) openlog("sircbot",0, LOG_DAEMON); while (1) { + sb.authed = 0; sb.sess = irc_connect(server, port, nick, username, pass); if (sb.sess == NULL) { -- cgit v1.2.3