#pragma once #include "../types.hpp" #include "server.hpp" #include #include #include #include #include #include namespace LibSock { namespace Server { class Client; struct SData { std::string msg; std::optional> sender = std::nullopt; }; class Clients : public std::enable_shared_from_this { public: static SP create(WP server); ~Clients(); SP newClient(std::function &)> loopFunc = [](const WP &) { ; }); void broadcast(const std::string &msg, std::optional> self = std::nullopt); // second param only specified when we // want to exclude the sender void kick(WP client, const bool kill = false, const std::string &reason = "", std::optional>>::iterator &)>> cb = std::nullopt); void addClient(const Client &client); void shutdownClients(std::optional>> &)>> cb = std::nullopt); SP getByIp(const std::string &ip) const; std::vector> getClients() const; std::vector getDatas() const; private: Clients(); void broadcast(const SData &msg); std::vector>> m_vClients; std::vector m_vDatas; WP get(); WP m_self; WP m_wpServer; friend class Client; }; inline std::vector> vpClients; } // namespace Server } // namespace LibSock