IRC backends work again
This commit is contained in:
parent
9b03ad3f30
commit
bc3971f7d2
7 changed files with 108 additions and 58 deletions
|
@ -54,7 +54,7 @@ find_package(event)
|
|||
find_package(Doxygen)
|
||||
|
||||
INCLUDE(FindQt4)
|
||||
FIND_PACKAGE(Qt4 COMPONENTS QtCore)
|
||||
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtNetwork)
|
||||
|
||||
# ADD_DEFINITIONS(${SWIFTEN_CFLAGS})
|
||||
ADD_DEFINITIONS(-DSUPPORT_LEGACY_CAPS)
|
||||
|
|
64
backends/libircclient-qt/ircnetworkplugin.cpp
Normal file
64
backends/libircclient-qt/ircnetworkplugin.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include "ircnetworkplugin.h"
|
||||
|
||||
IRCNetworkPlugin::IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) {
|
||||
this->config = config;
|
||||
m_socket = new QTcpSocket();
|
||||
m_socket->connectToHost(QString::fromStdString(host), port);
|
||||
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::readData() {
|
||||
size_t availableBytes = m_socket->bytesAvailable();
|
||||
if (availableBytes == 0)
|
||||
return;
|
||||
|
||||
std::cout << "READ\n";
|
||||
std::string d = std::string(m_socket->readAll().data(), availableBytes);
|
||||
handleDataRead(d);
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::sendData(const std::string &string) {
|
||||
m_socket->write(string.c_str(), string.size());
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
|
||||
MyIrcSession *session = new MyIrcSession(user, this);
|
||||
std::string h = user.substr(0, user.find("@"));
|
||||
session->setNick(QString::fromStdString(h.substr(0, h.find("%"))));
|
||||
session->connectToServer(QString::fromStdString(h.substr(h.find("%") + 1)), 6667);
|
||||
std::cout << "CONNECTING IRC NETWORK " << h.substr(h.find("%") + 1) << "\n";
|
||||
m_sessions[user] = session;
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::handleLogoutRequest(const std::string &user, const std::string &legacyName) {
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->disconnectFromServer();
|
||||
m_sessions[user]->deleteLater();
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &/*xhtml*/) {
|
||||
std::cout << "MESSAGE " << user << " " << legacyName << "\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->message(QString::fromStdString(legacyName), QString::fromStdString(message));
|
||||
std::cout << "SENT\n";
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password) {
|
||||
std::cout << "JOIN\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->addAutoJoinChannel(QString::fromStdString(room));
|
||||
m_sessions[user]->join(QString::fromStdString(room), QString::fromStdString(password));
|
||||
// update nickname, because we have nickname per session, no nickname per room.
|
||||
handleRoomNicknameChanged(user, room, m_sessions[user]->nick().toStdString());
|
||||
}
|
||||
|
||||
void IRCNetworkPlugin::handleLeaveRoomRequest(const std::string &user, const std::string &room) {
|
||||
std::cout << "PART\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->part(QString::fromStdString(room));
|
||||
m_sessions[user]->removeAutoJoinChannel(QString::fromStdString(room));
|
||||
}
|
38
backends/libircclient-qt/ircnetworkplugin.h
Normal file
38
backends/libircclient-qt/ircnetworkplugin.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "session.h"
|
||||
#include <QtCore>
|
||||
#include <QtNetwork>
|
||||
#include "Swiften/EventLoop/Qt/QtEventLoop.h"
|
||||
#include "ircnetworkplugin.h"
|
||||
|
||||
|
||||
class IRCNetworkPlugin : public QObject, public NetworkPlugin {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port);
|
||||
|
||||
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password);
|
||||
|
||||
void handleLogoutRequest(const std::string &user, const std::string &legacyName);
|
||||
|
||||
void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &/*xhtml*/);
|
||||
|
||||
void handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password);
|
||||
|
||||
void handleLeaveRoomRequest(const std::string &user, const std::string &room);
|
||||
|
||||
std::map<std::string, MyIrcSession *> m_sessions;
|
||||
|
||||
public slots:
|
||||
void readData();
|
||||
void sendData(const std::string &string);
|
||||
|
||||
private:
|
||||
Config *config;
|
||||
QTcpSocket *m_socket;
|
||||
};
|
|
@ -12,67 +12,15 @@
|
|||
#include "transport/networkplugin.h"
|
||||
#include "session.h"
|
||||
#include <QtCore>
|
||||
#include <QtNetwork>
|
||||
#include "Swiften/EventLoop/Qt/QtEventLoop.h"
|
||||
#include "ircnetworkplugin.h"
|
||||
|
||||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
||||
class IRCNetworkPlugin;
|
||||
IRCNetworkPlugin * np = NULL;
|
||||
|
||||
class IRCNetworkPlugin : public NetworkPlugin {
|
||||
public:
|
||||
IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
|
||||
this->config = config;
|
||||
}
|
||||
|
||||
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
|
||||
MyIrcSession *session = new MyIrcSession(user, this);
|
||||
session->setNick(QString::fromStdString(user.substr(0, user.find("@"))));
|
||||
session->connectToServer(QString::fromStdString(user.substr(user.find("@") + 1)), 6667);
|
||||
// std::cout << "CONNECTING IRC NETWORK " << jid.getNode() << " " << jid.getDomain() << "\n";
|
||||
m_sessions[user] = session;
|
||||
}
|
||||
|
||||
void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->disconnectFromServer();
|
||||
m_sessions[user]->deleteLater();
|
||||
}
|
||||
|
||||
void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &/*xhtml*/) {
|
||||
std::cout << "MESSAGE " << user << " " << legacyName << "\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->message(QString::fromStdString(legacyName), QString::fromStdString(message));
|
||||
std::cout << "SENT\n";
|
||||
}
|
||||
|
||||
void handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password) {
|
||||
std::cout << "JOIN\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->addAutoJoinChannel(QString::fromStdString(room));
|
||||
m_sessions[user]->join(QString::fromStdString(room), QString::fromStdString(password));
|
||||
// update nickname, because we have nickname per session, no nickname per room.
|
||||
handleRoomNicknameChanged(user, room, m_sessions[user]->nick().toStdString());
|
||||
}
|
||||
|
||||
void handleLeaveRoomRequest(const std::string &user, const std::string &room) {
|
||||
std::cout << "PART\n";
|
||||
if (m_sessions[user] == NULL)
|
||||
return;
|
||||
m_sessions[user]->part(QString::fromStdString(room));
|
||||
m_sessions[user]->removeAutoJoinChannel(QString::fromStdString(room));
|
||||
}
|
||||
|
||||
std::map<std::string, MyIrcSession *> m_sessions;
|
||||
|
||||
private:
|
||||
Config *config;
|
||||
};
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
std::string host;
|
||||
int port;
|
||||
|
|
|
@ -217,7 +217,6 @@ class NetworkPlugin {
|
|||
|
||||
|
||||
private:
|
||||
void connect();
|
||||
void handleLoginPayload(const std::string &payload);
|
||||
void handleLogoutPayload(const std::string &payload);
|
||||
void handleStatusChangedPayload(const std::string &payload);
|
||||
|
|
|
@ -11,10 +11,10 @@ admin_password=test
|
|||
#cert=server.pfx #patch to PKCS#12 certificate
|
||||
#cert_password=test #password to that certificate if any
|
||||
users_per_backend=10
|
||||
backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend
|
||||
#backend=/home/hanzz/code/libtransport/backends/libpurple/spectrum2_libpurple_backend
|
||||
#backend=/usr/bin/mono /home/hanzz/code/networkplugin-csharp/msnp-sharp-backend/bin/Debug/msnp-sharp-backend.exe
|
||||
#backend=/home/hanzz/code/libtransport/backends/frotz/spectrum2_frotz_backend
|
||||
#backend=../../backends/libircclient-qt/spectrum2_libircclient-qt_backend
|
||||
backend=/home/hanzz/code/libtransport/backends/libircclient-qt/spectrum2_libircclient-qt_backend
|
||||
#protocol=prpl-msn
|
||||
protocol=any
|
||||
#protocol=prpl-icq
|
||||
|
|
|
@ -355,6 +355,7 @@ void NetworkPluginServer::handleConnectedPayload(const std::string &data) {
|
|||
|
||||
User *user = m_userManager->getUser(payload.user());
|
||||
if (!user) {
|
||||
LOG4CXX_ERROR(logger, "Connected payload received for unknown user " << payload.user());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue