/* * ===================================================================================== * * Filename: Server.hpp * * Description: * * Created: 23/01/2018 14:47:14 * * Author: Quentin Bazin, * * ===================================================================================== */ #ifndef SERVER_HPP_ #define SERVER_HPP_ #include #include #include #include #include "Network.hpp" #include "ServerInfo.hpp" class Server { using ConnectionCallback = std::function; using CommandCallback = std::function; public: void init(u16 port = 4242); void handleKeyState(); void handleGameEvents(); void sendToAllClients(sf::Packet &packet); bool isRunning() const { return m_isRunning; } ServerInfo &info() { return m_info; } sf::UdpSocket &udpSocket() { return m_udpSocket; } void setRunning(bool isRunning) { m_isRunning = isRunning; } void setConnectionCallback(const ConnectionCallback &callback) { m_connectionCallback = callback; } void setCommandCallback(Network::Command command, const CommandCallback &callback) { m_commands[command] = callback; } private: void handleNewConnections(); void handleClientMessages(); bool m_isRunning = true; ServerInfo m_info; sf::UdpSocket m_udpSocket; sf::TcpListener m_tcpListener; sf::SocketSelector m_selector; ConnectionCallback m_connectionCallback; std::unordered_map m_commands; }; #endif // SERVER_HPP_