aboutsummaryrefslogtreecommitdiff
path: root/irc.c
diff options
context:
space:
mode:
Diffstat (limited to 'irc.c')
-rw-r--r--irc.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/irc.c b/irc.c
index 5af46ae..065cee0 100644
--- a/irc.c
+++ b/irc.c
@@ -49,9 +49,21 @@ irc_sendall(char msg[], size_t len)
int
irc_handshake()
-{
- char msg[] = "NICK "NICK"\r\nUSER "USERNAME" 0 * :"REALNAME"\r\nJOIN "CHANNEL"\r\n";
- return irc_sendall(msg, sizeof msg-1);
+{
+ #define E(x) do { if (x==-1) { perror("irc_sendall"); return -1; } } while(0)
+ char msg1[] = "NICK "NICK"\r\nUSER "USERNAME" 0 * :"REALNAME"\r\n";
+ E(irc_sendall(msg1, sizeof msg1-1));
+ for (int i = 0; CHANNELS[i] != NULL; i++) {
+ if (strlen(CHANNELS[i]) > 16) {
+ fprintf(stderr,"channel name too long (%s)\n",CHANNELS[i]);
+ return -1;
+ }
+ E(irc_sendall("JOIN #",6));
+ E(irc_sendall(CHANNELS[i],strlen(CHANNELS[i])));
+ E(irc_sendall("\r\n",2));
+ }
+ #undef E
+ return 0;
}
@@ -99,6 +111,7 @@ char *recv_end = &recv_buf[RECVBUF_SIZE];
// then cur points to one past the most recently recieved byte.
// after processing a message, if there's more stuff in the buffer, memmove it back.
+// returns -2 on eof, -1 on other error, 0 on success
int
irc_recv()
{
@@ -110,7 +123,7 @@ irc_recv()
} else if (amt == 0) {
// eof
fprintf(stderr,"irc eof\n");
- return -1;
+ return -2;
}
DPf("recieved %ld ",amt);