core: Allow clean shutdown of the core
[quassel.git] / src / core / coresession.cpp
index 359c365..8d08d5b 100644 (file)
@@ -154,7 +154,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, bool strictIdentEnabled,
 }
 
 
-CoreSession::~CoreSession()
+void CoreSession::shutdown()
 {
     saveSessionState();
 
@@ -200,6 +200,11 @@ CoreSession::~CoreSession()
         // Delete the network now that it's closed
         delete net;
     }
+
+    _networks.clear();
+
+    // Suicide
+    deleteLater();
 }
 
 
@@ -348,7 +353,8 @@ void CoreSession::recvMessageFromServer(NetworkId networkId, Message::Type type,
     if (_ignoreListManager.match(rawMsg, networkName) == IgnoreListManager::HardStrictness)
         return;
 
-    if (_highlightRuleManager.match(rawMsg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
+
+    if (currentNetwork && _highlightRuleManager.match(rawMsg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
         rawMsg.flags |= Message::Flag::Highlight;
 
     _messageQueue << rawMsg;