+
+void CoreNetwork::sendPing()
+{
+ uint now = QDateTime::currentDateTime().toTime_t();
+ if (_pingCount != 0) {
+ qDebug() << "UserId:" << userId() << "Network:" << networkName() << "missed" << _pingCount << "pings."
+ << "BA:" << socket.bytesAvailable() << "BTW:" << socket.bytesToWrite();
+ }
+ if ((int)_pingCount >= networkConfig()->maxPingCount() && now - _lastPingTime <= (uint)(_pingTimer.interval() / 1000) + 1) {
+ // the second check compares the actual elapsed time since the last ping and the pingTimer interval
+ // if the interval is shorter then the actual elapsed time it means that this thread was somehow blocked
+ // and unable to even handle a ping answer. So we ignore those misses.
+ disconnectFromIrc(false, QString("No Ping reply in %1 seconds.").arg(_pingCount * _pingTimer.interval() / 1000), true /* withReconnect */);
+ }
+ else {
+ _lastPingTime = now;
+ _pingCount++;
+ // Don't send pings until the network is initialized
+ if(_sendPings)
+ userInputHandler()->handlePing(BufferInfo(), QString());
+ }
+}
+
+
+void CoreNetwork::enablePingTimeout(bool enable)
+{
+ if (!enable)
+ disablePingTimeout();
+ else {
+ resetPingTimeout();
+ if (networkConfig()->pingTimeoutEnabled())
+ _pingTimer.start();
+ }
+}
+
+
+void CoreNetwork::disablePingTimeout()
+{
+ _pingTimer.stop();
+ _sendPings = false;
+ resetPingTimeout();
+}
+
+
+void CoreNetwork::setPingInterval(int interval)
+{
+ _pingTimer.setInterval(interval * 1000);
+}
+
+/******** IRCv3 Capability Negotiation ********/
+
+void CoreNetwork::addCap(const QString &capability, const QString &value)
+{
+ // Clear from pending list, add to supported list
+ if (!_capsSupported.contains(capability)) {
+ if (value != "") {
+ // Value defined, just use it
+ _capsSupported[capability] = value;
+ } else if (_capsPending.contains(capability)) {
+ // Value not defined, but a pending capability had a value.
+ // E.g. CAP * LS :sasl=PLAIN multi-prefix
+ // Preserve the capability value for later use.
+ _capsSupported[capability] = _capsPending[capability];
+ } else {
+ // No value ever given, assign to blank
+ _capsSupported[capability] = QString();
+ }
+ }
+ if (_capsPending.contains(capability))
+ _capsPending.remove(capability);
+
+ // Handle special cases here
+ // TODO Use events if it makes sense
+ if (capability == "away-notify") {
+ // away-notify enabled, stop the automatic timers, handle manually
+ setAutoWhoEnabled(false);
+ }
+}
+
+void CoreNetwork::removeCap(const QString &capability)
+{
+ // Clear from pending list, remove from supported list
+ if (_capsPending.contains(capability))
+ _capsPending.remove(capability);
+ if (_capsSupported.contains(capability))
+ _capsSupported.remove(capability);
+
+ // Handle special cases here
+ // TODO Use events if it makes sense
+ if (capability == "away-notify") {
+ // away-notify disabled, enable autowho according to configuration
+ setAutoWhoEnabled(networkConfig()->autoWhoEnabled());
+ }
+}
+
+QString CoreNetwork::capValue(const QString &capability) const
+{
+ // If a supported capability exists, good; if not, return pending value.
+ // If capability isn't supported after all, the pending entry will be removed.
+ if (_capsSupported.contains(capability))
+ return _capsSupported[capability];
+ else if (_capsPending.contains(capability))
+ return _capsPending[capability];