From 614470bc94e7d7583939cfc687692e44b22abbe1 Mon Sep 17 00:00:00 2001 From: 8nlight <8nlight@disroot.org> Date: Mon, 7 Aug 2023 18:06:44 +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 Fixed bugs in parser --- C/irc.c | 14 +++++++++----- C/irc.h | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/C/irc.c b/C/irc.c index afc4dc0..c68ecb8 100644 --- a/C/irc.c +++ b/C/irc.c @@ -42,15 +42,16 @@ unsigned int IRCC_register(IRCC_client *irc, const char *nickname){ } void IRCC_parse(char *tmp, IRCC_client *irc){ + irc->raw[strcspn(irc->raw, "\r\n")] = '\0'; if (tmp != NULL){ //Message if (strstr(tmp, ":") != NULL) irc->msg = strstr(tmp, ":"); //Channel - if (strstr(tmp, "#") != NULL){ - irc->channel = strstr(tmp, "#"); - irc->channel[strcspn(irc->channel, " ")] = '\0'; + if (strstr(tmp, " ") != NULL){ + irc->channel = strstr(tmp, " ") + 1; + irc->channel[strcspn(irc->channel, ":") - 1] = '\0'; } //Nickname @@ -77,9 +78,12 @@ unsigned int IRCC_recv(IRCC_client *irc){ else { //puts(irc->raw); - irc->raw[strcspn(irc->raw, "\r\n")] = '\0'; - if (strstr(irc->raw, "PRIVMSG ")){ + //Check end of motd + if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "/MOTD")) + return IRCC_CONNECTED; + + else if (strstr(irc->raw, "PRIVMSG ")){ IRCC_parse(strstr(irc->raw, "PRIVMSG "), irc); return IRCC_PRIVMSG; } diff --git a/C/irc.h b/C/irc.h index 44cd5a5..969e9f8 100644 --- a/C/irc.h +++ b/C/irc.h @@ -9,15 +9,18 @@ #include #include #include -#define IRCC_NICK 8 -#define IRCC_PRIVMSG 7 -#define IRCC_JOIN 6 -#define IRCC_PART 5 -#define IRCC_PING 4 +enum { + IRCC_CONNECTED = 1, + IRCC_NICK, + IRCC_PRIVMSG, + IRCC_JOIN, + IRCC_PART, + IRCC_PING, -#define IRCC_DISCONNECTED 2 -#define IRCC_ERROR 1 -#define IRCC_SUCCESS 0 + IRCC_DISCONNECTED, + IRCC_ERROR, + IRCC_SUCCESS +}; typedef struct { int socket;