From 5aa03515c3150973bf5f707cf77accf9ffc792a3 Mon Sep 17 00:00:00 2001 From: 8nlight <8nlight@disroot.org> Date: Wed, 9 Aug 2023 21:54:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index b12ec30..d3936dd 100644 --- a/main.c +++ b/main.c @@ -44,11 +44,14 @@ void WriteToFile(void) { fclose(fp); } -void recvinfo(void) { +void recvinfo(int ignore) { while (1) { unsigned int irc_status = IRCC_recv(&client); - if (irc_status == IRCC_DISCONNECTED) - die("Disconnected"); + if (irc_status == IRCC_DISCONNECTED) { + if (!ignore) + die("Disconnected"); + return; + } else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG) WriteToFile(); @@ -68,14 +71,22 @@ int main(void) { if (status == IRCC_ERROR) die("Conn refused"); - //Register and join in channel - recvinfo(); + //Socket timeout + struct timeval tv = {5, 5}; + if (setsockopt(client.socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) + die("setsockopt"); + + //Register + recvinfo(1); IRCC_register(&client, NICK); //Recv motd and join in channel - recvinfo(); + recvinfo(0); sleep(5); for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) { + if (channels[i] == NULL) + break; + size_t join_size = strlen("JOIN \r\n") + strlen(channels[i]) + 1; char *tmp = malloc(join_size); if (tmp == NULL) @@ -86,5 +97,6 @@ int main(void) { free(tmp); } - recvinfo(); + recvinfo(0); } +