+void CoreNetwork::updatePersistentModes(QString addModes, QString removeModes)
+{
+ QString persistentUserModes = Core::userModes(userId(), networkId());
+
+ QString requestedAdd = _requestedUserModes.section('-', 0, 0);
+ QString requestedRemove = _requestedUserModes.section('-', 1);
+
+ QString persistentAdd, persistentRemove;
+ if (persistentUserModes.contains('-')) {
+ persistentAdd = persistentUserModes.section('-', 0, 0);
+ persistentRemove = persistentUserModes.section('-', 1);
+ }
+ else {
+ persistentAdd = persistentUserModes;
+ }
+
+ // remove modes we didn't issue
+ if (requestedAdd.isEmpty())
+ addModes = QString();
+ else
+ addModes.remove(QRegExp(QString("[^%1]").arg(requestedAdd)));
+
+ if (requestedRemove.isEmpty())
+ removeModes = QString();
+ else
+ removeModes.remove(QRegExp(QString("[^%1]").arg(requestedRemove)));
+
+ // deduplicate
+ persistentAdd.remove(QRegExp(QString("[%1]").arg(addModes)));
+ persistentRemove.remove(QRegExp(QString("[%1]").arg(removeModes)));
+
+ // update
+ persistentAdd.remove(QRegExp(QString("[%1]").arg(removeModes)));
+ persistentRemove.remove(QRegExp(QString("[%1]").arg(addModes)));
+
+ // update issued mode list
+ requestedAdd.remove(QRegExp(QString("[%1]").arg(addModes)));
+ requestedRemove.remove(QRegExp(QString("[%1]").arg(removeModes)));
+ _requestedUserModes = QString("%1-%2").arg(requestedAdd).arg(requestedRemove);
+
+ persistentAdd += addModes;
+ persistentRemove += removeModes;
+ Core::setUserModes(userId(), networkId(), QString("%1-%2").arg(persistentAdd).arg(persistentRemove));
+}
+
+
+void CoreNetwork::resetPersistentModes()
+{
+ _requestedUserModes = QString('-');
+ Core::setUserModes(userId(), networkId(), QString());
+}
+
+
+void CoreNetwork::setUseAutoReconnect(bool use)
+{
+ Network::setUseAutoReconnect(use);
+ if (!use)
+ _autoReconnectTimer.stop();
+}
+
+
+void CoreNetwork::setAutoReconnectInterval(quint32 interval)
+{
+ Network::setAutoReconnectInterval(interval);
+ _autoReconnectTimer.setInterval(interval * 1000);
+}
+
+
+void CoreNetwork::setAutoReconnectRetries(quint16 retries)
+{
+ Network::setAutoReconnectRetries(retries);
+ if (_autoReconnectCount != 0) {
+ if (unlimitedReconnectRetries())
+ _autoReconnectCount = -1;
+ else
+ _autoReconnectCount = autoReconnectRetries();
+ }
+}
+
+
+void CoreNetwork::doAutoReconnect()
+{
+ if (connectionState() != Network::Disconnected && connectionState() != Network::Reconnecting) {
+ qWarning() << "CoreNetwork::doAutoReconnect(): Cannot reconnect while not being disconnected!";
+ return;
+ }
+ if (_autoReconnectCount > 0 || _autoReconnectCount == -1)
+ _autoReconnectCount--; // -2 means we delay the next reconnect
+ connectToIrc(true);
+}
+
+
+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();
+ }
+}
+