Füge Methode zum Senden von Nachrichten an alle Benutzer im ChatRoom hinzu

- Implementiere die Methode `sendToAllUsers`, um Nachrichten an alle aktiven Benutzer im Raum zu senden.
- Aktualisiere die WebSocket-Nachrichtenverarbeitung im SSLServer, um die aktualisierte Benutzerliste an alle Benutzer im Raum zu senden, wenn sich die Benutzerfarbe ändert.
- Ergänze Debug-Ausgaben zur Nachverfolgbarkeit der gesendeten Benutzerliste.
This commit is contained in:
Torsten Schulz (local)
2025-09-05 15:29:23 +02:00
parent 21c224835f
commit fe81e19bef
3 changed files with 22 additions and 0 deletions

View File

@@ -425,6 +425,15 @@ namespace Yc
return _parent->changeRoom(user, newRoom, password); return _parent->changeRoom(user, newRoom, password);
} }
void ChatRoom::sendToAllUsers(ChatUser::MsgType type, Json::Value message)
{
for (auto &user: _users) {
if (user) {
user->sendMsg(type, message, "", "");
}
}
}
unsigned int ChatRoom::flags() unsigned int ChatRoom::flags()
{ {
unsigned int value = (unsigned int)_type; unsigned int value = (unsigned int)_type;

View File

@@ -57,6 +57,7 @@ namespace Yc
RoomType type(); RoomType type();
bool isType(RoomType type); bool isType(RoomType type);
bool canDice(); bool canDice();
void sendToAllUsers(ChatUser::MsgType type, Json::Value message);
unsigned int addDice(std::shared_ptr<ChatUser> user, int diceValue); unsigned int addDice(std::shared_ptr<ChatUser> user, int diceValue);
bool accessAllowed(std::string userName, std::string password); bool accessAllowed(std::string userName, std::string password);
bool userIsInRoom(std::string userName); bool userIsInRoom(std::string userName);

View File

@@ -418,6 +418,18 @@ void SSLServer::handleWebSocketMessage(struct lws *wsi, const std::string& messa
colorMsg["from"] = oldColor; colorMsg["from"] = oldColor;
colorMsg["to"] = newColor; colorMsg["to"] = newColor;
room->addMessage(ChatUser::MsgType::system, colorMsg, user->name(), newColor); room->addMessage(ChatUser::MsgType::system, colorMsg, user->name(), newColor);
// Send updated user list to all users in the room
Json::Value updatedUserList = room->userList();
Json::Value userListMsg = Json::objectValue;
userListMsg["userlist"] = updatedUserList;
#ifdef YC_DEBUG
std::cout << "[Debug] SSL Server: Sending updated user list to all users in room: " << room->name() << std::endl;
#endif
// Send updated user list to all users in the room
room->sendToAllUsers(ChatUser::MsgType::userListe, userListMsg);
break; break;
} }
} }