Room change, room list with flags

This commit is contained in:
Torsten Schulz
2017-07-24 23:41:12 +02:00
parent 105232a9e3
commit b9d2b3e347
6 changed files with 102 additions and 7 deletions

View File

@@ -65,7 +65,10 @@ namespace Yc {
Json::Value Server::jsonRoomList() {
Json::Value list;
for (auto &room: _rooms) {
list.append(room->name());
Json::Value roomJson = Json::objectValue;
roomJson["name"] = room->name();
roomJson["flags"] = room->flags();
list.append(roomJson);
}
return list;
}
@@ -79,6 +82,35 @@ namespace Yc {
return false;
}
bool Server::changeRoom(User *user, std::string newRoom, std::string password) {
if (!roomAllowed(newRoom, user->name(), password)) {
return false;
}
Json::Value userMsg = Json::objectValue;
userMsg["tr"] = "room_change_user";
userMsg["to"] = newRoom;
for (auto &room: _rooms) {
if (room->userIsInRoom(user->name())) {
Json::Value msg = Json::objectValue;
msg["tr"] = "room_change_to";
msg["to"] = newRoom;
userMsg["from"] = room->name();
room->addMessage(User::system, msg, user->name(), user->color());
}
}
user->sendMsg(User::system, userMsg, "", "");
for (auto &room: _rooms) {
if (room->name() == newRoom) {
Json::Value msg = Json::objectValue;
msg["tr"] = "room_change_to";
msg["from"] = userMsg["from"];
room->addMessage(User::system, msg, user->name(), user->color());
room->addUserWhenQueueEmpty(user);
}
}
return true;
}
void Server::createRooms(Json::Value roomList) {
for (auto &room: roomList) {
Room *newRoom = new Room(this, room);