Don't always add a colon to custom commands
[quassel.git] / src / core / corenetwork.cpp
index 101f527..954565c 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2014 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -40,10 +40,10 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
 
     _lastPingTime(0),
     _pingCount(0),
+    _sendPings(false),
     _requestedUserModes('-')
 {
     _autoReconnectTimer.setSingleShot(true);
-    _socketCloseTimer.setSingleShot(true);
     connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
 
     setPingInterval(networkConfig()->pingInterval());
@@ -182,8 +182,9 @@ void CoreNetwork::connectToIrc(bool reconnecting)
         socket.setProxy(QNetworkProxy::NoProxy);
     }
 
+    enablePingTimeout();
+
 #ifdef HAVE_SSL
-    socket.setProtocol((QSsl::SslProtocol)server.sslVersion);
     if (server.useSsl) {
         CoreIdentity *identity = identityPtr();
         if (identity) {
@@ -263,11 +264,14 @@ void CoreNetwork::putCmd(const QString &cmd, const QList<QByteArray> &params, co
         msg += ":" + prefix + " ";
     msg += cmd.toUpper().toAscii();
 
-    for (int i = 0; i < params.size() - 1; i++) {
-        msg += " " + params[i];
+    for (int i = 0; i < params.size(); i++) {
+        msg += " ";
+
+        if (i == params.size() - 1 && (params[i].contains(' ') || (!params[i].isEmpty() && params[i][0] == ':')))
+            msg += ":";
+
+        msg += params[i];
     }
-    if (!params.isEmpty())
-        msg += " :" + params.last();
 
     putRawLine(msg);
 }
@@ -363,6 +367,19 @@ void CoreNetwork::setCipherKey(const QString &target, const QByteArray &key)
         return;
     }
 }
+
+
+bool CoreNetwork::cipherUsesCBC(const QString &target)
+{
+    CoreIrcChannel *c = qobject_cast<CoreIrcChannel*>(ircChannel(target));
+    if (c)
+        return c->cipher()->usesCBC();
+    CoreIrcUser *u = qobject_cast<CoreIrcUser*>(ircUser(target));
+    if (u)
+        return u->cipher()->usesCBC();
+
+    return false;
+}
 #endif /* HAVE_QCA2 */
 
 bool CoreNetwork::setAutoWhoDone(const QString &channel)
@@ -423,7 +440,9 @@ void CoreNetwork::socketInitialized()
     if (server.useSsl && !socket.isEncrypted())
         return;
 #endif
-
+#if QT_VERSION >= 0x040600
+    socket.setSocketOption(QAbstractSocket::KeepAliveOption, true);
+#endif
     CoreIdentity *identity = identityPtr();
     if (!identity) {
         qCritical() << "Identity invalid!";
@@ -538,7 +557,7 @@ void CoreNetwork::networkInitialized()
 
     sendPerform();
 
-    enablePingTimeout();
+    _sendPings = true;
 
     if (networkConfig()->autoWhoEnabled()) {
         _autoWhoCycleTimer.start();
@@ -782,7 +801,9 @@ void CoreNetwork::sendPing()
     else {
         _lastPingTime = now;
         _pingCount++;
-        userInputHandler()->handlePing(BufferInfo(), QString());
+        // Don't send pings until the network is initialized
+        if(_sendPings)
+            userInputHandler()->handlePing(BufferInfo(), QString());
     }
 }
 
@@ -802,6 +823,7 @@ void CoreNetwork::enablePingTimeout(bool enable)
 void CoreNetwork::disablePingTimeout()
 {
     _pingTimer.stop();
+    _sendPings = false;
     resetPingTimeout();
 }