From ad09f6fba5e79db48750316c204f345de3b06283 Mon Sep 17 00:00:00 2001 From: 8nlight <8nlight@disroot.org> Date: Wed, 9 Aug 2023 21:53:12 +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?C=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- C/irc.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/C/irc.c b/C/irc.c index c68ecb8..9831f7f 100644 --- a/C/irc.c +++ b/C/irc.c @@ -5,6 +5,7 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p if (!ghbn) return IRCC_ERROR; + //Only ipv4 struct sockaddr_in client_str; memset(&client_str, 0, sizeof(client_str)); client_str.sin_family = AF_INET; @@ -23,18 +24,14 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p } unsigned int IRCC_register(IRCC_client *irc, const char *nickname){ - size_t size = strlen("USER \r\n 0 0 ") + strlen(nickname) + strlen(nickname); - char *tmp = (char *)malloc(size + 1); + size_t size = strlen("NICK %s\r\nUSER %s 0 localhost :%s \r\n") + (strlen(nickname) * 3); + char *tmp = (char *)malloc(size); if (tmp == NULL){ fprintf(stderr, "malloc returned NULL (IRCC_register)\n"); exit(1); } - sleep(2); - snprintf(tmp, size, "USER %s 0 0 %s\r\n", nickname, nickname); - send(irc->socket, tmp, strlen(tmp), 0); - - snprintf(tmp, size, "NICK %s\r\n", nickname); + snprintf(tmp, size, "NICK %s\r\nUSER %s 0 localhost :%s\r\n", nickname, nickname, nickname); send(irc->socket, tmp, strlen(tmp), 0); free(tmp); @@ -80,9 +77,10 @@ unsigned int IRCC_recv(IRCC_client *irc){ //puts(irc->raw); //Check end of motd - if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "/MOTD")) + if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "MOTD")) return IRCC_CONNECTED; + //Other else if (strstr(irc->raw, "PRIVMSG ")){ IRCC_parse(strstr(irc->raw, "PRIVMSG "), irc); return IRCC_PRIVMSG; @@ -136,9 +134,7 @@ unsigned int IRCC_init(IRCC_client *irc, size_t size){ exit(1); } - irc->msg = NULL; - irc->nick = NULL; - irc->channel = NULL; + irc->msg = irc->nick = irc->channel = NULL; irc->size = size; return IRCC_SUCCESS; @@ -148,10 +144,7 @@ void IRCC_close(IRCC_client *irc){ close(irc->socket); free(irc->raw); - irc->raw = NULL; - irc->msg = NULL; - irc->nick = NULL; - irc->channel = NULL; + irc->raw = irc->msg = irc->nick = irc->channel = NULL; irc->size = 0; }