Verbessere Benutzerverwaltung in ChatRoom durch Überprüfung auf Elternobjekt

- 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`.
This commit is contained in:
Torsten Schulz (local)
2025-09-05 09:16:27 +02:00
parent 62a5c70c8c
commit 39780197f8
2 changed files with 5 additions and 3 deletions

View File

@@ -116,8 +116,10 @@ namespace Yc
auto newUser = std::make_shared<ChatUser>(shared_from_this(), _userName, color, socket); auto newUser = std::make_shared<ChatUser>(shared_from_this(), _userName, color, socket);
_users.push_back(newUser); _users.push_back(newUser);
newUser->start(); newUser->start();
Json::Value roomList = _parent->jsonRoomList(); if (_parent) {
newUser->sendMsg(ChatUser::roomList, roomList, "", ""); Json::Value roomList = _parent->jsonRoomList();
newUser->sendMsg(ChatUser::roomList, roomList, "", "");
}
// Sende aktuelle Userliste an den neuen User // Sende aktuelle Userliste an den neuen User
Json::Value currentUserList = userList(); Json::Value currentUserList = userList();

View File

@@ -461,7 +461,7 @@ void SSLServer::createRooms() {
for (const auto& room : roomList) { for (const auto& room : roomList) {
std::cout << "[YourChat] Config room: " << room << std::endl; std::cout << "[YourChat] Config room: " << room << std::endl;
// Create room objects using the same logic as the main server // Create room objects using the same logic as the main server
auto newRoom = std::make_shared<ChatRoom>(nullptr, room); // parent will be set later auto newRoom = std::make_shared<ChatRoom>(nullptr, room);
_rooms.push_back(newRoom); _rooms.push_back(newRoom);
} }
} else { } else {