From 35216c30aea2f85966bb59999ad7293726b5cacb Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 19 Jun 2025 16:38:12 +0800 Subject: internal: seperate client and clientmanager header --- include/libsock/server/clients.hpp | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/libsock/server/clients.hpp (limited to 'include/libsock/server/clients.hpp') diff --git a/include/libsock/server/clients.hpp b/include/libsock/server/clients.hpp new file mode 100644 index 0000000..9b94127 --- /dev/null +++ b/include/libsock/server/clients.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "../types.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: + Clients(); + ~Clients(); + + WP newClient( + std::optional)>> cb = std::nullopt + ); + + 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: + void broadcast(const SData &msg); + + std::vector>> m_vClients; + std::vector m_vDatas; + + friend class Client; +}; + +} // namespace Server +} // namespace LibSock -- cgit v1.2.3