Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarWorldServer.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-21 20:36:08 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-21 20:36:08 +1000
commit320428eddfb60ce16f1e1241ccb7ae397c908b9b (patch)
tree7e811868541fce502743b2044227a731729032f9 /source/game/StarWorldServer.cpp
parentee296e3381d0dc83a9315a101280dc63fdf4128a (diff)
slight polishing
Diffstat (limited to 'source/game/StarWorldServer.cpp')
-rw-r--r--source/game/StarWorldServer.cpp19
1 files changed, 13 insertions, 6 deletions
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<UpdateWorldPropertiesPacket>(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<UpdateWorldPropertiesPacket>(JsonObject{ {propertyName, property} }));
+ }
}
void WorldServer::timer(int stepsDelay, WorldAction worldAction) {