From 39780197f81dc424b65444f865defa9b680f358e Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 5 Sep 2025 09:16:27 +0200 Subject: [PATCH] =?UTF-8?q?Verbessere=20Benutzerverwaltung=20in=20ChatRoom?= =?UTF-8?q?=20durch=20=C3=9Cberpr=C3=BCfung=20auf=20Elternobjekt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Füge eine Bedingung hinzu, um sicherzustellen, dass `_parent` vor dem Abrufen der Raumliste nicht null ist, um potenzielle Fehler zu vermeiden. - Entferne überflüssige Kommentare und verbessere die Lesbarkeit des Codes in der `chat_room.cpp`. --- src/core/chat_room.cpp | 6 ++++-- src/core/ssl_server.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/chat_room.cpp b/src/core/chat_room.cpp index 42c9829..936a8ad 100755 --- a/src/core/chat_room.cpp +++ b/src/core/chat_room.cpp @@ -116,8 +116,10 @@ namespace Yc auto newUser = std::make_shared(shared_from_this(), _userName, color, socket); _users.push_back(newUser); newUser->start(); - Json::Value roomList = _parent->jsonRoomList(); - newUser->sendMsg(ChatUser::roomList, roomList, "", ""); + if (_parent) { + Json::Value roomList = _parent->jsonRoomList(); + newUser->sendMsg(ChatUser::roomList, roomList, "", ""); + } // Sende aktuelle Userliste an den neuen User Json::Value currentUserList = userList(); diff --git a/src/core/ssl_server.cpp b/src/core/ssl_server.cpp index 28e656c..042a374 100644 --- a/src/core/ssl_server.cpp +++ b/src/core/ssl_server.cpp @@ -461,7 +461,7 @@ void SSLServer::createRooms() { for (const auto& room : roomList) { std::cout << "[YourChat] Config room: " << room << std::endl; // Create room objects using the same logic as the main server - auto newRoom = std::make_shared(nullptr, room); // parent will be set later + auto newRoom = std::make_shared(nullptr, room); _rooms.push_back(newRoom); } } else {