From 9b0852a91d5437dc9acab8f0a825cc6b974d5dd3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 10 Apr 2020 09:59:11 +0800 Subject: [PATCH] Protect from duplicate UP and DOWN callbacks, fix ryzom/ryzomcore#601 --- nel/include/nel/net/unified_network.h | 1 + nel/src/net/unified_network.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/nel/include/nel/net/unified_network.h b/nel/include/nel/net/unified_network.h index d380427b6..df735a740 100644 --- a/nel/include/nel/net/unified_network.h +++ b/nel/include/nel/net/unified_network.h @@ -662,6 +662,7 @@ private: std::vector _UpUniCallback; TNameMappedCallback _DownCallbacks; std::vector _DownUniCallback; + std::set> _NotifiedUpCallbacks; /// Recording state CCallbackNetBase::TRecordingState _RecordingState; diff --git a/nel/src/net/unified_network.cpp b/nel/src/net/unified_network.cpp index 5a6034e18..ca3ef37d7 100644 --- a/nel/src/net/unified_network.cpp +++ b/nel/src/net/unified_network.cpp @@ -2090,6 +2090,14 @@ void CUnifiedNetwork::addNetworkAssociation (const string &networkName, uint8 ni void CUnifiedNetwork::callServiceUpCallback (const std::string &serviceName, TServiceId sid, bool callGlobalCallback) { + std::pair pss = std::make_pair(serviceName, sid); + if (_NotifiedUpCallbacks.find(pss) != _NotifiedUpCallbacks.end()) + { + nlwarning("HNETL5: Attempt to call service UP callback twice for '%s', ignored!", serviceName.c_str()); + return; + } + _NotifiedUpCallbacks.insert(pss); + // now we warn the user CUnifiedNetwork::TNameMappedCallback::iterator it = _UpCallbacks.find(serviceName); if (it != _UpCallbacks.end()) @@ -2119,6 +2127,14 @@ void CUnifiedNetwork::callServiceUpCallback (const std::string &serviceName, TSe void CUnifiedNetwork::callServiceDownCallback (const std::string &serviceName, TServiceId sid, bool callGlobalCallback) { + std::pair pss = std::make_pair(serviceName, sid); + if (_NotifiedUpCallbacks.find(pss) == _NotifiedUpCallbacks.end()) + { + nlwarning("HNETL5: Attempt to call service DOWN callback twice for '%s', ignored!", serviceName.c_str()); + return; + } + _NotifiedUpCallbacks.erase(pss); + // now we warn the user CUnifiedNetwork::TNameMappedCallback::iterator it = _DownCallbacks.find(serviceName); if (it != _DownCallbacks.end())