- Renamed Room class to ChatRoom and updated all references accordingly. - Removed the old room.cpp and room.h files. - Updated CMakeLists.txt to include chat_room.cpp instead of room.cpp. - Modified ChatUser class to use shared_ptr<ChatRoom> instead of shared_ptr<Room>. - Updated Server class to create instances of ChatRoom instead of Room. - Removed User class and its associated files, integrating its functionality into ChatUser. - Ensured all relevant includes and dependencies are updated to reflect the new class structure.
40 lines
1.3 KiB
C++
Executable File
40 lines
1.3 KiB
C++
Executable File
#ifndef YP_LIB_SERVER_H
|
|
#define YP_LIB_SERVER_H
|
|
|
|
#include "config.h"
|
|
#include "database.h"
|
|
#include <vector>
|
|
#include "chat_room.h"
|
|
#include "base.h"
|
|
#include <json/value.h>
|
|
|
|
namespace Yc {
|
|
namespace Lib {
|
|
|
|
class Server: public Base, public std::enable_shared_from_this<Server>
|
|
{
|
|
public:
|
|
Server(std::shared_ptr<Yc::Lib::Config> config, std::shared_ptr<Yc::Lib::Database> database);
|
|
void run();
|
|
std::vector<std::string> roomList();
|
|
Json::Value jsonRoomList();
|
|
bool roomAllowed(std::string roomName, std::string userName, std::string password);
|
|
bool changeRoom(std::shared_ptr<ChatUser> user, std::string newRoom, std::string password);
|
|
int _socket;
|
|
std::shared_ptr<Yc::Lib::Config> _config;
|
|
std::shared_ptr<Yc::Lib::Database> _database;
|
|
bool _stop;
|
|
std::vector<std::shared_ptr<Yc::Lib::ChatRoom>> _rooms;
|
|
void createRooms(Json::Value roomList);
|
|
private:
|
|
void handleRequest();
|
|
void inputSwitcher(int userSocket, std::string input);
|
|
bool userExists(std::string userName);
|
|
void initUser(int userSocket, Json::Value data);
|
|
};
|
|
|
|
} // namespace Lib
|
|
} // namespace Yp
|
|
|
|
#endif // YP_LIB_SERVER_H
|