Room change, room list with flags
This commit is contained in:
34
server.cpp
34
server.cpp
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user