void DatabaseLite::LoadSessions() { std::shared_ptr<SqlResult> networks = this->database->ExecuteQuery("SELECT id, network_id, user_id, hostname, port, ssl, nick, ident, system_id, password, scrollback_list, name FROM networks;"); if (networks->InError) throw new Exception("Unable to load networks from db: " + this->LastError, BOOST_CURRENT_FUNCTION); unsigned int network = 0; unsigned int lnid = 0; while (network < networks->Count()) { SqlRow row = networks->GetRow(network++); unsigned int nid = row.GetField(1).toUInt(); User *user = User::GetUser(row.GetField(2).toUInt()); if (!user) { if (!CONF->AutoFix) { GRUMPY_ERROR("Missing owner for a network, skipping initialization of scrollback, please run grumpyd with --cleanup parameter to fix this issue permanently"); } else { GRUMPY_LOG("Removing network with no owner: " + QString::number(row.GetField(0).toInt())); this->database->ExecuteNonQuery("DELETE FROM networks WHERE id = " + QString::number(row.GetField(0).toInt()) + ";"); } continue; } Scrollback *system = user->GetScrollback(row.GetField(8).toUInt()); if (!system) { if (!CONF->AutoFix) { GRUMPY_ERROR("Missing system window for a network, skipping initialization, please run grumpyd with --cleanup parameter to fix this issue permanently"); } else { GRUMPY_LOG("Removing network with no system window: " + QString::number(row.GetField(0).toInt())); this->database->ExecuteNonQuery("DELETE FROM networks WHERE id = " + QString::number(row.GetField(0).toInt()) + ";"); } continue; } QList<Scrollback*> scrollback_list; QList<scrollback_id_t> scrollback_temp = StringToList(row.GetField(10).toString()); system->SetDead(true); SyncableIRCSession *session = NULL; foreach (scrollback_id_t item, scrollback_temp) { Scrollback *scrollback = user->GetScrollback(item); if (!scrollback) { if (!CONF->AutoFix) { GRUMPY_ERROR("Missing window for a network, skipping initialization, please run grumpyd with --cleanup parameter to fix this issue permanently"); } else { GRUMPY_LOG("Removing network with no window: " + QString::number(row.GetField(0).toInt())); this->database->ExecuteNonQuery("DELETE FROM networks WHERE id = " + QString::number(row.GetField(0).toInt()) + ";"); } goto next; } scrollback->SetDead(true); scrollback_list.append(scrollback); } session = new SyncableIRCSession(nid, system, user, scrollback_list); session->SetHostname(row.GetField(3).toString()); session->SetIdent(row.GetField(7).toString()); session->SetNick(row.GetField(6).toString()); session->SetSSL(Generic::Int2Bool(row.GetField(5).toInt())); session->SetPort(row.GetField(4).toUInt()); session->SetName(row.GetField(11).toString()); if (lnid < nid) lnid = nid; user->RegisterSession(session); next: continue; }