Changeset - 8e03fbec4701
[Not reviewed]
0 10 0
Jan Kaluza - 14 years ago 2011-05-19 08:26:09
hanzz.k@gmail.com
Working part, moderators resending
10 files changed with 84 insertions and 18 deletions:
0 comments (0 inline, 0 general)
backends/libircclient-qt/main.cpp
Show inline comments
 
@@ -44,48 +44,49 @@ class IRCNetworkPlugin : public NetworkPlugin {
 

	
 
		void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) {
 
			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.
 
			handleRoomChanged(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;
 

	
 

	
 
	boost::program_options::options_description desc("Usage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
 
	desc.add_options()
 
		("host,h", value<std::string>(&host), "host")
 
		("port,p", value<int>(&port), "port")
 
		;
 
	try
 
	{
 
		boost::program_options::variables_map vm;
 
		boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
 
		boost::program_options::notify(vm);
 
	}
backends/libircclient-qt/session.cpp
Show inline comments
 
/*
 
 * Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
 
 *
 
 * This example is free, and not covered by LGPL license. There is no
 
 * restriction applied to their modification, redistribution, using and so on.
 
 * You can study them, modify them, use them in your own program - either
 
 * completely or partially. By using it you may give me some credits in your
 
 * program, but you don't have to.
 
 */
 

	
 
#include "session.h"
 
#include <QtCore>
 
#include <iostream>
 
#include "Swiften/Elements/StatusShow.h"
 

	
 
MyIrcSession::MyIrcSession(const std::string &user, NetworkPlugin *np, QObject* parent) : Irc::Session(parent)
 
{
 
	this->np = np;
 
	this->user = user;
 
}
 

	
 
void MyIrcSession::on_connected()
 
{
 
    std::cout << "connected:\n";
 
}
 

	
 
void MyIrcSession::on_disconnected()
 
{
 
    std::cout << "disconnected:\n";
 
}
 

	
 
void MyIrcSession::on_bufferAdded(Irc::Buffer* buffer)
 
{
 
    qDebug() << "buffer added:" << buffer->receiver();
 
}
 

	
 
void MyIrcSession::on_bufferRemoved(Irc::Buffer* buffer)
 
{
 
    qDebug() << "buffer removed:" << buffer->receiver();
 
}
 

	
 
Irc::Buffer* MyIrcSession::createBuffer(const QString& receiver)
 
{
 
    return new MyIrcBuffer(receiver, user, np, this);
 
}
 

	
 
MyIrcBuffer::MyIrcBuffer(const QString& receiver, const std::string &user, NetworkPlugin *np, Irc::Session* parent)
 
    : Irc::Buffer(receiver, parent)
 
{
 
	this->np = np;
 
	this->user = user;
 
	p = (MyIrcSession *) parent;
 
    connect(this, SIGNAL(receiverChanged(QString)), SLOT(on_receiverChanged(QString)));
 
    connect(this, SIGNAL(joined(QString)), SLOT(on_joined(QString)));
 
    connect(this, SIGNAL(parted(QString, QString)), SLOT(on_parted(QString, QString)));
 
    connect(this, SIGNAL(quit(QString, QString)), SLOT(on_quit(QString, QString)));
 
    connect(this, SIGNAL(nickChanged(QString, QString)), SLOT(on_nickChanged(QString, QString)));
 
    connect(this, SIGNAL(modeChanged(QString, QString, QString)), SLOT(on_modeChanged(QString, QString, QString)));
 
    connect(this, SIGNAL(topicChanged(QString, QString)), SLOT(on_topicChanged(QString, QString)));
 
    connect(this, SIGNAL(invited(QString, QString, QString)), SLOT(on_invited(QString, QString, QString)));
 
    connect(this, SIGNAL(kicked(QString, QString, QString)), SLOT(on_kicked(QString, QString, QString)));
 
    connect(this, SIGNAL(messageReceived(QString, QString, Irc::Buffer::MessageFlags)),
 
                  SLOT(on_messageReceived(QString, QString, Irc::Buffer::MessageFlags)));
 
    connect(this, SIGNAL(noticeReceived(QString, QString, Irc::Buffer::MessageFlags)),
 
                  SLOT(on_noticeReceived(QString, QString, Irc::Buffer::MessageFlags)));
 
    connect(this, SIGNAL(ctcpRequestReceived(QString, QString, Irc::Buffer::MessageFlags)),
 
                  SLOT(on_ctcpRequestReceived(QString, QString, Irc::Buffer::MessageFlags)));
 
    connect(this, SIGNAL(ctcpReplyReceived(QString, QString, Irc::Buffer::MessageFlags)),
 
                  SLOT(on_ctcpReplyReceived(QString, QString, Irc::Buffer::MessageFlags)));
 
    connect(this, SIGNAL(ctcpActionReceived(QString, QString, Irc::Buffer::MessageFlags)),
 
                  SLOT(on_ctcpActionReceived(QString, QString, Irc::Buffer::MessageFlags)));
 
    connect(this, SIGNAL(numericMessageReceived(QString, uint, QStringList)), SLOT(on_numericMessageReceived(QString, uint, QStringList)));
 
    connect(this, SIGNAL(unknownMessageReceived(QString, QStringList)), SLOT(on_unknownMessageReceived(QString, QStringList)));
 
}
 

	
 
void MyIrcBuffer::on_receiverChanged(const QString& receiver)
 
{
 
    qDebug() << "receiver changed:" << receiver;
 
}
 

	
 
int MyIrcBuffer::correctNickname(std::string &nickname) {
 
	int flags = 0;
 
	switch(nickname.at(0)) {
 
		case '@': nickname = nickname.substr(1); flags = 1; break;
 
		case '+': nickname = nickname.substr(1); break;
 
		default: break;
 
	}
 
	return flags;
 
}
 

	
 
void MyIrcBuffer::on_joined(const QString& origin) {
 
	qDebug() << "joined:" << receiver() << origin;
 
	np->handleParticipantChanged(user, origin.toStdString(), receiver().toStdString(), 0);
 
	int flags = 0;
 
	std::string nickname = origin.toStdString();
 
	flags = correctNickname(nickname);
 
	np->handleParticipantChanged(user, origin.toStdString(), receiver().toStdString(), flags, Swift::StatusShow::Online);
 
}
 

	
 
void MyIrcBuffer::on_parted(const QString& origin, const QString& message)
 
{
 
void MyIrcBuffer::on_parted(const QString& origin, const QString& message) {
 
	qDebug() << "parted:" << receiver() << origin << message;
 
	int flags = 0;
 
	std::string nickname = origin.toStdString();
 
	flags = correctNickname(nickname);
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(), flags, Swift::StatusShow::None, message.toStdString());
 
}
 

	
 
void MyIrcBuffer::on_quit(const QString& origin, const QString& message)
 
{
 
    qDebug() << "quit:" << receiver() << origin << message;
 
}
 

	
 
void MyIrcBuffer::on_nickChanged(const QString& origin, const QString& nick) {
 
	qDebug() << "nick changed:" << receiver() << origin << nick;
 
	np->handleParticipantChanged(user, origin.toStdString(), receiver().toStdString(), 0, nick.toStdString());
 
	std::string nickname = origin.toStdString();
 
	int flags = p->m_modes[receiver().toStdString() + nickname];
 
	std::cout << receiver().toStdString() + nickname << " " << flags <<  "\n";
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(), flags, Swift::StatusShow::Online, "", nick.toStdString());
 
}
 

	
 
void MyIrcBuffer::on_modeChanged(const QString& origin, const QString& mode, const QString& args)
 
{
 
void MyIrcBuffer::on_modeChanged(const QString& origin, const QString& mode, const QString& args) {
 
	// mode changed: "#testik" "HanzZ" "+o" "hanzz_k" 
 
	qDebug() << "mode changed:" << receiver() << origin << mode << args;
 
	std::string nickname = args.toStdString();
 
	if (mode == "+o") {
 
		p->m_modes[receiver().toStdString() + nickname] = 1;
 
	}
 
	else {
 
		p->m_modes[receiver().toStdString() + nickname] = 0;
 
	}
 
	int flags = p->m_modes[receiver().toStdString() + nickname];
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(), flags, Swift::StatusShow::Online, "");
 
}
 

	
 
void MyIrcBuffer::on_topicChanged(const QString& origin, const QString& topic)
 
{
 
    qDebug() << "topic changed:" << receiver() << origin << topic;
 
}
 

	
 
void MyIrcBuffer::on_invited(const QString& origin, const QString& receiver, const QString& channel)
 
{
 
    qDebug() << "invited:" << Irc::Buffer::receiver() << origin << receiver << channel;
 
}
 

	
 
void MyIrcBuffer::on_kicked(const QString& origin, const QString& nick, const QString& message)
 
{
 
    qDebug() << "kicked:" << receiver() << origin << nick << message;
 
}
 

	
 
void MyIrcBuffer::on_messageReceived(const QString& origin, const QString& message, Irc::Buffer::MessageFlags flags) {
 
	qDebug() << "message received:" << receiver() << origin << message << (flags & Irc::Buffer::IdentifiedFlag ? "(identified!)" : "(not identified)");
 
	if (!receiver().startsWith("#") && (flags & Irc::Buffer::EchoFlag))
 
		return;
 
	np->handleMessage(user, receiver().toStdString(), message.toStdString(), origin.toStdString());
 
}
 

	
 
@@ -134,35 +164,40 @@ void MyIrcBuffer::on_ctcpRequestReceived(const QString& origin, const QString& r
 
    qDebug() << "ctcp request received:" << receiver() << origin << request
 
             << (flags & Irc::Buffer::IdentifiedFlag ? "(identified!)" : "(not identified)");
 
}
 

	
 
void MyIrcBuffer::on_ctcpReplyReceived(const QString& origin, const QString& reply, Irc::Buffer::MessageFlags flags)
 
{
 
    qDebug() << "ctcp reply received:" << receiver() << origin << reply
 
             << (flags & Irc::Buffer::IdentifiedFlag ? "(identified!)" : "(not identified)");
 
}
 

	
 
void MyIrcBuffer::on_ctcpActionReceived(const QString& origin, const QString& action, Irc::Buffer::MessageFlags flags)
 
{
 
    qDebug() << "ctcp action received:" << receiver() << origin << action
 
             << (flags & Irc::Buffer::IdentifiedFlag ? "(identified!)" : "(not identified)");
 
}
 

	
 
void MyIrcBuffer::on_numericMessageReceived(const QString& origin, uint code, const QStringList& params)
 
{
 
	switch (code) {
 
		case 353:
 
			QString channel = params.value(2);
 
			QStringList members = params.value(3).split(" ");
 

	
 
			for (int i = 0; i < members.size(); i++) {
 
				np->handleParticipantChanged(user, members.at(i).toStdString(), channel.toStdString(), 0);
 
				int flags = 0;
 
				std::string nickname = members.at(i).toStdString();
 
				flags = correctNickname(nickname);
 
				p->m_modes[channel.toStdString() + nickname] = flags;
 
				std::cout << channel.toStdString() + nickname << " " << flags << "\n";
 
				np->handleParticipantChanged(user, nickname, channel.toStdString(), flags, Swift::StatusShow::Online);
 
			}
 
			break;
 
	}
 
    qDebug() << "numeric message received:" << receiver() << origin << code << params;
 
}
 

	
 
void MyIrcBuffer::on_unknownMessageReceived(const QString& origin, const QStringList& params)
 
{
 
    qDebug() << "unknown message received:" << receiver() << origin << params;
 
}
backends/libircclient-qt/session.h
Show inline comments
 
@@ -2,67 +2,71 @@
 
 * Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
 
 *
 
 * This example is free, and not covered by LGPL license. There is no
 
 * restriction applied to their modification, redistribution, using and so on.
 
 * You can study them, modify them, use them in your own program - either
 
 * completely or partially. By using it you may give me some credits in your
 
 * program, but you don't have to.
 
 */
 

	
 
#ifndef SESSION_H
 
#define SESSION_H
 

	
 
#include <IrcSession>
 
#include <IrcBuffer>
 
#include <transport/networkplugin.h>
 

	
 
using namespace Transport;
 

	
 
class MyIrcSession : public Irc::Session
 
{
 
    Q_OBJECT
 

	
 
public:
 
    MyIrcSession(const std::string &user, NetworkPlugin *np, QObject* parent = 0);
 
	std::map<std::string, int> m_modes;
 

	
 
protected Q_SLOTS:
 
    void on_connected();
 
    void on_disconnected();
 

	
 
    void on_bufferAdded(Irc::Buffer* buffer);
 
    void on_bufferRemoved(Irc::Buffer* buffer);
 

	
 
protected:
 
	NetworkPlugin *np;
 
	std::string user;
 
    virtual Irc::Buffer* createBuffer(const QString& receiver);
 
};
 

	
 
class MyIrcBuffer : public Irc::Buffer
 
{
 
    Q_OBJECT
 

	
 
public:
 
    MyIrcBuffer(const QString& receiver, const std::string &user, NetworkPlugin *np, Irc::Session* parent);
 
	NetworkPlugin *np;
 
	std::string user;
 
	MyIrcSession *p;
 

	
 
protected Q_SLOTS:
 
    void on_receiverChanged(const QString& receiver);
 
    void on_joined(const QString& origin);
 
    void on_parted(const QString& origin, const QString& message);
 
    void on_quit(const QString& origin, const QString& message);
 
    void on_nickChanged(const QString& origin, const QString& nick);
 
    void on_modeChanged(const QString& origin, const QString& mode, const QString& args);
 
    void on_topicChanged(const QString& origin, const QString& topic);
 
    void on_invited(const QString& origin, const QString& receiver, const QString& channel);
 
    void on_kicked(const QString& origin, const QString& nick, const QString& message);
 
    void on_messageReceived(const QString& origin, const QString& message, Irc::Buffer::MessageFlags flags);
 
    void on_noticeReceived(const QString& origin, const QString& notice, Irc::Buffer::MessageFlags flags);
 
    void on_ctcpRequestReceived(const QString& origin, const QString& request, Irc::Buffer::MessageFlags flags);
 
    void on_ctcpReplyReceived(const QString& origin, const QString& reply, Irc::Buffer::MessageFlags flags);
 
    void on_ctcpActionReceived(const QString& origin, const QString& action, Irc::Buffer::MessageFlags flags);
 
    void on_numericMessageReceived(const QString& origin, uint code, const QStringList& params);
 
    void on_unknownMessageReceived(const QString& origin, const QStringList& params);
 

	
 
	int correctNickname(std::string &nickname);
 
};
 

	
 
#endif // SESSION_H
include/transport/conversation.h
Show inline comments
 
@@ -12,58 +12,60 @@
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include "transport/transport.h"
 

	
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Elements/Message.h"
 

	
 
namespace Transport {
 

	
 
class ConversationManager;
 

	
 
class Conversation {
 
	public:
 
		enum ParticipantFlag {None, Moderator};
 

	
 
		/// Constructor.
 
		Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool m_muc = false);
 

	
 
		/// Destructor
 
		virtual ~Conversation();
 

	
 
		const std::string &getLegacyName() { return m_legacyName; }
 

	
 
		void handleMessage(boost::shared_ptr<Swift::Message> &message, const std::string &nickname = "");
 
		void handleParticipantChanged(const std::string &nickname, int flag, const std::string &newname = "");
 
		void handleParticipantChanged(const std::string &nickname, int flag, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "");
 
		void setNickname(const std::string &nickname) {
 
			m_nickname = nickname;
 
		}
 

	
 
		virtual void sendMessage(boost::shared_ptr<Swift::Message> &message) = 0;
 

	
 
		ConversationManager *getConversationManager() {
 
			return m_conversationManager;
 
		}
 

	
 
		bool isMUC() {
 
			return m_muc;
 
		}
 

	
 
		void setRoom(const std::string &room) {
 
			m_room = room;
 
		}
 

	
 
		const std::string &getRoom() {
 
			return m_room;
 
		}
 

	
 
	private:
 
		ConversationManager *m_conversationManager;
include/transport/networkplugin.h
Show inline comments
 
@@ -23,49 +23,49 @@
 
#include <time.h>
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Presence/PresenceOracle.h"
 
#include "Swiften/Disco/EntityCapsManager.h"
 
#include "Swiften/Network/ConnectionServer.h"
 
#include "Swiften/Network/Connection.h"
 
#include "Swiften/Network/BoostTimerFactory.h"
 
#include "Swiften/Network/BoostNetworkFactories.h"
 
#include "Swiften/Network/BoostIOServiceThread.h"
 
#include "Swiften/Network/Connection.h"
 
#include "storagebackend.h"
 

	
 
namespace Transport {
 

	
 
class NetworkPlugin {
 
	public:
 
		NetworkPlugin(Swift::EventLoop *loop, const std::string &host, int port);
 

	
 
		virtual ~NetworkPlugin();
 

	
 
		void handleBuddyChanged(const std::string &user, const std::string &buddyName, const std::string &alias,
 
			const std::string &groups, int status, const std::string &statusMessage = "", const std::string &iconHash = ""
 
		);
 

	
 
		void handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags, const std::string &newname = "");
 
		void handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "");
 

	
 
		void handleDisconnected(const std::string &user, const std::string &legacyName, int error, const std::string &message);
 

	
 
		void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "");
 

	
 
		void handleRoomChanged(const std::string &user, const std::string &room, const std::string &nickname);
 

	
 
		virtual void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) = 0;
 
		virtual void handleLogoutRequest(const std::string &user, const std::string &legacyName) = 0;
 
		virtual void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) = 0;
 
		virtual void handleJoinRoomRequest(const std::string &/*user*/, const std::string &/*room*/, const std::string &/*nickname*/, const std::string &/*pasword*/) {}
 
		virtual void handleLeaveRoomRequest(const std::string &/*user*/, const std::string &/*room*/) {}
 
		
 

	
 
	private:
 
		void connect();
 
		void handleLoginPayload(const std::string &payload);
 
		void handleLogoutPayload(const std::string &payload);
 
		void handleConvMessagePayload(const std::string &payload);
 
		void handleJoinRoomPayload(const std::string &payload);
 
		void handleLeaveRoomPayload(const std::string &payload);
 
		void handleDataRead(const Swift::ByteArray&);
 
		void handleConnected(bool error);
 
		void handleDisconnected();
src/conversation.cpp
Show inline comments
 
@@ -57,56 +57,72 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
 
			}
 
			else {
 
				std::cout << m_legacyName << " 1111111\n";
 
				// TODO: escape from and setFrom
 
			}
 
		}
 
		// PM message
 
		else {
 
			if (m_room.empty()) {
 
				message->setFrom(Swift::JID(nickname, m_conversationManager->getComponent()->getJID().toBare(), "user"));
 
			}
 
			else {
 
				message->setFrom(Swift::JID(m_room, m_conversationManager->getComponent()->getJID().toBare(), nickname));
 
			}
 
		}
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
 
	}
 
	else {
 
		message->setTo(m_conversationManager->getUser()->getJID().toString());
 
		message->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
 
	}
 
}
 

	
 
void Conversation::handleParticipantChanged(const std::string &nick, int flag, const std::string &newname) {
 
void Conversation::handleParticipantChanged(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) {
 
	std::string nickname = nick;
 
	if (nickname.find("@") == 0) {
 
		nickname = nickname.substr(1);
 
	}
 
	Swift::Presence::ref presence = Swift::Presence::create();
 
 	presence->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
 
	presence->setTo(m_conversationManager->getUser()->getJID().toString());
 
	presence->setType(Swift::Presence::Available);
 

	
 
	if (!statusMessage.empty())
 
		presence->setStatus(statusMessage);
 

	
 
	Swift::StatusShow s((Swift::StatusShow::Type) status);
 

	
 
	if (s.getType() == Swift::StatusShow::None)
 
		presence->setType(Swift::Presence::Unavailable);
 
	presence->setShow(s.getType());
 

	
 
	Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
 
	if (m_nickname == nickname) {
 
		Swift::MUCUserPayload::StatusCode c;
 
		c.code = 110;
 
		p->addStatusCode(c);
 
	}
 

	
 
	
 
	Swift::MUCUserPayload::Item item(Swift::MUCOccupant::Member, Swift::MUCOccupant::Participant);
 

	
 
	if (flag & Moderator) {
 
		item = Swift::MUCUserPayload::Item(Swift::MUCOccupant::Admin, Swift::MUCOccupant::Moderator);
 
	}
 

	
 
	if (!newname.empty()) {
 
		item.nick = newname;
 
		Swift::MUCUserPayload::StatusCode c;
 
		c.code = 303;
 
		p->addStatusCode(c);
 
		presence->setType(Swift::Presence::Unavailable);
 
	}
 

	
 
	p->addItem(item);
 

	
 
	presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
 
	m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
 
	if (!newname.empty()) {
 
		handleParticipantChanged(newname, flag, status, statusMessage);
 
	}
 
}
 

	
 
}
src/networkplugin.cpp
Show inline comments
 
@@ -84,55 +84,57 @@ void NetworkPlugin::handleBuddyChanged(const std::string &user, const std::strin
 

	
 
	std::string message;
 
	buddy.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_BUDDY_CHANGED);
 

	
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleDisconnected(const std::string &user, const std::string &legacyName, int error, const std::string &msg) {
 
	pbnetwork::Disconnected d;
 
	d.set_user(user);
 
	d.set_name(legacyName);
 
	d.set_error(error);
 
	d.set_message(msg);
 

	
 
	std::string message;
 
	d.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_DISCONNECTED);
 

	
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags, const std::string &newname) {
 
void NetworkPlugin::handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags, int status, const std::string &statusMessage, const std::string &newname) {
 
	pbnetwork::Participant d;
 
	d.set_username(user);
 
	d.set_nickname(nickname);
 
	d.set_room(room);
 
	d.set_flag(flags);
 
	d.set_newname(newname);
 
	d.set_status(status);
 
	d.set_statusmessage(statusMessage);
 

	
 
	std::string message;
 
	d.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_PARTICIPANT_CHANGED);
 

	
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleRoomChanged(const std::string &user, const std::string &r, const std::string &nickname) {
 
	pbnetwork::Room room;
 
	room.set_username(user);
 
	room.set_nickname(nickname);
 
	room.set_room(r);
 
	room.set_password("");
 

	
 
	std::string message;
 
	room.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_ROOM_NICKNAME_CHANGED);
 
 
 
	send(message);
 
}
 

	
src/networkpluginserver.cpp
Show inline comments
 
@@ -189,49 +189,49 @@ void NetworkPluginServer::handleBuddyChangedPayload(const std::string &data) {
 
	}
 
	else {
 
		buddy = new LocalBuddy(user->getRosterManager(), -1);
 
		handleBuddyPayload(buddy, payload);
 
		user->getRosterManager()->setBuddy(buddy);
 
	}
 
}
 

	
 
void NetworkPluginServer::handleParticipantChangedPayload(const std::string &data) {
 
	pbnetwork::Participant payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 

	
 
	User *user = m_userManager->getUser(payload.username());
 
	if (!user)
 
		return;
 

	
 
	NetworkConversation *conv = (NetworkConversation *) user->getConversationManager()->getConversation(payload.room());
 
	if (!conv) {
 
		return;
 
	}
 

	
 
	conv->handleParticipantChanged(payload.nickname(), payload.flag(), payload.newname());
 
	conv->handleParticipantChanged(payload.nickname(), payload.flag(), payload.status(), payload.statusmessage(), payload.newname());
 

	
 
// 	LocalBuddy *buddy = (LocalBuddy *) user->getRosterManager()->getBuddy(payload.buddyname());
 
// 	if (buddy) {
 
// 		handleBuddyPayload(buddy, payload);
 
// 		buddy->buddyChanged();
 
// 	}
 
// 	else {
 
// 		buddy = new LocalBuddy(user->getRosterManager(), -1);
 
// 		handleBuddyPayload(buddy, payload);
 
// 		user->getRosterManager()->setBuddy(buddy);
 
// 	}
 
// 	std::cout << payload.nickname() << "\n";
 
}
 

	
 
void NetworkPluginServer::handleRoomChangedPayload(const std::string &data) {
 
	pbnetwork::Room payload;
 
	if (payload.ParseFromString(data) == false) {
 
		return;
 
	}
 

	
 
	User *user = m_userManager->getUser(payload.username());
 
	if (!user)
 
		return;
 

	
src/pbnetwork.proto
Show inline comments
 
@@ -31,48 +31,49 @@ message Buddy {
 
	required int32 status = 5;
 
	optional string statusMessage = 6;
 
	optional string iconHash = 7;
 
}
 

	
 
message ConversationMessage {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	required string message = 3;
 
	optional string nickname = 4;
 
}
 

	
 
message Room {
 
	required string userName = 1;
 
	required string nickname = 2;
 
	required string room = 3;
 
	optional string password = 4;
 
}
 

	
 
message Participant {
 
	required string userName = 1;
 
	required string room = 2;
 
	required string nickname = 3;
 
	required int32 flag = 4;
 
	optional string newname = 5;
 
	required int32 status = 5;
 
	optional string statusMessage = 6;
 
	optional string newname = 7;
 
}
 

	
 
message WrapperMessage {
 
	enum Type { 
 
		TYPE_CONNECTED 				= 1;
 
		TYPE_DISCONNECTED 			= 2;
 
		TYPE_LOGIN 					= 3;
 
		TYPE_LOGOUT 				= 4;
 
		TYPE_BUDDY_CHANGED			= 6;
 
		TYPE_BUDDY_REMOVED			= 7;
 
		TYPE_CONV_MESSAGE			= 8;
 
		TYPE_PING					= 9;
 
		TYPE_PONG					= 10;
 
		TYPE_JOIN_ROOM				= 11;
 
		TYPE_LEAVE_ROOM				= 12;
 
		TYPE_PARTICIPANT_CHANGED	= 13;
 
		TYPE_PARTICIPANT_LEFT		= 14;
 
		TYPE_ROOM_NICKNAME_CHANGED	= 15;
 
		TYPE_ROOM_NICKNAME_CHANGED	= 14;
 
	}
 
	required Type type = 1;
 
	optional bytes payload = 2;
 
}
 
;
 
\ No newline at end of file
src/user.cpp
Show inline comments
 
@@ -69,48 +69,53 @@ void User::handlePresence(Swift::Presence::ref presence) {
 
			// Forward status message to legacy network, but only if it's sent from active resource
 
// 					if (m_activeResource == presence->getFrom().getResource().getUTF8String()) {
 
// 						forwardStatus(presenceShow, stanzaStatus);
 
// 					}
 
			boost::shared_ptr<Swift::CapsInfo> capsInfo = presence->getPayload<Swift::CapsInfo>();
 
			if (capsInfo && capsInfo->getHash() == "sha-1") {
 
				if (m_entityCapsManager->getCaps(presence->getFrom()) != Swift::DiscoInfo::ref()) {
 
					m_readyForConnect = true;
 
					onReadyToConnect();
 
				}
 
			}
 
			else {
 
				m_reconnectTimer->start();
 
			}
 
		}
 
	}
 
	std::cout << "HANDLE PRESENCE\n";
 
	bool isMUC = presence->getPayload<Swift::MUCPayload>() != NULL || *presence->getTo().getNode().c_str() == '#';
 
	if (isMUC) {
 
		std::cout << "AAAAAAAAA\n";
 
		if (presence->getType() == Swift::Presence::Unavailable) {
 
			onRoomLeft(presence->getTo().getNode());
 
		}
 
		else {
 
			// force connection to legacy network to let backend to handle auto-join on connect.
 
			if (!m_readyForConnect) {
 
				m_readyForConnect = true;
 
				onReadyToConnect();
 
			}
 
			onRoomJoined(presence->getTo().getNode(), presence->getTo().getResource(), "");
 
		}
 
		return;
 
	}
 

	
 

	
 
	if (highest) {
 
		highest->setTo(presence->getFrom().toBare());
 
		highest->setFrom(m_component->getJID());
 
		m_component->getStanzaChannel()->sendPresence(highest);
 
	}
 
	else {
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo(m_jid.toBare());
 
		response->setFrom(m_component->getJID());
 
		response->setType(Swift::Presence::Unavailable);
 
		m_component->getStanzaChannel()->sendPresence(response);
 
	}
 
}
 

	
 
void User::handleSubscription(Swift::Presence::ref presence) {
 
	m_rosterManager->handleSubscription(presence);
 
}
 

	
0 comments (0 inline, 0 general)