From 320428eddfb60ce16f1e1241ccb7ae397c908b9b Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 21 Jun 2023 20:36:08 +1000 Subject: slight polishing --- source/game/StarWorldServer.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source/game/StarWorldServer.cpp') diff --git a/source/game/StarWorldServer.cpp b/source/game/StarWorldServer.cpp index bf36e62..417c718 100644 --- a/source/game/StarWorldServer.cpp +++ b/source/game/StarWorldServer.cpp @@ -2037,12 +2037,19 @@ Json WorldServer::getProperty(String const& propertyName, Json const& def) const } void WorldServer::setProperty(String const& propertyName, Json const& property) { - if (m_worldProperties.value(propertyName) == property) - return; - - m_worldProperties[propertyName] = property; - for (auto const& pair : m_clientInfo) - pair.second->outgoingPackets.append(make_shared(JsonObject{{propertyName, property}})); + // Kae: Properties set to null (nil from Lua) should be erased instead of lingering around + auto entry = m_worldProperties.find(propertyName); + bool missing = entry == m_worldProperties.end(); + if (missing ? !property.isNull() : property != entry->second) { + if (missing) // property can't be null if we're doing this when missing is true + m_worldProperties.emplace(propertyName, property); + else if (property.isNull()) + m_worldProperties.erase(entry); + else + entry->second = property; + for (auto const& pair : m_clientInfo) + pair.second->outgoingPackets.append(make_shared(JsonObject{ {propertyName, property} })); + } } void WorldServer::timer(int stepsDelay, WorldAction worldAction) { -- cgit v1.2.3