Beispiel #1
0
void IRCSession::on_message_received(const IRCMessage &message)
{
/*
	// Do not remove this code.  It is useful to see exactly what the server writes to us.
	IRCRawString s = IRCMessage::create_line(message.get_prefix().to_raw(), message.get_command(), message.get_params());
	cb_system_text(IRCText::from_raw(s.substr(0, s.length()-2)));
*/
	switch (message.get_type())
	{
	case IRCMessage::type_numeric_reply: on_numeric_reply(IRCNumericReply(message)); break;
	case IRCMessage::type_nick: on_nick(IRCNickMessage(message)); break;
	case IRCMessage::type_join: on_join(IRCJoinMessage(message)); break;
	case IRCMessage::type_part: on_part(IRCPartMessage(message)); break;
	case IRCMessage::type_kick: on_kick(IRCKickMessage(message)); break;
	case IRCMessage::type_quit: on_quit(IRCQuitMessage(message)); break;
	case IRCMessage::type_channel_mode: on_channel_mode(IRCChannelModeMessage(message)); break;
	case IRCMessage::type_nick_mode: on_nick_mode(IRCNickModeMessage(message)); break;
	case IRCMessage::type_topic: on_topic(IRCTopicMessage(message)); break;
	case IRCMessage::type_privmsg: on_privmsg(IRCPrivateMessage(message)); break;
	case IRCMessage::type_notice: on_notice(IRCNoticeMessage(message)); break;
	case IRCMessage::type_ping: on_ping(IRCPingMessage(message)); break;
	case IRCMessage::type_unknown:
	default: on_unknown_message(message); break;
	}
}
Beispiel #2
0
///分析服务器回应
void talk_to_svr::analyze_answer(std::string &msg)
{
    if (msg.find("register") == 0)on_register(msg);
    else if (msg.find("login") == 0)on_login(msg);
    else if (msg.find("ping") == 0)on_ping(msg);
    else if (msg.find("ask for clients") == 0)on_ask_client(msg);
    else if (msg.find("send to") == 0)on_sendto(msg);
    else if (msg.find("send from") == 0)on_sendfrom(msg);
    else {
        //funcSelect();
        return; /// 处理错误信息 error answer
    }
}
Beispiel #3
0
/**
 * process_incomming_data: handles a raw irc line minus the \r\n that
 * has already been removed in the handle_receive event.
 * @param line
 */
void Client::process_incomming_data(std::string &line) {
    session_t session;
    int pos;

    line = trim(line);

    //std::cout << "server->'" << line << "'" << std::endl;
        
    // Get the prefix
    if (line.at(0) == ':') {
        if ((pos = line.find(' ')) > 0) {
            session.prefix = line.substr(1, pos - 1);
            line = line.substr(pos);
        }
    }

    line = ltrim(line);

    // Get the code or the command
    session.code = 0;
    if (isdigit(line.at(0)) && isdigit(line.at(1)) && isdigit(line.at(2))) {
        session.code = atoi(line.substr(0, 3).c_str());
        line = line.substr(3);
    } else if ((pos = line.find(' ')) > 0) {
        session.command = line.substr(0, pos);
        line = line.substr(pos);
    } else {
        // just drop line for now.
        return;
    }

    line = ltrim(line);

    // Get the params
    session.param_count = 0;   
    while (line.length() > 0 && session.param_count < 15) {
        // Message
        if (line.at(0) == ':') {
            session.trailing = line.substr(1);
            break;
        }

        // Params
        if ((pos = line.find(' ')) > 0) {
            session.params[session.param_count] = line.substr(0, pos);
            session.param_count++;
            line = line.substr(pos);
            line = ltrim(line);
        } else {
            session.params[session.param_count] = line;
            session.param_count++;
            break;
        }
    }

    //std::cout << "prefix: '" << session.prefix << "', command: '" << session.command << "', code: " << session.code << ", message: '" << session.trailing << "', param_count: " << session.param_count << ", params[0]: '" << session.params[0] << "', params[1]: '" << session.params[1] << "', params[2]: '" << session.params[2] << "'" << std::endl;

    // Handle Codes
    switch (session.code) {
            // We use the MOTD as a signal that we are fully connected to IRC.
        case RPL_ENDOFMOTD:
        case ERR_NOMOTD:
            on_connected();
            break;
        case ERR_NONICKNAMEGIVEN:
        case ERR_ERRONEUSNICKNAME:
        case ERR_NICKNAMEINUSE:
        case ERR_NICKCOLLISION:
            on_nick_error(session);
    }

    // Handle Commands
    if (session.command == "JOIN") on_join(session);
    else if (session.command == "NICK") on_nick(session);
    else if (session.command == "NOTICE") on_notice(session);
    else if (session.command == "PART") on_part(session);
    else if (session.command == "PING") on_ping(session);
    else if (session.command == "PRIVMSG") on_privmsg(session);
    else if (session.command == "QUIT") on_quit(session);

    //std::cout << "---------------------------------------------------------------------------------------------------------------------------" << std::endl;

}