From e4e29de9a08f1de8c1e7807dc7c684670835f05c Mon Sep 17 00:00:00 2001 From: 8nlight <8nlight@disroot.org> Date: Wed, 23 Aug 2023 19:24:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20ma?= =?UTF-8?q?in.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 81 ---------------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 main.c diff --git a/main.c b/main.c deleted file mode 100644 index 5d06f5a..0000000 --- a/main.c +++ /dev/null @@ -1,81 +0,0 @@ -#include "irc.h" - -//Config -#define HOST "localhost" -#define PORT 6667 -#define NICK "tester134" -char *channels[] = {"#channel"}; - - -#define CHECK_NULL() (client.nick != NULL && client.channel != NULL && client.msg != NULL) -IRCC_client client; - -void die(char *msg) { - puts(msg); - IRCC_close(&client); - exit(1); -} - -void recvinfo(void) { - while (1) { - unsigned int irc_status = IRCC_recv(&client); - if (irc_status == IRCC_DISCONNECTED) - die("Disconnected"); - - else if (irc_status == IRCC_CONNECTED) - return; - - //Print - if (CHECK_NULL() && irc_status == IRCC_PRIVMSG) - printf("[%s %s] %s\n", client.channel, client.nick, client.msg); - - else if (CHECK_NULL() && irc_status == IRCC_NICK) - printf("[N] %s is know as %s\n", client.nick, client.msg); - - else if (CHECK_NULL() && irc_status == IRCC_TOPIC) - printf("[T] %s\n", client.msg); - - else if (client.nick != NULL && irc_status == IRCC_JOIN) - printf("[>] %s\n", client.nick); - - else if (client.nick != NULL && irc_status == IRCC_PART) - printf("[<] %s\n", client.nick); - } -} - -int main(void) { - - //512 - size of raw buffer (max irc) - IRCC_init(&client, IRCC_MSG_MAX); - int status = IRCC_connect(&client, HOST, PORT); - if (status == IRCC_ERROR) - die("Conn refused"); - - //Socket timeout - struct timeval tv = {IRCC_PING_TIMEOUT, IRCC_PING_TIMEOUT}; - if (setsockopt(client.socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) - die("setsockopt"); - - //Register - IRCC_register(&client, NICK); - - //Recv motd and join in channel - recvinfo(); - 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) - die("malloc retured NULL"); - - snprintf(tmp, join_size, "JOIN %s\r\n", channels[i]); - send(client.socket, tmp, join_size, 0); - free(tmp); - } - - recvinfo(); -} -