int handle_client_connection(t_client_info *client, t_client_info *list, char *cmd, t_channel **channels) { char *buff; buff = strdup(cmd); bzero(cmd, 4096); if (strncmp(buff, "PASS ", 5) == 0) return (0); else if (strncmp(buff, "NICK ", 5) == 0) return (handle_nick(client, buff + 5, list)); else if (strncmp(buff, "USER ", 5) == 0) return (0); else if (strncmp(buff, "JOIN ", 5) == 0) return (join_channel(client, buff + 5, channels)); else if (strncmp(buff, "PART ", 5) == 0) return (part_channel(client, channels)); else if (strncmp(buff, "LIST", 4) == 0) return (list_channels(*channels, cmd, client)); else if (strncmp(buff, "USERS", 5) == 0) return (list_users(client, *channels)); else if (strncmp(buff, "MSG", 3) == 0) return (private_message(client, list, buff)); else return (send_messages(client, *channels, buff)); return (0); }
void ircInterface::onMessage(std::string msg){ /* while(pkge.find("\r\n") != std::string::npos){ std::string msg = pkge.substr(0, pkge.find("\r\n")); pkge = pkge.substr(pkge.find("\r\n") + 2); */ //std::cout << "ircInterface: raw message is : "<<msg<<std::endl; ircLog::instance()->logf(FILENAME, "raw message is: %s", msg.c_str()); //alot of the control strings will start with the type sperated from the //contents of the message with a space std::string type = msg.substr(0, msg.find_first_of(' ')); //first check for messages that start with message names //check for ping if(!type.compare(PING)) { _connStatus->pingRcvd(); sendPong(); return; } else if(!type.compare(ERROR)) { //TODO need to figure out hwat to do here //for now lets just try and not spam the other levels return; } else if(!type.compare("IRCERROR")) { //handle connection errors in conn status _connStatus->connectionIoError(); } //now check for messages that start with nicks or server titles else { _connStatus->pingRcvd(); //type is actually a prefix containing the host mask etc std::string prefix = type; // the actual message past the prefix msg = msg.substr(msg.find_first_of(' ')+1); //the first part of that message should be the type type = msg.substr(0, msg.find_first_of(' ')); //check first to see if it is a private message //most irc messaages are private messages if(!type.compare(PRIVMSG)) { handle_privmsg(msg, prefix); } else if(!type.compare(NOTICE)) { if(_connStatus->state() == CS_IDLE) { _connStatus->connected(); } handle_notice(msg, prefix); } else if(!type.compare(QUIT)) { ircEvent e = handle_quit(msg, prefix); notifyEvent(e); } else if(!type.compare(JOIN)) { ircEvent e = handle_join(msg, prefix); notifyEvent(e); } else if(!type.compare(PART)) { ircEvent e = handle_part(msg, prefix); notifyEvent(e); } else if(!type.compare(NICK)) { ircEvent e = handle_nick(msg, prefix); notifyEvent(e); } else if(!type.compare(INSPIRCDVARS)) { handle_vars(msg); } else if(!type.compare(NICKLIST)) { //add function to parse the nicklist std::vector<ircEvent> e = handle_nicklist(msg); for(unsigned int i = 0; i < e.size(); ++i) { notifyEvent(e[i]); } } else if(!type.compare("001")) { _connStatus->registered(); } } // } }