Beispiel #1
0
/**
 * Construct the xmpp client
 */
XmppClient::XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, bool regOpt)
	: m_client(NULL), m_mucRoom(NULL), m_registration(NULL), m_username(sUsername), m_password(sPassword), m_nick(sNick)
{
	// Read lobby configuration from default.cfg
	std::string sServer;
	std::string sXpartamupp;
	CFG_GET_VAL("lobby.server", String, sServer);
	CFG_GET_VAL("lobby.xpartamupp", String, sXpartamupp);

	m_xpartamuppId = sXpartamupp + "@" + sServer + "/CC";
	glooxwrapper::JID clientJid(sUsername + "@" + sServer + "/0ad");
	glooxwrapper::JID roomJid(sRoom + "@conference." + sServer + "/" + sNick);

	// If we are connecting, use the full jid and a password
	// If we are registering, only use the server name
	if(!regOpt)
		m_client = new glooxwrapper::Client(clientJid, sPassword);
	else
		m_client = new glooxwrapper::Client(sServer);

	// Disable TLS as we haven't set a certificate on the server yet
	m_client->setTls(gloox::TLSDisabled);

	// Disable use of the SASL PLAIN mechanism, to prevent leaking credentials
	// if the server doesn't list any supported SASL mechanism or the response
	// has been modified to exclude those.
	const int mechs = gloox::SaslMechAll ^ gloox::SaslMechPlain;
	m_client->setSASLMechanisms(mechs);

	m_client->registerConnectionListener( this );
	m_client->setPresence(gloox::Presence::Available, -1);
	m_client->disco()->setVersion( "Pyrogenesis", "0.0.15" );
	m_client->disco()->setIdentity( "client", "bot" );
	m_client->setCompression(false);

	m_client->registerStanzaExtension( new GameListQuery() );
	m_client->registerIqHandler( this, ExtGameListQuery);

	m_client->registerStanzaExtension( new BoardListQuery() );
	m_client->registerIqHandler( this, ExtBoardListQuery);

	m_client->registerMessageHandler( this );

	// Uncomment to see the raw stanzas
	//m_client->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );

	if (!regOpt)
	{
		// Create a Multi User Chat Room
		m_mucRoom = new glooxwrapper::MUCRoom(m_client, roomJid, this, 0);
		// Disable the history because its anoying
		m_mucRoom->setRequestHistory(0, gloox::MUCRoom::HistoryMaxStanzas);
	}
	else
	{
		// Registration
		m_registration = new glooxwrapper::Registration(m_client);
		m_registration->registerRegistrationHandler(this);
	}
}
Beispiel #2
0
bool MultiUserChat::sendPresence(int AShow, const QString &AStatus)
{
	if (FStanzaProcessor)
	{
		Jid userJid(FRoomJid.node(),FRoomJid.domain(),FNickName);

		Stanza presence("presence");
		presence.setTo(userJid.full());

		QString showText;
		bool isConnecting = true;
		switch (AShow)
		{
		case IPresence::Online:
			showText = QString::null;
			break;
		case IPresence::Chat:
			showText = "chat";
			break;
		case IPresence::Away:
			showText = "away";
			break;
		case IPresence::DoNotDisturb:
			showText = "dnd";
			break;
		case IPresence::ExtendedAway:
			showText = "xa";
			break;
		default:
			isConnecting = false;
			showText = "unavailable";
		}

		if (!isConnecting)
			presence.setType("unavailable");
		else if (!showText.isEmpty())
			presence.addElement("show").appendChild(presence.createTextNode(showText));

		if (!AStatus.isEmpty())
			presence.addElement("status").appendChild(presence.createTextNode(AStatus));

		if (!isConnected() && isConnecting)
		{
			FRoomError = XmppError::null;
			emit chatAboutToConnect();

			QDomElement xelem = presence.addElement("x",NS_MUC);
			if (FHistory.empty || FHistory.maxChars>0 || FHistory.maxStanzas>0 || FHistory.seconds>0 || FHistory.since.isValid())
			{
				QDomElement histElem = xelem.appendChild(presence.createElement("history")).toElement();
				if (!FHistory.empty)
				{
					if (FHistory.maxChars > 0)
						histElem.setAttribute("maxchars",FHistory.maxChars);
					if (FHistory.maxStanzas > 0)
						histElem.setAttribute("maxstanzas",FHistory.maxStanzas);
					if (FHistory.seconds > 0)
						histElem.setAttribute("seconds",FHistory.seconds);
					if (FHistory.since.isValid())
						histElem.setAttribute("since",DateTime(FHistory.since).toX85UTC());
				}
				else
				{
					histElem.setAttribute("maxchars",0);
				}
			}
			if (!FPassword.isEmpty())
				xelem.appendChild(presence.createElement("password")).appendChild(presence.createTextNode(FPassword));
			if (FDiscovery && !FDiscovery->hasDiscoInfo(streamJid(),roomJid()))
				FDiscovery->requestDiscoInfo(streamJid(),roomJid());
		}
		else if (isConnected() && !isConnecting)
		{
			emit chatAboutToDisconnect();
		}

		if (FStanzaProcessor->sendStanzaOut(FStreamJid,presence))
		{
			LOG_STRM_INFO(FStreamJid,QString("Presence sent to conference, room=%1, show=%2").arg(FRoomJid.bare()).arg(AShow));
			FConnected = isConnecting;
			return true;
		}
		else
		{
			LOG_STRM_WARNING(FStreamJid,QString("Failed to send presence to conference, room=%1, show=%2").arg(FRoomJid.bare()).arg(AShow));
		}
	}
	else
	{
		REPORT_ERROR("Failed to send presence to conference: Required interfaces not found");
	}
	return false;
}
Beispiel #3
0
MultiUserChat::MultiUserChat(IMultiUserChatManager *AMultiChatManager, const Jid &AStreamJid, const Jid &ARoomJid, const QString &ANickName, const QString &APassword, QObject *AParent) : QObject(AParent)
{
	FMultiChatManager = AMultiChatManager;

	FMainUser = NULL;
	FSHIPresence = -1;
	FSHIMessage = -1;
	FConnected = false;
	FAutoPresence = false;

	FRoomJid = ARoomJid;
	FStreamJid = AStreamJid;
	FNickName = ANickName;
	FPassword = APassword;
	FShow = IPresence::Offline;
	FRoomName = FRoomJid.uBare();

	FMessageProcessor = PluginHelper::pluginInstance<IMessageProcessor>();
	if (FMessageProcessor)
	{
		FMessageProcessor->insertMessageEditor(MEO_MULTIUSERCHAT,this);
	}

	FStanzaProcessor = PluginHelper::pluginInstance<IStanzaProcessor>();
	if (FStanzaProcessor)
	{
		IStanzaHandle shandle;
		shandle.handler = this;
		shandle.order = SHO_PI_MULTIUSERCHAT;
		shandle.direction = IStanzaHandle::DirectionIn;
		shandle.streamJid = FStreamJid;
		shandle.conditions.append(SHC_PRESENCE);
		FSHIPresence = FStanzaProcessor->insertStanzaHandle(shandle);

		if (FMessageProcessor==NULL || !FMessageProcessor->isActiveStream(streamJid()))
		{
			shandle.conditions.clear();
			shandle.order = SHO_MI_MULTIUSERCHAT;
			shandle.conditions.append(SHC_MESSAGE);
			FSHIMessage = FStanzaProcessor->insertStanzaHandle(shandle);
		}
	}

	IPresenceManager *presenceManager = PluginHelper::pluginInstance<IPresenceManager>();
	FPresence = presenceManager!=NULL ? presenceManager->findPresence(FStreamJid) : NULL;
	if (FPresence)
	{
		connect(FPresence->instance(),SIGNAL(changed(int, const QString &, int)),SLOT(onPresenceChanged(int, const QString &, int)));
	}

	IXmppStreamManager *xmppStreamManager = PluginHelper::pluginInstance<IXmppStreamManager>();
	FXmppStream = xmppStreamManager!=NULL ? xmppStreamManager->findXmppStream(FStreamJid) : NULL;
	if (FXmppStream)
	{
		connect(FXmppStream->instance(),SIGNAL(closed()),SLOT(onXmppStreamClosed()));
		connect(FXmppStream->instance(),SIGNAL(jidChanged(const Jid &)),SLOT(onXmppStreamJidChanged(const Jid &)));
	}

	FDiscovery = PluginHelper::pluginInstance<IServiceDiscovery>();
	if (FDiscovery)
	{
		onDiscoveryInfoReceived(FDiscovery->discoInfo(streamJid(),roomJid()));
		connect(FDiscovery->instance(),SIGNAL(discoInfoReceived(const IDiscoInfo &)),SLOT(onDiscoveryInfoReceived(const IDiscoInfo &)));
	}

	FDataForms = PluginHelper::pluginInstance<IDataForms>();
}