X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcore%2Fcore.cpp;h=79433b9471b8e15c93fffc74a4c6ea2174de3b9f;hb=b84f31a79b8cc8b69db7b21723493224334575b6;hp=31a409f51b9b9b6588b2115bec32f76db6849850;hpb=0b25f3d02a72ebe2953441f36fd6595bb9fb4e22;p=quassel.git diff --git a/src/core/core.cpp b/src/core/core.cpp index 31a409f5..79433b94 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -89,8 +89,8 @@ void Core::init() { } Core::~Core() { - foreach(QTcpSocket *socket, blocksizes.keys()) { qDebug() << "disconnecting" << socket << blocksizes.keys(); - socket->disconnectFromHost(); // disconnect local (i.e. non-authed) clients + foreach(QTcpSocket *socket, blocksizes.keys()) { + socket->disconnectFromHost(); // disconnect non authed clients } qDeleteAll(sessions); qDeleteAll(_storageBackends); @@ -394,8 +394,10 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) { QVariantMap reply; // Just version information -- check it! - if((msg.contains("ClientBuild") && msg["ClientBuild"].toUInt() < 732) - || (!msg.contains("ClientBuild") && msg["ProtocolVersion"].toUInt() < Global::coreNeedsProtocol)) { + uint ver = 0; + if(!msg.contains("ProtocolVersion") && msg["ClientBuild"].toUInt() >= 732) ver = 1; // FIXME legacy + if(msg.contains("ProtocolVersion")) ver = msg["ProtocolVersion"].toUInt(); + if(ver < Global::coreNeedsProtocol) { reply["MsgType"] = "ClientInitReject"; reply["Error"] = tr("Your Quassel Client is too old!
" "This core needs at least client/core protocol version %1.
" @@ -515,13 +517,34 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) { // Potentially called during the initialization phase (before handing the connection off to the session) void Core::clientDisconnected() { - QTcpSocket *socket = dynamic_cast(sender()); // Note: This might be a QObject* already (if called by ~Core())! - Q_ASSERT(socket); - blocksizes.remove(socket); - clientInfo.remove(socket); - qDebug() << qPrintable(tr("Non-authed client disconnected.")); - socket->deleteLater(); - socket = 0; + QTcpSocket *socket = qobject_cast(sender()); + if(socket) { + // here it's safe to call methods on socket! + qDebug() << qPrintable(tr("Non-authed client disconnected.")) << qPrintable(socket->peerAddress().toString()); + socket->deleteLater(); + } else { + // we have to crawl through the hashes and see if we find a victim to remove + + // DO NOT CALL ANY METHODS ON socket!! + socket = static_cast(sender()); + + QHash::iterator blockSizeIter = blocksizes.begin(); + while(blockSizeIter != blocksizes.end()) { + if(blockSizeIter.key() == socket) { + blocksizes.erase(blockSizeIter); + } + blockSizeIter++; + } + + QHash::iterator clientInfoIter = clientInfo.begin(); + while(clientInfoIter != clientInfo.end()) { + if(clientInfoIter.key() == socket) { + clientInfo.erase(clientInfoIter); + } + clientInfoIter++; + } + } + // make server listen again if still not configured if (!configured) {