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:
@@ -116,8 +116,10 @@ namespace Yc
|
||||
auto newUser = std::make_shared<ChatUser>(shared_from_this(), _userName, color, socket);
|
||||
_users.push_back(newUser);
|
||||
newUser->start();
|
||||
if (_parent) {
|
||||
Json::Value roomList = _parent->jsonRoomList();
|
||||
newUser->sendMsg(ChatUser::roomList, roomList, "", "");
|
||||
}
|
||||
|
||||
// Sende aktuelle Userliste an den neuen User
|
||||
Json::Value currentUserList = userList();
|
||||
|
||||
@@ -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<ChatRoom>(nullptr, room); // parent will be set later
|
||||
auto newRoom = std::make_shared<ChatRoom>(nullptr, room);
|
||||
_rooms.push_back(newRoom);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user