aboutsummaryrefslogtreecommitdiff
path: root/irc.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-10-29 03:51:48 +0100
committerubq323 <ubq323@ubq323.website>2022-10-29 03:51:54 +0100
commit86dac1e342e0b5b52dbd68152cdc8d5a60128ce8 (patch)
treefa8c383b468918b948a9fb5aadc3a1ef75a96b14 /irc.c
parent8e7e23110bc483ba647d33d6f46a7fac1302107c (diff)
functionality. (it is functionally equivalent to the old version now)
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);