#pragma once #include "../types.hpp" #include "clients.hpp" #include "server.hpp" #include #include #include #include #include #include namespace LibSock { namespace Server { struct SRecvData { std::string data; const size_t size = 1024; bool good = false; bool isEmpty() const; void sanitize(); static constexpr char asciiEscape = 0x1B; //  }; enum eEventType : std::uint8_t { READ, WRITE }; class Client { public: ~Client(); const std::string &getIp() const; bool isAdmin() const; UP read(std::optional> cb = std::nullopt); UP read(const std::string &msg, std::optional> cb = std::nullopt); bool write(const std::string &msg, std::optional> cb = std::nullopt); template bool write(std::format_string fmt, Args &&...args); void resumeHistory(); void runLoop(bool resumeHistory = true, std::optional> cb = std::nullopt); bool isValid(); private: void init(); Client(SP server, SP clients, bool track = false, bool wait = false); WP m_self; WP m_wpServer; WP m_wpClients; SP m_sockfd; sockaddr_in m_addr; socklen_t m_addrLen = sizeof(m_addr); std::string m_ip; int m_port; bool m_track; bool m_wait; std::optional m_szReading = std::nullopt; void recvLoop(std::optional> cb = std::nullopt); friend class Clients; }; } // namespace Server } // namespace LibSock