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:
@@ -425,6 +425,15 @@ namespace Yc
|
||||
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 value = (unsigned int)_type;
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace Yc
|
||||
RoomType type();
|
||||
bool isType(RoomType type);
|
||||
bool canDice();
|
||||
void sendToAllUsers(ChatUser::MsgType type, Json::Value message);
|
||||
unsigned int addDice(std::shared_ptr<ChatUser> user, int diceValue);
|
||||
bool accessAllowed(std::string userName, std::string password);
|
||||
bool userIsInRoom(std::string userName);
|
||||
|
||||
@@ -418,6 +418,18 @@ void SSLServer::handleWebSocketMessage(struct lws *wsi, const std::string& messa
|
||||
colorMsg["from"] = oldColor;
|
||||
colorMsg["to"] = 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user