From 57ec9c2cb60412a227de13c32b5df7ce71b33b1c Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Thu, 12 Oct 2017 14:49:07 +0200 Subject: [PATCH] Code refactoring --- .gitignore | 1 + main.cpp | 3 +-- room.cpp | 10 ++++++++++ room.h | 1 + user.h | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9b3a42a..b301867 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /user.o /yourchat *.o +*.qmake.stash diff --git a/main.cpp b/main.cpp index 7f67efb..bf94bf2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,7 @@ #include "config.h" #include "server.h" -int main(int, char **) -{ +int main(int, char **) { Yc::Lib::Config *config = new Yc::Lib::Config(); Yc::Lib::Server server(config); server.run(); diff --git a/room.cpp b/room.cpp index 919d5fc..3cc1dab 100644 --- a/room.cpp +++ b/room.cpp @@ -149,6 +149,16 @@ namespace Yc { return value; } + Json::Value Room::userList() { + Json::Value users = Json::arrayValue; + for (auto &user: _users) { + Json::Value jsonUser = Json::objectValue; + jsonUser["name"] = user->name(); + users.append(jsonUser); + } + return users; + } + Room::RoomType Room::type() { return _type; } diff --git a/room.h b/room.h index 4be1bcf..2023cf7 100644 --- a/room.h +++ b/room.h @@ -48,6 +48,7 @@ namespace Yc { void addUserWhenQueueEmpty(User *user); bool userToNewRoom(User *user, std::string newRoom, std::string password); unsigned int flags(); + Json::Value userList(); private: struct Message { User::MsgType type; diff --git a/user.h b/user.h index e3e663e..2a3ff96 100644 --- a/user.h +++ b/user.h @@ -52,6 +52,7 @@ namespace Yc { void doDice(); void changeRoom(std::string newRoom, std::string password); void checkString(std::string message); + void sendUserList(); }; } // namespace Lib