diff --git a/src/core/chat_room.cpp b/src/core/chat_room.cpp index b5c2e61..30be6c0 100755 --- a/src/core/chat_room.cpp +++ b/src/core/chat_room.cpp @@ -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; diff --git a/src/core/chat_room.h b/src/core/chat_room.h index 4a30ae4..610d86a 100755 --- a/src/core/chat_room.h +++ b/src/core/chat_room.h @@ -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 user, int diceValue); bool accessAllowed(std::string userName, std::string password); bool userIsInRoom(std::string userName); diff --git a/src/core/ssl_server.cpp b/src/core/ssl_server.cpp index 6eb6654..be69638 100644 --- a/src/core/ssl_server.cpp +++ b/src/core/ssl_server.cpp @@ -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; } }