/***************************************************************************
- * Copyright (C) 2005-2019 by the Quassel Project *
+ * Copyright (C) 2005-2020 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include <utility>
-#include <QtScript>
-
#include "core.h"
#include "corebacklogmanager.h"
#include "corebuffersyncer.h"
, _sessionEventProcessor(new CoreSessionEventProcessor(this))
, _ctcpParser(new CtcpParser(this))
, _ircParser(new IrcParser(this))
- , scriptEngine(new QScriptEngine(this))
, _processMessages(false)
, _ignoreListManager(this)
, _highlightRuleManager(this)
+ , _metricsServer(Core::instance()->metricsServer())
{
SignalProxy* p = signalProxy();
p->setHeartBeatInterval(30);
_coreInfo->setCoreData(data);
loadSettings();
- initScriptEngine();
eventManager()->registerObject(ircParser(), EventManager::NormalPriority);
eventManager()->registerObject(sessionEventProcessor(), EventManager::HighPriority); // needs to process events *before* the stringifier!
restoreSessionState();
emit initialized();
+
+ if (_metricsServer) {
+ _metricsServer->addSession(user(), Core::instance()->strictSysIdent(_user));
+ }
}
void CoreSession::shutdown()
// Nothing to do, suicide so the core can shut down
deleteLater();
}
+
+ if (_metricsServer) {
+ _metricsServer->removeSession(user());
+ }
}
void CoreSession::onNetworkDisconnected(NetworkId networkId)
// migrate to db
QList<IdentityId> ids = s.identityIds();
- QList<NetworkInfo> networkInfos = Core::networks(user());
+ std::vector<NetworkInfo> networkInfos = Core::networks(user());
for (IdentityId id : ids) {
CoreIdentity identity(s.identity(id));
IdentityId newId = Core::createIdentity(user(), identity);
- QList<NetworkInfo>::iterator networkIter = networkInfos.begin();
+ auto networkIter = networkInfos.begin();
while (networkIter != networkInfos.end()) {
if (networkIter->identity == id) {
networkIter->identity = newId;
void CoreSession::restoreSessionState()
{
- QList<NetworkId> nets = Core::connectedNetworks(user());
- CoreNetwork* net = nullptr;
- for (NetworkId id : nets) {
- net = network(id);
+ for (NetworkId id : Core::connectedNetworks(user())) {
+ auto net = network(id);
Q_ASSERT(net);
net->connectToIrc();
}
_coreInfo->setConnectedClientData(signalProxy()->peerCount(), signalProxy()->peerData());
signalProxy()->setTargetPeer(nullptr);
+
+ if (_metricsServer) {
+ _metricsServer->addClient(user());
+ }
}
void CoreSession::addClient(InternalPeer* peer)
if (p)
qInfo() << qPrintable(tr("Client")) << p->description() << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
_coreInfo->setConnectedClientData(signalProxy()->peerCount(), signalProxy()->peerData());
+
+ if (_metricsServer) {
+ _metricsServer->removeClient(user());
+ }
}
QHash<QString, QString> CoreSession::persistentChannels(NetworkId id) const
// check for HardStrictness ignore
CoreNetwork* currentNetwork = network(msg.networkId);
QString networkName = currentNetwork ? currentNetwork->networkName() : QString("");
- if (_ignoreListManager.match(msg, networkName) == IgnoreListManager::HardStrictness)
+ switch (_ignoreListManager.match(msg, networkName)) {
+ case IgnoreListManager::StrictnessType::HardStrictness:
+ // Drop the message permanently
return;
+ case IgnoreListManager::StrictnessType::SoftStrictness:
+ // Mark the message as (dynamically) ignored
+ msg.flags |= Message::Flag::Ignored;
+ break;
+ case IgnoreListManager::StrictnessType::UnmatchedStrictness:
+ // Keep the message unmodified
+ break;
+ }
if (currentNetwork && _highlightRuleManager.match(msg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
msg.flags |= Message::Flag::Highlight;
void CoreSession::processMessageEvent(MessageEvent* event)
{
recvMessageFromServer(RawMessage{
+ event->timestamp(),
event->networkId(),
event->msgType(),
event->bufferType(),
});
}
-QList<BufferInfo> CoreSession::buffers() const
+std::vector<BufferInfo> CoreSession::buffers() const
{
return Core::requestBuffers(user());
}
Q_ASSERT(!createBuffer);
bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, BufferInfo::StatusBuffer, "");
}
- Message msg(bufferInfo,
+ Message msg(rawMsg.timestamp,
+ bufferInfo,
rawMsg.type,
rawMsg.text,
rawMsg.sender,
}
bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo;
}
- Message msg(bufferInfo,
+ Message msg(rawMsg.timestamp,
+ bufferInfo,
rawMsg.type,
rawMsg.text,
rawMsg.sender,
// add the StatusBuffer to the Cache in case there are more Messages for the original target
bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo;
}
- Message msg(bufferInfo,
+ Message msg(rawMsg.timestamp,
+ bufferInfo,
rawMsg.type,
rawMsg.text,
rawMsg.sender,
return Protocol::SessionState(identities, bufferInfos, networkIds);
}
-void CoreSession::initScriptEngine()
-{
- signalProxy()->attachSlot(SIGNAL(scriptRequest(QString)), this, &CoreSession::scriptRequest);
- signalProxy()->attachSignal(this, &CoreSession::scriptResult);
-
- // FIXME
- // QScriptValue storage_ = scriptEngine->newQObject(storage);
- // scriptEngine->globalObject().setProperty("storage", storage_);
-}
-
-void CoreSession::scriptRequest(QString script)
-{
- emit scriptResult(scriptEngine->evaluate(script).toString());
-}
-
/*** Identity Handling ***/
void CoreSession::createIdentity(const Identity& identity, const QVariantMap& additional)
{
-#ifndef HAVE_SSL
- Q_UNUSED(additional)
-#endif
-
CoreIdentity coreIdentity(identity);
-#ifdef HAVE_SSL
if (additional.contains("KeyPem"))
coreIdentity.setSslKey(additional["KeyPem"].toByteArray());
if (additional.contains("CertPem"))
coreIdentity.setSslCert(additional["CertPem"].toByteArray());
-#endif
qDebug() << Q_FUNC_INFO;
IdentityId id = Core::createIdentity(user(), coreIdentity);
if (!id.isValid())
void CoreSession::destroyNetwork(NetworkId id)
{
- QList<BufferId> removedBuffers = Core::requestBufferIdsForNetwork(user(), id);
Network* net = _networks.take(id);
if (net && Core::removeNetwork(user(), id)) {
// make sure that all unprocessed RawMessages from this network are removed
}
}
// remove buffers from syncer
- for (BufferId bufferId : removedBuffers) {
+ for (BufferId bufferId : Core::requestBufferIdsForNetwork(user(), id)) {
_bufferSyncer->removeBuffer(bufferId);
}
emit networkRemoved(id);