int irc_parse_action(irc_t *irc) { // :msg_prefix msg_irc_command * :msg_command msg_suffix if (!(strchr(irc->servbuf, ' '))) { return 0; // empty msg } irc_log_message(irc); char* ptr = strtok(irc->servbuf, " "); if (ptr != NULL && strncmp(ptr, "PING", 4) == 0) { return sck_sendf(irc->s, "PONG :%s\r\n", ptr); } ptr = strtok(NULL, " "); if (ptr != NULL && strncmp(ptr, "433", 3) == 0) { irc_prepare(irc); return 0; } ptr = strtok(NULL, ":"); ptr = strtok(NULL, " "); if (ptr != NULL && *ptr == '!') { ptr++; // skips '!' char msg_cmd[strlen(ptr)]; strncpy(msg_cmd, ptr, strlen(ptr)); ptr = strtok(NULL, "\0"); return irc_parse_uaction(irc, msg_cmd, ptr, count_args(ptr)); } return 0; }
static int irc_parse_action(irc_t *irc) { if ( strncmp(irc->servbuf, "PING :", 6) == 0 ) { return irc_pong(irc->s, &irc->servbuf[6]); } else if ( strncmp(irc->servbuf, "NOTICE AUTH :", 13) == 0 ) { // Don't care return 0; } else if ( strncmp(irc->servbuf, "ERROR :", 7) == 0 ) { // Still don't care return 0; } else { // Parses IRC message that pulls out nick and message. // Sample: :[email protected] PRIVMSG #bajrden :test char *ptr; int privmsg = 0; char irc_nick[NICK_LEN]; char irc_msg[MSG_LEN]; char irc_chan[CHAN_LEN]; fprintf(stdout, "%s\n", irc->servbuf); // For debugging // Check for non-message string if ( strchr(irc->servbuf, 1) != NULL ) return 0; if ( irc->servbuf[0] == ':' ) { ptr = strtok(irc->servbuf, " !"); if ( ptr == NULL ) { fprintf(stderr, "ptr == NULL\n"); return 0; } else { strncpy(irc_nick, &ptr[1], NICK_LEN-2); irc_nick[NICK_LEN-1] = '\0'; } while ( (ptr = strtok(NULL, " ")) != NULL ) { if ( strncmp(ptr, "PRIVMSG", strlen("PRIVMSG")) == 0 ) { privmsg = 1; break; } } if ( privmsg ) { ptr = strtok(NULL, ":"); strncpy(irc_chan, ptr, CHAN_LEN - 2); if ( (ptr = strtok(NULL, "")) != NULL ) { strncpy(irc_msg, ptr, MSG_LEN - 2); irc_msg[MSG_LEN-1] = '\0'; } } if ( privmsg == 1 && strlen(irc_nick) > 0 && strlen(irc_msg) > 0 ) { //MOdify this irc_log_message(irc, irc_chan, irc_nick, irc_msg); if ( irc_reply_message(irc, irc_chan, irc_nick, irc_msg) < 0 ) return -1; } } } return 0; }
int irc_parse_action(irc_t *irc) { char irc_nick[128]; char irc_msg[512]; if ( strncmp(irc->servbuf, "PING :", 6) == 0 ) { return irc_pong(irc->s, &irc->servbuf[6]); } else if ( strncmp(irc->servbuf, "NOTICE AUTH :", 13) == 0 ) { // Don't care return 0; } else if ( strncmp(irc->servbuf, "ERROR :", 7) == 0 ) { // Still don't care return 0; } // Here be lvl. 42 dragonn boss // Parses IRC message that pulls out nick and message. else { char *ptr; int privmsg = 0; char irc_nick[128]; char irc_msg[512]; *irc_nick = '\0'; *irc_msg = '\0'; // Checks if we have non-message string if ( strchr(irc->servbuf, 1) != NULL ) return 0; if ( irc->servbuf[0] == ':' ) { ptr = strtok(irc->servbuf, "!"); if ( ptr == NULL ) { printf("ptr == NULL\n"); return 0; } else { strncpy(irc_nick, &ptr[1], 127); irc_nick[127] = '\0'; } while ( (ptr = strtok(NULL, " ")) != NULL ) { if ( strcmp(ptr, "PRIVMSG") == 0 ) { privmsg = 1; break; } } if ( privmsg ) { if ( (ptr = strtok(NULL, ":")) != NULL && (ptr = strtok(NULL, "")) != NULL ) { strncpy(irc_msg, ptr, 511); irc_msg[511] = '\0'; } } if ( privmsg == 1 && strlen(irc_nick) > 0 && strlen(irc_msg) > 0 ) { irc_log_message(irc, irc_nick, irc_msg); if ( irc_reply_message(irc, irc_nick, irc_msg) < 0 ) return -1; } } } return 0; }