Refactor Server class: move createRooms call outside constructor and update access modifier for _socket

This commit is contained in:
Torsten Schulz (local)
2025-08-11 11:45:09 +02:00
parent f44d780537
commit 89956bd01a
3 changed files with 4 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
int main(int, char **) { int main(int, char **) {
auto config = std::make_shared<Yc::Lib::Config>(); auto config = std::make_shared<Yc::Lib::Config>();
auto server = std::make_shared<Yc::Lib::Server>(config); auto server = std::make_shared<Yc::Lib::Server>(config);
server->createRooms(config->group("rooms"));
server->run(); server->run();
return 0; return 0;
} }

View File

@@ -31,7 +31,7 @@ namespace Yc {
std::cout << "bind not possible" << std::endl; std::cout << "bind not possible" << std::endl;
exit(-1); exit(-1);
} }
createRooms(_config->group("rooms")); // createRooms wird jetzt außerhalb des Konstruktors aufgerufen
} }
void Server::run() { void Server::run() {

View File

@@ -19,12 +19,13 @@ namespace Yc {
Json::Value jsonRoomList(); Json::Value jsonRoomList();
bool roomAllowed(std::string roomName, std::string userName, std::string password); bool roomAllowed(std::string roomName, std::string userName, std::string password);
bool changeRoom(std::shared_ptr<User> user, std::string newRoom, std::string password); bool changeRoom(std::shared_ptr<User> user, std::string newRoom, std::string password);
private: public:
int _socket; int _socket;
std::shared_ptr<Yc::Lib::Config> _config; std::shared_ptr<Yc::Lib::Config> _config;
bool _stop; bool _stop;
std::vector<std::shared_ptr<Yc::Lib::Room>> _rooms; std::vector<std::shared_ptr<Yc::Lib::Room>> _rooms;
void createRooms(Json::Value roomList); void createRooms(Json::Value roomList);
private:
void handleRequest(); void handleRequest();
void inputSwitcher(int userSocket, std::string input); void inputSwitcher(int userSocket, std::string input);
bool userExists(std::string userName); bool userExists(std::string userName);