#ifndef SERVER_H #define SERVER_H #include #include #include #include "server/network/IServerListener.h" class Server final { private: struct ConnectedClient { ConnectedClient(); std::thread th; int socket; }; public: Server(uint16_t port, uint16_t maxClients, const IServerListener& listener); ~Server(); bool isRunning() const; private: void printError(const char* message) const; void listenForClients(); bool addClient(int clientSocket); void listenOnClient(ConnectedClient& cc); std::atomic_bool shouldRun; uint16_t port; uint16_t maxClients; const IServerListener& serverListener; int listenerSocket; std::thread listenerThread; uint16_t clientAmount; ConnectedClient* clients; std::mutex clientMutex; }; #endif