-void CoreNetwork::connectToIrc(bool reconnecting) {
- if(!reconnecting && useAutoReconnect() && _autoReconnectCount == 0) {
- _autoReconnectTimer.setInterval(autoReconnectInterval() * 1000);
- if(unlimitedReconnectRetries())
- _autoReconnectCount = -1;
- else
- _autoReconnectCount = autoReconnectRetries();
- }
- if(serverList().isEmpty()) {
- qWarning() << "Server list empty, ignoring connect request!";
- return;
- }
- Identity *identity = identityPtr();
- if(!identity) {
- qWarning() << "Invalid identity configures, ignoring connect request!";
- return;
- }
- // use a random server?
- if(useRandomServer()) {
- _lastUsedServerIndex = qrand() % serverList().size();
- } else if(_previousConnectionAttemptFailed) {
- // cycle to next server if previous connection attempt failed
- displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Connection failed. Cycling to next Server"));
- if(++_lastUsedServerIndex == serverList().size()) {
- _lastUsedServerIndex = 0;
- }
- }
- _previousConnectionAttemptFailed = false;
-
- Server server = usedServer();
- displayStatusMsg(tr("Connecting to %1:%2...").arg(server.host).arg(server.port));
- displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Connecting to %1:%2...").arg(server.host).arg(server.port));
- socket.connectToHost(server.host, server.port);
-}
-
-void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason) {
- _quitRequested = requested; // see socketDisconnected();
- _autoReconnectTimer.stop();
- _autoReconnectCount = 0; // prohibiting auto reconnect
- displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting."));
- if(socket.state() == QAbstractSocket::UnconnectedState) {
- socketDisconnected();
- } else if(socket.state() < QAbstractSocket::ConnectedState || !requested) {
- // we might be in a state waiting for a timeout...
- // or (!requested) this is a core shutdown...
- // in both cases we don't really care... set a disconnected state
- socket.close();
- socketDisconnected();
- } else {
- // quit gracefully if it's user requested quit
- userInputHandler()->issueQuit(reason);
- // the irc server has 10 seconds to close the socket
- _socketCloseTimer.start(10000);
- }
-}
-
-void CoreNetwork::userInput(BufferInfo buf, QString msg) {
- userInputHandler()->handleUserInput(buf, msg);
-}
-
-void CoreNetwork::putRawLine(QByteArray s) {
- if(_tokenBucket > 0)
- writeToSocket(s);
- else
- _msgQueue.append(s);
-}
-
-void CoreNetwork::putCmd(const QString &cmd, const QList<QByteArray> ¶ms, const QByteArray &prefix) {
- QByteArray msg;
-
- if(!prefix.isEmpty())
- msg += ":" + prefix + " ";
- msg += cmd.toUpper().toAscii();
-
- for(int i = 0; i < params.size() - 1; i++) {
- msg += " " + params[i];
- }
- if(!params.isEmpty())
- msg += " :" + params.last();
-
- putRawLine(msg);
-}
-
-void CoreNetwork::setChannelJoined(const QString &channel) {
- _autoWhoQueue.prepend(channel.toLower()); // prepend so this new chan is the first to be checked
-
- Core::setChannelPersistent(userId(), networkId(), channel, true);
- Core::setPersistentChannelKey(userId(), networkId(), channel, _channelKeys[channel.toLower()]);
-}
-
-void CoreNetwork::setChannelParted(const QString &channel) {
- removeChannelKey(channel);
- _autoWhoQueue.removeAll(channel.toLower());
- _autoWhoInProgress.remove(channel.toLower());
-
- Core::setChannelPersistent(userId(), networkId(), channel, false);
-}
-
-void CoreNetwork::addChannelKey(const QString &channel, const QString &key) {
- if(key.isEmpty()) {