Protect from duplicate UP and DOWN callbacks, fix ryzom/ryzomcore#601

develop
kaetemi 5 years ago
parent 05d6b16b9c
commit 9b0852a91d

@ -662,6 +662,7 @@ private:
std::vector<TCallbackArgItem> _UpUniCallback;
TNameMappedCallback _DownCallbacks;
std::vector<TCallbackArgItem> _DownUniCallback;
std::set<std::pair<std::string, TServiceId>> _NotifiedUpCallbacks;
/// Recording state
CCallbackNetBase::TRecordingState _RecordingState;

@ -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<std::string, TServiceId> 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<std::string, TServiceId> 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())

Loading…
Cancel
Save