Esempio n. 1
0
void Channel::handleMUCMessage(gloox::MUCRoom* room, const gloox::Message& msg, bool priv)
{
    if (msg.from().resource() == bot->nick) {
        // The bot got a message from itself.
    }
    else {
        // TODO: Log this.
        std::cout << "[" << room->name() << ": " << msg.from().resource() << "(" << priv << ") ]  " << msg.body() << std::endl;
        bot->processMessage(this, msg, priv);
    }
}
Esempio n. 2
0
void PrivateChat::handleMessage(const gloox::Message& msg, gloox::MessageSession* session)
{
	if(msg.subtype() == gloox::Message::Chat)
		emit reciveMessage(QString().fromUtf8(msg.body().c_str()), QString().fromUtf8((msg.from().full().c_str())));
	else
		emit reciveNotPrivateMessage(QString().fromUtf8(msg.body().c_str()), QString().fromUtf8((msg.from().full().c_str())), QString().fromUtf8((msg.from().resource().c_str())));
}
void SpaceControlClient::handleMessage(const gloox::Message& msg, gloox::MessageSession* session) {
    try {
        // create the command
        // may throw a SpaceCommandFormatException
        const SpaceCommandSerializer::Incoming in = serializer()->to_command(msg.body());
        const std::string threadId(in.first);
        const SpaceCommand cmd = in.second;

        // create shared sink
        Sink sink(threadId, msg.from(), m_client, m_ser);

        // check for access
        if (m_access ? m_access->accepted(msg.from()) : true) {

            // call handler
            if (m_hnd)
                m_hnd->handleSpaceCommand(msg.from(), cmd, &sink);
        } else {
            // send access denied message
            SpaceCommand::space_command_params par;
            par["reason"] = "Denied by access filter!";
            SpaceCommand ex("denied", par);
            sink.sendSpaceCommand(ex);
        }
    } catch (const SpaceCommandFormatException& scfe) {
        SpaceCommand::space_command_params par;
        par["what"] = scfe.what();
        par["body"] = scfe.body();

        // add line number if available
        if (scfe.line_number()) {
// use std::to_string if available
#ifdef COMPILER_SUPPORTS_CXX11
            par["line number"] = std::to_string(scfe.line_number());
#else // COMPILER_SUPPORTS_CXX11
            std::stringstream s;
            s << scfe.line_number();
            par["line number"] = s.str();
#endif // COMPILER_SUPPORTS_CXX11
        }

        SpaceCommand ex("exception", par);

        m_client->send(gloox::Message(gloox::Message::Normal, msg.from(),
                                      serializer()->to_body(ex, "")));
    }
}