diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2015-06-19 10:30:41 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2015-06-19 10:33:41 +0200 |
commit | d885a6cb64765a9dff58db7cddd2dd86d9619a84 (patch) | |
tree | 46692b4d8dd8a0ecf6db2f98736d7ba9b5b85150 /sircbot.c | |
parent | 26bf2b6c79378ca8cdc63c71b1d9ac97044f1c0b (diff) | |
download | sircbot-d885a6cb64765a9dff58db7cddd2dd86d9619a84.tar.bz2 sircbot-d885a6cb64765a9dff58db7cddd2dd86d9619a84.tar.xz |
don't join channels til we are authed
Diffstat (limited to 'sircbot.c')
-rw-r--r-- | sircbot.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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) { |