diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-15 14:23:00 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-16 22:22:10 +0800 |
| commit | 366e5004e6f09f69d945a1f41816cef08e442a2b (patch) | |
| tree | 765c2858bcd630ec358ae5770c0ee33406d194cd /src/server/clients.cpp | |
| parent | 82b6612418908654a61b7947550b796ce4ed57d6 (diff) | |
fix: server types
Diffstat (limited to 'src/server/clients.cpp')
| -rw-r--r-- | src/server/clients.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/server/clients.cpp b/src/server/clients.cpp index e42579c..5fc63df 100644 --- a/src/server/clients.cpp +++ b/src/server/clients.cpp @@ -5,7 +5,7 @@ #include <unistd.h> #include <utility> -using namespace LibSock::Client; +using namespace LibSock::Server; void Clients::shutdownClients() { if (m_vClients.empty()) @@ -15,7 +15,7 @@ void Clients::shutdownClients() { if (client) { client->write("Server shutting down"); if (!client->getName().empty()) - pClients->broadcast(std::format("{} has left the chat", client->getName()), WP<Client>(client)); + broadcast(std::format("{} has left the chat", client->getName()), WP<Client>(client)); } } @@ -29,11 +29,11 @@ void Clients::shutdownClients() { } Clients::Clients() { - if (std::atexit([]() { - if (pClients) - pClients->shutdownClients(); - })) - void(); // failed to register exit handler... + // if (std::atexit([&]() { + // shutdownClients(); + // })) + // void(); // failed to register exit handler... + pClients = SP<Clients>(this); }; Clients::~Clients() { @@ -47,7 +47,7 @@ Clients::~Clients() { void Clients::newClient(std::optional<std::function<void()>> cb) { if (cb) (*cb)(); - SP client = std::make_shared<Client>(); + SP client = std::make_shared<Client>(pServer, SP<Clients>(this)); auto &instance = m_vClients.emplace_back(std::jthread([client]() { client->run(); }), client); instance.second->self = std::weak_ptr<Client>(instance.second); } @@ -114,7 +114,7 @@ void Clients::kick(WP<Client> clientWeak, const bool kill, const std::string &re // this only exist when the client is registered // not sure why the second is null, but m_name definately is since it's setted during register // but we don't need to notify people if the client didn't even "join"/register anyways - pClients->broadcast(std::format("{} has left the chat", client->getName()), clientWeak); + broadcast(std::format("{} has left the chat", client->getName()), clientWeak); if (!reason.empty()) client->write(reason); |
