diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-16 19:25:57 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-16 22:22:10 +0800 |
| commit | b46ba43e06aba714abc0afb29566a56d69891691 (patch) | |
| tree | 2f8ede6c777b37254b58c3a998ad540e476024a0 /include | |
| parent | 366e5004e6f09f69d945a1f41816cef08e442a2b (diff) | |
fix!: create new client without SP<Clients>(this) param
API: removed run(), use newClient() to accept a new client, now
returning a WP of the client instance
API: allow all cb to return std::any
Diffstat (limited to 'include')
| -rw-r--r-- | include/libsock/server/client.hpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/include/libsock/server/client.hpp b/include/libsock/server/client.hpp index eb528a2..6a5aa88 100644 --- a/include/libsock/server/client.hpp +++ b/include/libsock/server/client.hpp @@ -2,6 +2,7 @@ #include "../types.hpp" #include "server.hpp" +#include <any> #include <format> #include <functional> #include <netinet/in.h> @@ -42,9 +43,9 @@ class Client { const std::string &getIp() const; bool isAdmin() const; - UP<SRecvData> read(std::optional<std::function<void(const SRecvData &)>> cb = std::nullopt); - UP<SRecvData> read(const std::string &msg, std::optional<std::function<void(const SRecvData &)>> cb = std::nullopt); - bool write(const std::string &msg, std::optional<std::function<void(const SRecvData &)>> cb = std::nullopt); + UP<SRecvData> read(std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); + UP<SRecvData> read(const std::string &msg, std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); + bool write(const std::string &msg, std::optional<std::function<std::any(const SRecvData &)>> cb = std::nullopt); template <typename... Args> bool write(std::format_string<Args...> fmt, Args &&...args); @@ -81,9 +82,8 @@ class Clients { Clients(); ~Clients(); - void newClient(std::optional<std::function<void()>> cb = std::nullopt); + WP<Client> newClient(std::optional<std::function<std::any(WP<Client>)>> cb = std::nullopt); - void run(std::optional<std::function<void()>> cb = std::nullopt); void broadcast(const std::string &msg, std::optional<WP<Client>> self = std::nullopt); // second param only specified when we want to exclude the sender void kick(WP<Client> client, const bool kill = false, const std::string &reason = ""); void addClient(const Client &client); |
