Working IRC nickserv + PMs
This commit is contained in:
parent
5424e5c686
commit
ff3adaa3f3
7 changed files with 43 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,4 +36,5 @@ class SingleIRCNetworkPlugin : public QObject, public NetworkPlugin {
|
|||
Config *config;
|
||||
QTcpSocket *m_socket;
|
||||
std::string m_server;
|
||||
std::string m_identify;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -56,10 +56,15 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &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<Swift::Message> &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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue