diff --git a/backends/libircclient-qt/session.cpp b/backends/libircclient-qt/session.cpp index 1d216016..2fcc81a9 100644 --- a/backends/libircclient-qt/session.cpp +++ b/backends/libircclient-qt/session.cpp @@ -204,8 +204,14 @@ void MyIrcBuffer::on_numericMessageReceived(const QString& origin, uint code, co { switch (code) { case 251: - if (suffix.empty()) + if (suffix.empty()) { np->handleConnected(user); + } + if (p->getIdentify().find(" ") != std::string::npos) { + std::string to = p->getIdentify().substr(0, p->getIdentify().find(" ")); + std::string what = p->getIdentify().substr(p->getIdentify().find(" ") + 1); + p->message(QString::fromStdString(to), QString::fromStdString(what)); + } break; case 332: m_topicData = params.value(2).toStdString(); diff --git a/backends/libircclient-qt/session.h b/backends/libircclient-qt/session.h index 326ba4b4..1e1067ce 100644 --- a/backends/libircclient-qt/session.h +++ b/backends/libircclient-qt/session.h @@ -27,6 +27,14 @@ public: std::string suffix; int rooms; + void setIdentify(const std::string &identify) { + m_identify = identify; + } + + const std::string &getIdentify() { + return m_identify; + } + protected Q_SLOTS: void on_connected(); void on_disconnected(); @@ -37,6 +45,7 @@ protected Q_SLOTS: protected: NetworkPlugin *np; std::string user; + std::string m_identify; virtual Irc::Buffer* createBuffer(const QString& receiver); }; diff --git a/backends/libircclient-qt/singleircnetworkplugin.cpp b/backends/libircclient-qt/singleircnetworkplugin.cpp index 64260a23..657251ef 100644 --- a/backends/libircclient-qt/singleircnetworkplugin.cpp +++ b/backends/libircclient-qt/singleircnetworkplugin.cpp @@ -12,6 +12,13 @@ SingleIRCNetworkPlugin::SingleIRCNetworkPlugin(Config *config, Swift::QtEventLoo m_socket->connectToHost(QString::fromStdString(host), port); connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData())); + if (config->getUnregistered().find("service.irc_identify") != config->getUnregistered().end()) { + m_identify = config->getUnregistered().find("service.irc_identify")->second; + } + else { + m_identify = "NickServ identify $name $password"; + } + LOG4CXX_INFO(logger, "SingleIRCNetworkPlugin for server " << m_server << " initialized."); } @@ -39,6 +46,12 @@ void SingleIRCNetworkPlugin::handleLoginRequest(const std::string &user, const s MyIrcSession *session = new MyIrcSession(user, this); session->setNick(QString::fromStdString(legacyName)); session->connectToServer(QString::fromStdString(m_server), 6667); + + std::string identify = m_identify; + boost::replace_all(identify, "$password", password); + boost::replace_all(identify, "$name", legacyName); + session->setIdentify(identify); + m_sessions[user] = session; } diff --git a/backends/libircclient-qt/singleircnetworkplugin.h b/backends/libircclient-qt/singleircnetworkplugin.h index e59499d5..e80dd151 100644 --- a/backends/libircclient-qt/singleircnetworkplugin.h +++ b/backends/libircclient-qt/singleircnetworkplugin.h @@ -36,4 +36,5 @@ class SingleIRCNetworkPlugin : public QObject, public NetworkPlugin { Config *config; QTcpSocket *m_socket; std::string m_server; + std::string m_identify; }; diff --git a/include/transport/conversation.h b/include/transport/conversation.h index 89f3a4ea..d3999d28 100644 --- a/include/transport/conversation.h +++ b/include/transport/conversation.h @@ -74,6 +74,10 @@ class Conversation { m_nickname = nickname; } + const std::string &getNickname() { + return m_nickname; + } + void setJID(const Swift::JID &jid) { m_jid = jid; } diff --git a/src/conversation.cpp b/src/conversation.cpp index 96ae8144..d903e320 100644 --- a/src/conversation.cpp +++ b/src/conversation.cpp @@ -56,10 +56,15 @@ void Conversation::handleMessage(boost::shared_ptr &message, con message->setType(Swift::Message::Chat); } + std::string n = nickname; + if (n.empty() && !m_room.empty() && !m_muc) { + n = m_nickname; + } + if (message->getType() != Swift::Message::Groupchat) { message->setTo(m_jid); // normal message - if (nickname.empty()) { + if (n.empty()) { Buddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName); if (buddy) { message->setFrom(buddy->getJID()); @@ -71,10 +76,10 @@ void Conversation::handleMessage(boost::shared_ptr &message, con // PM message else { if (m_room.empty()) { - message->setFrom(Swift::JID(nickname, m_conversationManager->getComponent()->getJID().toBare(), "user")); + message->setFrom(Swift::JID(n, m_conversationManager->getComponent()->getJID().toBare(), "user")); } else { - message->setFrom(Swift::JID(m_room, m_conversationManager->getComponent()->getJID().toBare(), nickname)); + message->setFrom(Swift::JID(m_room, m_conversationManager->getComponent()->getJID().toBare(), n)); } } m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message); diff --git a/src/conversationmanager.cpp b/src/conversationmanager.cpp index a83803be..ee24ec1c 100644 --- a/src/conversationmanager.cpp +++ b/src/conversationmanager.cpp @@ -90,6 +90,7 @@ void ConversationManager::handleMessageReceived(Swift::Message::ref message) { if (!m_convs[name]) { m_convs[name] = m_component->getFactory()->createConversation(this, name); m_convs[name]->setRoom(room_name); + m_convs[name]->setNickname(name); } }