From 366e5004e6f09f69d945a1f41816cef08e442a2b Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 15 Jun 2025 14:23:00 +0800 Subject: fix: server types --- src/server/clients.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/server/clients.cpp') 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 #include -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)); + broadcast(std::format("{} has left the chat", client->getName()), WP(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(this); }; Clients::~Clients() { @@ -47,7 +47,7 @@ Clients::~Clients() { void Clients::newClient(std::optional> cb) { if (cb) (*cb)(); - SP client = std::make_shared(); + SP client = std::make_shared(pServer, SP(this)); auto &instance = m_vClients.emplace_back(std::jthread([client]() { client->run(); }), client); instance.second->self = std::weak_ptr(instance.second); } @@ -114,7 +114,7 @@ void Clients::kick(WP 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); -- cgit v1.2.3