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;