+class ProcessMessagesEvent : public QEvent
+{
+public:
+ ProcessMessagesEvent()
+ : QEvent(QEvent::User)
+ {}
+};
+
+CoreSession::CoreSession(UserId uid, bool restoreState, bool strictIdentEnabled, QObject* parent)
+ : QObject(parent)
+ , _user(uid)
+ , _strictIdentEnabled(strictIdentEnabled)
+ , _signalProxy(new SignalProxy(SignalProxy::Server, this))
+ , _aliasManager(this)
+ , _bufferSyncer(new CoreBufferSyncer(this))
+ , _backlogManager(new CoreBacklogManager(this))
+ , _bufferViewManager(new CoreBufferViewManager(_signalProxy, this))
+ , _dccConfig(new CoreDccConfig(this))
+ , _ircListHelper(new CoreIrcListHelper(this))
+ , _networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this))
+ , _coreInfo(new CoreInfo(this))
+ , _transferManager(new CoreTransferManager(this))
+ , _eventManager(new CoreEventManager(this))
+ , _eventStringifier(new EventStringifier(this))
+ , _sessionEventProcessor(new CoreSessionEventProcessor(this))
+ , _ctcpParser(new CtcpParser(this))
+ , _ircParser(new IrcParser(this))
+ , _processMessages(false)
+ , _ignoreListManager(this)
+ , _highlightRuleManager(this)
+ , _metricsServer(Core::instance()->metricsServer())
+{
+ SignalProxy* p = signalProxy();
+ p->setHeartBeatInterval(30);
+ p->setMaxHeartBeatCount(60); // 30 mins until we throw a dead socket out
+
+ connect(p, &SignalProxy::peerRemoved, this, &CoreSession::removeClient);
+
+ connect(p, &SignalProxy::connected, this, &CoreSession::clientsConnected);
+ connect(p, &SignalProxy::disconnected, this, &CoreSession::clientsDisconnected);
+
+ p->attachSlot(SIGNAL(sendInput(BufferInfo,QString)), this, &CoreSession::msgFromClient);
+ p->attachSignal(this, &CoreSession::displayMsg);
+ p->attachSignal(this, &CoreSession::displayStatusMsg);
+
+ p->attachSignal(this, &CoreSession::identityCreated);
+ p->attachSignal(this, &CoreSession::identityRemoved);
+ p->attachSlot(SIGNAL(createIdentity(Identity,QVariantMap)), this, selectOverload<const Identity&, const QVariantMap&>(&CoreSession::createIdentity));
+ p->attachSlot(SIGNAL(removeIdentity(IdentityId)), this, &CoreSession::removeIdentity);
+
+ p->attachSignal(this, &CoreSession::networkCreated);
+ p->attachSignal(this, &CoreSession::networkRemoved);
+ p->attachSlot(SIGNAL(createNetwork(NetworkInfo,QStringList)), this,&CoreSession::createNetwork);
+ p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, &CoreSession::removeNetwork);
+
+ p->attachSlot(SIGNAL(changePassword(PeerPtr,QString,QString,QString)), this, &CoreSession::changePassword);
+ p->attachSignal(this, &CoreSession::passwordChanged);
+
+ p->attachSlot(SIGNAL(kickClient(int)), this, &CoreSession::kickClient);
+ p->attachSignal(this, &CoreSession::disconnectFromCore);
+
+ QVariantMap data;
+ data["quasselVersion"] = Quassel::buildInfo().fancyVersionString;
+ data["quasselBuildDate"] = Quassel::buildInfo().commitDate; // "BuildDate" for compatibility
+ data["startTime"] = Core::startTime();
+ data["sessionConnectedClients"] = 0;
+ _coreInfo->setCoreData(data);
+
+ loadSettings();
+
+ eventManager()->registerObject(ircParser(), EventManager::NormalPriority);
+ eventManager()->registerObject(sessionEventProcessor(), EventManager::HighPriority); // needs to process events *before* the stringifier!
+ eventManager()->registerObject(ctcpParser(), EventManager::NormalPriority);
+ eventManager()->registerObject(eventStringifier(), EventManager::NormalPriority);
+ eventManager()->registerObject(this, EventManager::LowPriority); // for sending MessageEvents to the client
+ // some events need to be handled after msg generation
+ eventManager()->registerObject(sessionEventProcessor(), EventManager::LowPriority, "lateProcess");
+ eventManager()->registerObject(ctcpParser(), EventManager::LowPriority, "send");
+
+ // periodically save our session state
+ connect(Core::syncTimer(), &QTimer::timeout, this, &CoreSession::saveSessionState);
+
+ p->synchronize(_bufferSyncer);
+ p->synchronize(&aliasManager());
+ p->synchronize(_backlogManager);
+ p->synchronize(dccConfig());
+ p->synchronize(ircListHelper());
+ p->synchronize(networkConfig());
+ p->synchronize(_coreInfo);
+ p->synchronize(&_ignoreListManager);
+ p->synchronize(&_highlightRuleManager);
+ // Listen to network removed events
+ connect(this, &CoreSession::networkRemoved, &_highlightRuleManager, &HighlightRuleManager::networkRemoved);
+ p->synchronize(transferManager());
+ // Restore session state
+ if (restoreState)
+ restoreSessionState();
+
+ emit initialized();
+
+ if (_metricsServer) {
+ _metricsServer->addSession(user(), Core::instance()->strictSysIdent(_user));
+ }
+}