X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcore.cpp;h=e222a137df29c28e65c98358ab771f95a7339349;hp=32337988388958a0b9b376beec2a8c89a613339e;hb=6f2f1723f5bb3d26908f6dd297890f6fba43793b;hpb=d1b6499b0b848d4287efae89107576548533502c diff --git a/src/core/core.cpp b/src/core/core.cpp index 32337988..e222a137 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -95,37 +95,35 @@ Core::~Core() { } void Core::restoreState() { - return; - /* - Q_ASSERT(!instance()->sessions.count()); + if(instance()->sessions.count()) { + qWarning() << qPrintable(tr("Calling restoreState() even though active sessions exist!")); + return; + } CoreSettings s; - QList users = s.coreState().toList(); - if(users.count() > 0) { + uint build = s.coreState().toMap()["CoreBuild"].toUInt(); + if(build < 362) { + qWarning() << qPrintable(tr("Core state too old, ignoring...")); + return; + } + QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList(); + if(activeSessions.count() > 0) { qDebug() << "Restoring previous core state..."; - foreach(QVariant v, users) { - QVariantMap m = v.toMap(); - if(m.contains("UserId")) { - CoreSession *sess = createSession(m["UserId"].toUInt()); - sess->restoreState(m["State"]); // FIXME multithreading - } + foreach(QVariant v, activeSessions) { + UserId user = v.value(); + instance()->createSession(user, true); } qDebug() << "...done."; } - */ } void Core::saveState() { - /* CoreSettings s; - QList users; - foreach(CoreSession *sess, instance()->sessions.values()) { - QVariantMap m; - m["UserId"] = sess->user(); // FIXME multithreading - m["State"] = sess->state(); - users << m; - } - s.setCoreState(users); - */ + QVariantMap state; + QVariantList activeSessions; + foreach(UserId user, instance()->sessions.keys()) activeSessions << QVariant::fromValue(user); + state["CoreBuild"] = Global::quasselBuild; + state["ActiveSessions"] = activeSessions; + s.setCoreState(state); } /*** Storage Access ***/ @@ -254,7 +252,7 @@ void Core::clientHasData() { mutex.lock(); UserId uid = storage->validateUser(msg["User"].toString(), msg["Password"].toString()); mutex.unlock(); - if(!uid) { + if(uid == 0) { reply["MsgType"] = "ClientLoginReject"; reply["Error"] = tr("Invalid username or password!
The username/password combination you supplied could not be found in the database."); SignalProxy::writeDataToDevice(socket, reply); @@ -308,15 +306,6 @@ void Core::clientDisconnected() { // Suggestion: kill sessions if they are not connected to any network and client. } - - //disconnect(socket, 0, this, 0); - /* - sessions[uid]->addClient(socket); // FIXME multithreading - qDebug() << "Client initialized successfully."; - SignalProxy::writeDataToDevice(socket, reply); - */ - - void Core::processCoreSetup(QTcpSocket *socket, QVariantMap &msg) { if(msg["HasSettings"].toBool()) { QVariantMap auth; @@ -366,12 +355,12 @@ void Core::setupClientSession(QTcpSocket *socket, UserId uid) { sess->addClient(socket); } -SessionThread *Core::createSession(UserId uid) { +SessionThread *Core::createSession(UserId uid, bool restore) { if(sessions.contains(uid)) { qWarning() << "Calling createSession() when a session for the user already exists!"; return 0; } - SessionThread *sess = new SessionThread(uid, this); + SessionThread *sess = new SessionThread(uid, restore, this); sessions[uid] = sess; sess->start(); return sess;