Esempio n. 1
0
static bool
dispatch_handler(int fd, struct ircmsg *msg)
{
    switch (msg->type) {
      case IRCMSG_UNKNOWN:  return true;
      case IRCMSG_PING:     return handle_ping(fd, &msg->u.ping);
      case IRCMSG_PART:     return handle_part(fd, &msg->u.part);
      case IRCMSG_JOIN:     return handle_join(fd, &msg->u.join);
      case IRCMSG_PRIVMSG:  return handle_privmsg(fd, &msg->u.privmsg);
      case IRCMSG_KICK:     return handle_kick(fd, &msg->u.kick);
      default:              return false;
    }
}
Esempio n. 2
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();
			}
		}
//	}
}