From 62a5c70c8c9287a09793a686a790e625e416f557 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 4 Sep 2025 16:55:23 +0200 Subject: [PATCH] =?UTF-8?q?Erg=C3=A4nze=20Unterst=C3=BCtzung=20f=C3=BCr=20?= =?UTF-8?q?das=20Laden=20von=20R=C3=A4umen=20aus=20der=20Datenbank=20in=20?= =?UTF-8?q?der=20`createRooms`-Methode=20des=20SSLServers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implementiere eine Fehlerbehandlung, um Räume aus der Datenbank zu laden und bei einem Fehler auf die Konfiguration zurückzugreifen. - Füge detaillierte Logging-Ausgaben hinzu, um den Prozess des Ladens von Räumen zu verfolgen und die Anzahl der geladenen Räume zu dokumentieren. --- src/core/ssl_server.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/core/ssl_server.cpp b/src/core/ssl_server.cpp index cefd9ae..28e656c 100644 --- a/src/core/ssl_server.cpp +++ b/src/core/ssl_server.cpp @@ -425,10 +425,35 @@ void SSLServer::broadcastToRoom(const std::string& roomName, const std::string& } void SSLServer::createRooms() { - // Load rooms from database or config - Json::Value roomList = _config->group("rooms"); - std::cout << "[YourChat] createRooms() called" << std::endl; + + // Try to load rooms from database first + try { + Json::Value dbRooms = _database->getRooms(); + std::cout << "[YourChat] Database returned " << dbRooms.size() << " rooms" << std::endl; + + if (dbRooms.isArray() && dbRooms.size() > 0) { + std::cout << "[YourChat] Loading rooms from database..." << std::endl; + for (const auto& room : dbRooms) { + std::cout << "[YourChat] Database room: " << room << std::endl; + auto newRoom = std::make_shared(nullptr, room); + _rooms.push_back(newRoom); + } + std::cout << "[YourChat] Loaded " << _rooms.size() << " rooms from database" << std::endl; + for (const auto& room : _rooms) { + std::cout << "[YourChat] Loaded room: '" << room->name() << "'" << std::endl; + } + return; + } else { + std::cout << "[YourChat] No rooms found in database, falling back to config" << std::endl; + } + } catch (const std::exception& e) { + std::cerr << "[YourChat] Failed to load rooms from database: " << e.what() << std::endl; + std::cout << "[YourChat] Falling back to config..." << std::endl; + } + + // Fallback to config + Json::Value roomList = _config->group("rooms"); std::cout << "[YourChat] Config rooms size: " << roomList.size() << std::endl; if (roomList.isArray() && roomList.size() > 0) {