1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "coresession.h"
26 #include "coreuserinputhandler.h"
27 #include "corebuffersyncer.h"
28 #include "corebacklogmanager.h"
29 #include "corebufferviewmanager.h"
30 #include "coredccconfig.h"
31 #include "coreeventmanager.h"
32 #include "coreidentity.h"
33 #include "coreignorelistmanager.h"
35 #include "coreirclisthelper.h"
36 #include "corenetwork.h"
37 #include "corenetworkconfig.h"
38 #include "coresessioneventprocessor.h"
39 #include "coretransfermanager.h"
40 #include "coreusersettings.h"
41 #include "ctcpparser.h"
42 #include "eventstringifier.h"
43 #include "internalpeer.h"
44 #include "ircchannel.h"
45 #include "ircparser.h"
48 #include "messageevent.h"
49 #include "remotepeer.h"
54 class ProcessMessagesEvent : public QEvent
57 ProcessMessagesEvent() : QEvent(QEvent::User) {}
61 CoreSession::CoreSession(UserId uid, bool restoreState, bool strictIdentEnabled, QObject *parent)
64 _strictIdentEnabled(strictIdentEnabled),
65 _signalProxy(new SignalProxy(SignalProxy::Server, this)),
67 _bufferSyncer(new CoreBufferSyncer(this)),
68 _backlogManager(new CoreBacklogManager(this)),
69 _bufferViewManager(new CoreBufferViewManager(_signalProxy, this)),
70 _dccConfig(new CoreDccConfig(this)),
71 _ircListHelper(new CoreIrcListHelper(this)),
72 _networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this)),
73 _coreInfo(new CoreInfo(this)),
74 _transferManager(new CoreTransferManager(this)),
75 _eventManager(new CoreEventManager(this)),
76 _eventStringifier(new EventStringifier(this)),
77 _sessionEventProcessor(new CoreSessionEventProcessor(this)),
78 _ctcpParser(new CtcpParser(this)),
79 _ircParser(new IrcParser(this)),
80 scriptEngine(new QScriptEngine(this)),
81 _processMessages(false),
82 _ignoreListManager(this),
83 _highlightRuleManager(this)
85 SignalProxy *p = signalProxy();
86 p->setHeartBeatInterval(30);
87 p->setMaxHeartBeatCount(60); // 30 mins until we throw a dead socket out
89 connect(p, SIGNAL(peerRemoved(Peer*)), SLOT(removeClient(Peer*)));
91 connect(p, SIGNAL(connected()), SLOT(clientsConnected()));
92 connect(p, SIGNAL(disconnected()), SLOT(clientsDisconnected()));
94 p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromClient(BufferInfo, QString)));
95 p->attachSignal(this, SIGNAL(displayMsg(Message)));
96 p->attachSignal(this, SIGNAL(displayStatusMsg(QString, QString)));
98 p->attachSignal(this, SIGNAL(identityCreated(const Identity &)));
99 p->attachSignal(this, SIGNAL(identityRemoved(IdentityId)));
100 p->attachSlot(SIGNAL(createIdentity(const Identity &, const QVariantMap &)), this, SLOT(createIdentity(const Identity &, const QVariantMap &)));
101 p->attachSlot(SIGNAL(removeIdentity(IdentityId)), this, SLOT(removeIdentity(IdentityId)));
103 p->attachSignal(this, SIGNAL(networkCreated(NetworkId)));
104 p->attachSignal(this, SIGNAL(networkRemoved(NetworkId)));
105 p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &, const QStringList &)), this, SLOT(createNetwork(const NetworkInfo &, const QStringList &)));
106 p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, SLOT(removeNetwork(NetworkId)));
108 p->attachSlot(SIGNAL(changePassword(PeerPtr,QString,QString,QString)), this, SLOT(changePassword(PeerPtr,QString,QString,QString)));
109 p->attachSignal(this, SIGNAL(passwordChanged(PeerPtr,bool)));
111 p->attachSlot(SIGNAL(kickClient(int)), this, SLOT(kickClient(int)));
112 p->attachSignal(this, SIGNAL(disconnectFromCore()));
115 data["quasselVersion"] = Quassel::buildInfo().fancyVersionString;
116 data["quasselBuildDate"] = Quassel::buildInfo().commitDate; // "BuildDate" for compatibility
117 data["startTime"] = Core::instance()->startTime();
118 data["sessionConnectedClients"] = 0;
119 _coreInfo->setCoreData(data);
124 eventManager()->registerObject(ircParser(), EventManager::NormalPriority);
125 eventManager()->registerObject(sessionEventProcessor(), EventManager::HighPriority); // needs to process events *before* the stringifier!
126 eventManager()->registerObject(ctcpParser(), EventManager::NormalPriority);
127 eventManager()->registerObject(eventStringifier(), EventManager::NormalPriority);
128 eventManager()->registerObject(this, EventManager::LowPriority); // for sending MessageEvents to the client
129 // some events need to be handled after msg generation
130 eventManager()->registerObject(sessionEventProcessor(), EventManager::LowPriority, "lateProcess");
131 eventManager()->registerObject(ctcpParser(), EventManager::LowPriority, "send");
133 // periodically save our session state
134 connect(&(Core::instance()->syncTimer()), SIGNAL(timeout()), this, SLOT(saveSessionState()));
136 p->synchronize(_bufferSyncer);
137 p->synchronize(&aliasManager());
138 p->synchronize(_backlogManager);
139 p->synchronize(dccConfig());
140 p->synchronize(ircListHelper());
141 p->synchronize(networkConfig());
142 p->synchronize(_coreInfo);
143 p->synchronize(&_ignoreListManager);
144 p->synchronize(&_highlightRuleManager);
145 p->synchronize(transferManager());
146 // Restore session state
148 restoreSessionState();
154 CoreSession::~CoreSession()
158 /* Why partially duplicate CoreNetwork destructor? When each CoreNetwork quits in the
159 * destructor, disconnections are processed in sequence for each object. For many IRC servers
160 * on a slow network, this could significantly delay core shutdown [msecs wait * network count].
162 * Here, CoreSession first calls disconnect on all networks, letting them all start
163 * disconnecting before beginning to sequentially wait for each network. Ideally, after the
164 * first network is disconnected, the other networks will have already closed. Worst-case may
165 * still wait [msecs wait time * num. of networks], but the risk should be much lower.
167 * CoreNetwork should still do cleanup in its own destructor in case a network is deleted
168 * outside of deleting the whole CoreSession.
170 * If this proves to be problematic in the future, there's an alternative Qt signal-based system
171 * implemented in another pull request that guarentees a maximum amount of time to disconnect,
172 * but at the cost of more complex code.
174 * See https://github.com/quassel/quassel/pull/203
177 foreach(CoreNetwork *net, _networks.values()) {
178 // Request each network properly disconnect, but don't count as user-requested disconnect
179 if (net->socketConnected()) {
180 // Only try if the socket's fully connected (not initializing or disconnecting).
181 // Force an immediate disconnect, jumping the command queue. Ensures the proper QUIT is
182 // shown even if other messages are queued.
183 net->disconnectFromIrc(false, QString(), false, true);
187 // Process the putCmd events that trigger the quit. Without this, shutting down the core
188 // results in abrubtly closing the socket rather than sending the QUIT as expected.
189 QCoreApplication::processEvents();
191 foreach(CoreNetwork *net, _networks.values()) {
192 // Wait briefly for each network to disconnect. Sometimes it takes a little while to send.
193 if (!net->forceDisconnect()) {
194 qWarning() << "Timed out quitting network" << net->networkName() <<
195 "(user ID " << net->userId() << ")";
197 // Delete the network now that it's closed
203 CoreNetwork *CoreSession::network(NetworkId id) const
205 if (_networks.contains(id)) return _networks[id];
210 CoreIdentity *CoreSession::identity(IdentityId id) const
212 if (_identities.contains(id)) return _identities[id];
217 void CoreSession::loadSettings()
219 CoreUserSettings s(user());
222 QList<IdentityId> ids = s.identityIds();
223 QList<NetworkInfo> networkInfos = Core::networks(user());
224 foreach(IdentityId id, ids) {
225 CoreIdentity identity(s.identity(id));
226 IdentityId newId = Core::createIdentity(user(), identity);
227 QList<NetworkInfo>::iterator networkIter = networkInfos.begin();
228 while (networkIter != networkInfos.end()) {
229 if (networkIter->identity == id) {
230 networkIter->identity = newId;
231 Core::updateNetwork(user(), *networkIter);
232 networkIter = networkInfos.erase(networkIter);
238 s.removeIdentity(id);
242 foreach(CoreIdentity identity, Core::identities(user())) {
243 createIdentity(identity);
246 foreach(NetworkInfo info, Core::networks(user())) {
252 void CoreSession::saveSessionState() const
254 _bufferSyncer->storeDirtyIds();
255 _bufferViewManager->saveBufferViews();
256 _networkConfig->save();
260 void CoreSession::restoreSessionState()
262 QList<NetworkId> nets = Core::connectedNetworks(user());
263 CoreNetwork *net = 0;
264 foreach(NetworkId id, nets) {
272 void CoreSession::addClient(RemotePeer *peer)
274 signalProxy()->setTargetPeer(peer);
276 peer->dispatch(sessionState());
277 signalProxy()->addPeer(peer);
278 _coreInfo->setConnectedClientData(signalProxy()->peerCount(), signalProxy()->peerData());
280 signalProxy()->setTargetPeer(nullptr);
284 void CoreSession::addClient(InternalPeer *peer)
286 signalProxy()->addPeer(peer);
287 emit sessionState(sessionState());
291 void CoreSession::removeClient(Peer *peer)
293 RemotePeer *p = qobject_cast<RemotePeer *>(peer);
295 quInfo() << qPrintable(tr("Client")) << p->description() << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
296 _coreInfo->setConnectedClientData(signalProxy()->peerCount(), signalProxy()->peerData());
300 QHash<QString, QString> CoreSession::persistentChannels(NetworkId id) const
302 return Core::persistentChannels(user(), id);
306 QHash<QString, QByteArray> CoreSession::bufferCiphers(NetworkId id) const
308 return Core::bufferCiphers(user(), id);
311 void CoreSession::setBufferCipher(NetworkId id, const QString &bufferName, const QByteArray &cipher) const
313 Core::setBufferCipher(user(), id, bufferName, cipher);
317 // FIXME switch to BufferId
318 void CoreSession::msgFromClient(BufferInfo bufinfo, QString msg)
320 CoreNetwork *net = network(bufinfo.networkId());
322 net->userInput(bufinfo, msg);
325 qWarning() << "Trying to send to unconnected network:" << msg;
330 // ALL messages coming pass through these functions before going to the GUI.
331 // So this is the perfect place for storing the backlog and log stuff.
332 void CoreSession::recvMessageFromServer(NetworkId networkId, Message::Type type, BufferInfo::Type bufferType,
333 const QString &target, const QString &text_, const QString &sender, Message::Flags flags)
335 // U+FDD0 and U+FDD1 are special characters for Qt's text engine, specifically they mark the boundaries of
336 // text frames in a QTextDocument. This might lead to problems in widgets displaying QTextDocuments (such as
337 // KDE's notifications), hence we remove those just to be safe.
338 QString text = text_;
339 text.remove(QChar(0xfdd0)).remove(QChar(0xfdd1));
340 RawMessage rawMsg(networkId, type, bufferType, target, text, sender, flags);
342 // check for HardStrictness ignore
343 CoreNetwork *currentNetwork = network(networkId);
344 QString networkName = currentNetwork ? currentNetwork->networkName() : QString("");
345 if (_ignoreListManager.match(rawMsg, networkName) == IgnoreListManager::HardStrictness)
348 if (_highlightRuleManager.match(rawMsg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
349 rawMsg.flags |= Message::Flag::Highlight;
351 _messageQueue << rawMsg;
352 if (!_processMessages) {
353 _processMessages = true;
354 QCoreApplication::postEvent(this, new ProcessMessagesEvent());
359 void CoreSession::recvStatusMsgFromServer(QString msg)
361 CoreNetwork *net = qobject_cast<CoreNetwork *>(sender());
363 emit displayStatusMsg(net->networkName(), msg);
367 void CoreSession::processMessageEvent(MessageEvent *event)
369 recvMessageFromServer(event->networkId(), event->msgType(), event->bufferType(),
370 event->target().isNull() ? "" : event->target(),
371 event->text().isNull() ? "" : event->text(),
372 event->sender().isNull() ? "" : event->sender(),
377 QList<BufferInfo> CoreSession::buffers() const
379 return Core::requestBuffers(user());
383 void CoreSession::customEvent(QEvent *event)
385 if (event->type() != QEvent::User)
393 void CoreSession::processMessages()
395 if (_messageQueue.count() == 1) {
396 const RawMessage &rawMsg = _messageQueue.first();
397 bool createBuffer = !(rawMsg.flags & Message::Redirected);
398 BufferInfo bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, rawMsg.bufferType, rawMsg.target, createBuffer);
399 if (!bufferInfo.isValid()) {
400 Q_ASSERT(!createBuffer);
401 bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, BufferInfo::StatusBuffer, "");
403 Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, senderPrefixes(rawMsg.sender, bufferInfo),
404 realName(rawMsg.sender, rawMsg.networkId), avatarUrl(rawMsg.sender, rawMsg.networkId),
406 if(Core::storeMessage(msg))
407 emit displayMsg(msg);
410 QHash<NetworkId, QHash<QString, BufferInfo> > bufferInfoCache;
411 MessageList messages;
412 QList<RawMessage> redirectedMessages; // list of Messages which don't enforce a buffer creation
413 BufferInfo bufferInfo;
414 for (int i = 0; i < _messageQueue.count(); i++) {
415 const RawMessage &rawMsg = _messageQueue.at(i);
416 if (bufferInfoCache.contains(rawMsg.networkId) && bufferInfoCache[rawMsg.networkId].contains(rawMsg.target)) {
417 bufferInfo = bufferInfoCache[rawMsg.networkId][rawMsg.target];
420 bool createBuffer = !(rawMsg.flags & Message::Redirected);
421 bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, rawMsg.bufferType, rawMsg.target, createBuffer);
422 if (!bufferInfo.isValid()) {
423 Q_ASSERT(!createBuffer);
424 redirectedMessages << rawMsg;
427 bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo;
429 Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, senderPrefixes(rawMsg.sender, bufferInfo),
430 realName(rawMsg.sender, rawMsg.networkId), avatarUrl(rawMsg.sender, rawMsg.networkId),
435 // recheck if there exists a buffer to store a redirected message in
436 for (int i = 0; i < redirectedMessages.count(); i++) {
437 const RawMessage &rawMsg = redirectedMessages.at(i);
438 if (bufferInfoCache.contains(rawMsg.networkId) && bufferInfoCache[rawMsg.networkId].contains(rawMsg.target)) {
439 bufferInfo = bufferInfoCache[rawMsg.networkId][rawMsg.target];
442 // no luck -> we store them in the StatusBuffer
443 bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, BufferInfo::StatusBuffer, "");
444 // add the StatusBuffer to the Cache in case there are more Messages for the original target
445 bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo;
447 Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, senderPrefixes(rawMsg.sender, bufferInfo),
448 realName(rawMsg.sender, rawMsg.networkId), avatarUrl(rawMsg.sender, rawMsg.networkId),
453 if(Core::storeMessages(messages)) {
454 // FIXME: extend protocol to a displayMessages(MessageList)
455 for (int i = 0; i < messages.count(); i++) {
456 emit displayMsg(messages[i]);
460 _processMessages = false;
461 _messageQueue.clear();
464 QString CoreSession::senderPrefixes(const QString &sender, const BufferInfo &bufferInfo) const
466 CoreNetwork *currentNetwork = network(bufferInfo.networkId());
467 if (!currentNetwork) {
471 if (bufferInfo.type() != BufferInfo::ChannelBuffer) {
475 IrcChannel *currentChannel = currentNetwork->ircChannel(bufferInfo.bufferName());
476 if (!currentChannel) {
480 const QString modes = currentChannel->userModes(nickFromMask(sender).toLower());
481 return currentNetwork->modesToPrefixes(modes);
484 QString CoreSession::realName(const QString &sender, NetworkId networkId) const
486 CoreNetwork *currentNetwork = network(networkId);
487 if (!currentNetwork) {
491 IrcUser *currentUser = currentNetwork->ircUser(nickFromMask(sender));
496 return currentUser->realName();
499 QString CoreSession::avatarUrl(const QString &sender, NetworkId networkId) const
503 // Currently we do not have a way to retrieve this value yet.
505 // This likely will require implementing IRCv3's METADATA spec.
506 // See https://ircv3.net/irc/
507 // And https://blog.irccloud.com/avatars/
511 Protocol::SessionState CoreSession::sessionState() const
513 QVariantList bufferInfos;
514 QVariantList networkIds;
515 QVariantList identities;
517 foreach(const BufferInfo &id, buffers())
518 bufferInfos << QVariant::fromValue(id);
519 foreach(const NetworkId &id, _networks.keys())
520 networkIds << QVariant::fromValue(id);
521 foreach(const Identity *i, _identities.values())
522 identities << QVariant::fromValue(*i);
524 return Protocol::SessionState(identities, bufferInfos, networkIds);
528 void CoreSession::initScriptEngine()
530 signalProxy()->attachSlot(SIGNAL(scriptRequest(QString)), this, SLOT(scriptRequest(QString)));
531 signalProxy()->attachSignal(this, SIGNAL(scriptResult(QString)));
534 //QScriptValue storage_ = scriptEngine->newQObject(storage);
535 //scriptEngine->globalObject().setProperty("storage", storage_);
539 void CoreSession::scriptRequest(QString script)
541 emit scriptResult(scriptEngine->evaluate(script).toString());
545 /*** Identity Handling ***/
546 void CoreSession::createIdentity(const Identity &identity, const QVariantMap &additional)
552 CoreIdentity coreIdentity(identity);
554 if (additional.contains("KeyPem"))
555 coreIdentity.setSslKey(additional["KeyPem"].toByteArray());
556 if (additional.contains("CertPem"))
557 coreIdentity.setSslCert(additional["CertPem"].toByteArray());
559 qDebug() << Q_FUNC_INFO;
560 IdentityId id = Core::createIdentity(user(), coreIdentity);
564 createIdentity(coreIdentity);
567 const QString CoreSession::strictCompliantIdent(const CoreIdentity *identity) {
568 if (_strictIdentEnabled) {
569 // Strict mode enabled: only allow the user's Quassel username as an ident
570 return Core::instance()->strictSysIdent(_user);
572 // Strict mode disabled: allow any identity specified
573 return identity->ident();
577 void CoreSession::createIdentity(const CoreIdentity &identity)
579 CoreIdentity *coreIdentity = new CoreIdentity(identity, this);
580 _identities[identity.id()] = coreIdentity;
581 // CoreIdentity has its own synchronize method since its "private" sslManager needs to be synced as well
582 coreIdentity->synchronize(signalProxy());
583 connect(coreIdentity, SIGNAL(updated()), this, SLOT(updateIdentityBySender()));
584 emit identityCreated(*coreIdentity);
588 void CoreSession::updateIdentityBySender()
590 CoreIdentity *identity = qobject_cast<CoreIdentity *>(sender());
593 Core::updateIdentity(user(), *identity);
597 void CoreSession::removeIdentity(IdentityId id)
599 CoreIdentity *identity = _identities.take(id);
601 emit identityRemoved(id);
602 Core::removeIdentity(user(), id);
603 identity->deleteLater();
608 /*** Network Handling ***/
610 void CoreSession::createNetwork(const NetworkInfo &info_, const QStringList &persistentChans)
612 NetworkInfo info = info_;
615 if (!info.networkId.isValid())
616 Core::createNetwork(user(), info);
618 if (!info.networkId.isValid()) {
619 qWarning() << qPrintable(tr("CoreSession::createNetwork(): Got invalid networkId from Core when trying to create network %1!").arg(info.networkName));
623 id = info.networkId.toInt();
624 if (!_networks.contains(id)) {
625 // create persistent chans
626 QRegExp rx("\\s*(\\S+)(?:\\s*(\\S+))?\\s*");
627 foreach(QString channel, persistentChans) {
628 if (!rx.exactMatch(channel)) {
629 qWarning() << QString("Invalid persistent channel declaration: %1").arg(channel);
632 Core::bufferInfo(user(), info.networkId, BufferInfo::ChannelBuffer, rx.cap(1), true);
633 Core::setChannelPersistent(user(), info.networkId, rx.cap(1), true);
634 if (!rx.cap(2).isEmpty())
635 Core::setPersistentChannelKey(user(), info.networkId, rx.cap(1), rx.cap(2));
638 CoreNetwork *net = new CoreNetwork(id, this);
639 connect(net, SIGNAL(displayMsg(NetworkId, Message::Type, BufferInfo::Type, const QString &, const QString &, const QString &, Message::Flags)),
640 SLOT(recvMessageFromServer(NetworkId, Message::Type, BufferInfo::Type, const QString &, const QString &, const QString &, Message::Flags)));
641 connect(net, SIGNAL(displayStatusMsg(QString)), SLOT(recvStatusMsgFromServer(QString)));
642 connect(net, SIGNAL(disconnected(NetworkId)), SIGNAL(networkDisconnected(NetworkId)));
644 net->setNetworkInfo(info);
645 net->setProxy(signalProxy());
647 signalProxy()->synchronize(net);
648 emit networkCreated(id);
651 qWarning() << qPrintable(tr("CoreSession::createNetwork(): Trying to create a network that already exists, updating instead!"));
652 _networks[info.networkId]->requestSetNetworkInfo(info);
657 void CoreSession::removeNetwork(NetworkId id)
659 // Make sure the network is disconnected!
660 CoreNetwork *net = network(id);
664 if (net->connectionState() != Network::Disconnected) {
665 // make sure we no longer receive data from the tcp buffer
666 disconnect(net, SIGNAL(displayMsg(NetworkId, Message::Type, BufferInfo::Type, const QString &, const QString &, const QString &, Message::Flags)), this, 0);
667 disconnect(net, SIGNAL(displayStatusMsg(QString)), this, 0);
668 connect(net, SIGNAL(disconnected(NetworkId)), this, SLOT(destroyNetwork(NetworkId)));
669 net->disconnectFromIrc();
677 void CoreSession::destroyNetwork(NetworkId id)
679 QList<BufferId> removedBuffers = Core::requestBufferIdsForNetwork(user(), id);
680 Network *net = _networks.take(id);
681 if (net && Core::removeNetwork(user(), id)) {
682 // make sure that all unprocessed RawMessages from this network are removed
683 QList<RawMessage>::iterator messageIter = _messageQueue.begin();
684 while (messageIter != _messageQueue.end()) {
685 if (messageIter->networkId == id) {
686 messageIter = _messageQueue.erase(messageIter);
692 // remove buffers from syncer
693 foreach(BufferId bufferId, removedBuffers) {
694 _bufferSyncer->removeBuffer(bufferId);
696 emit networkRemoved(id);
702 void CoreSession::renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName)
704 BufferInfo bufferInfo = Core::bufferInfo(user(), networkId, BufferInfo::QueryBuffer, oldName, false);
705 if (bufferInfo.isValid()) {
706 _bufferSyncer->renameBuffer(bufferInfo.bufferId(), newName);
711 void CoreSession::clientsConnected()
713 QHash<NetworkId, CoreNetwork *>::iterator netIter = _networks.begin();
714 Identity *identity = 0;
715 CoreNetwork *net = 0;
717 while (netIter != _networks.end()) {
721 if (!net->isConnected())
723 identity = net->identityPtr();
730 if (identity->detachAwayEnabled() && me->isAway()) {
731 net->userInputHandler()->handleAway(BufferInfo(), QString());
737 void CoreSession::clientsDisconnected()
739 QHash<NetworkId, CoreNetwork *>::iterator netIter = _networks.begin();
740 Identity *identity = 0;
741 CoreNetwork *net = 0;
744 while (netIter != _networks.end()) {
748 if (!net->isConnected())
751 identity = net->identityPtr();
758 if (identity->detachAwayEnabled() && !me->isAway()) {
759 if (!identity->detachAwayReason().isEmpty())
760 awayReason = identity->detachAwayReason();
761 net->setAutoAwayActive(true);
762 // Allow handleAway() to format the current date/time in the string.
763 net->userInputHandler()->handleAway(BufferInfo(), awayReason);
769 void CoreSession::globalAway(const QString &msg, const bool skipFormatting)
771 QHash<NetworkId, CoreNetwork *>::iterator netIter = _networks.begin();
772 CoreNetwork *net = 0;
773 while (netIter != _networks.end()) {
777 if (!net->isConnected())
780 net->userInputHandler()->issueAway(msg, false /* no force away */, skipFormatting);
784 void CoreSession::changePassword(PeerPtr peer, const QString &userName, const QString &oldPassword, const QString &newPassword) {
787 bool success = false;
788 UserId uid = Core::validateUser(userName, oldPassword);
789 if (uid.isValid() && uid == user())
790 success = Core::changeUserPassword(uid, newPassword);
792 signalProxy()->restrictTargetPeers(signalProxy()->sourcePeer(), [&]{
793 emit passwordChanged(nullptr, success);
797 void CoreSession::kickClient(int peerId) {
798 auto peer = signalProxy()->peerById(peerId);
799 if (peer == nullptr) {
800 qWarning() << "Invalid peer Id: " << peerId;
803 signalProxy()->restrictTargetPeers(peer, [&]{
804 emit disconnectFromCore();