mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-25 13:30:43 +00:00
fix not removing client when disconnecting them
This commit is contained in:
3 files changed
+11
No files matched your search
@@ -40,6 +40,7 @@ public:
|
|||||||
|
|
||||||
void InsertClient(const std::shared_ptr<TClient>& Ptr);
|
void InsertClient(const std::shared_ptr<TClient>& Ptr);
|
||||||
void RemoveClient(const std::weak_ptr<TClient>&);
|
void RemoveClient(const std::weak_ptr<TClient>&);
|
||||||
|
void RemoveClientById(int Id);
|
||||||
// in Fn, return true to continue, return false to break
|
// in Fn, return true to continue, return false to break
|
||||||
[[deprecated("use ForEachClient instead")]] void ForEachClientWeak(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
[[deprecated("use ForEachClient instead")]] void ForEachClientWeak(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
||||||
// in Fn, return Break or Continue
|
// in Fn, return Break or Continue
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ void TClient::Disconnect(std::string_view Reason) {
|
|||||||
if (ec) {
|
if (ec) {
|
||||||
beammp_debugf("Failed to close client socket: {}", ec.message());
|
beammp_debugf("Failed to close client socket: {}", ec.message());
|
||||||
}
|
}
|
||||||
|
mServer.RemoveClientById(GetID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TClient::SetCarPosition(int Ident, const std::string& Data) {
|
void TClient::SetCarPosition(int Ident, const std::string& Data) {
|
||||||
|
|||||||
@@ -190,6 +190,15 @@ void TServer::RemoveClient(const std::weak_ptr<TClient>& WeakClientPtr) {
|
|||||||
mClients.erase(WeakClientPtr.lock());
|
mClients.erase(WeakClientPtr.lock());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TServer::RemoveClientById(int Id) {
|
||||||
|
auto Client = GetClient(*this, Id);
|
||||||
|
WriteLock Lock(mClientsMutex);
|
||||||
|
if (Client) {
|
||||||
|
Client->ClearCars();
|
||||||
|
mClients.erase(Client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TServer::ForEachClientWeak(const std::function<bool(std::weak_ptr<TClient>)>& Fn) {
|
void TServer::ForEachClientWeak(const std::function<bool(std::weak_ptr<TClient>)>& Fn) {
|
||||||
decltype(mClients) Clients;
|
decltype(mClients) Clients;
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user