if our Node isn't allowed to create entities in this domain, don't try.

This commit is contained in:
Seth Alves 2015-04-27 19:07:53 -07:00
parent e48552f243
commit 6f441e3490
2 changed files with 21 additions and 4 deletions

View file

@ -16,6 +16,7 @@
#include "LightEntityItem.h"
#include "ModelEntityItem.h"
#include "ZoneEntityItem.h"
#include "EntitiesLogging.h"
EntityScriptingInterface::EntityScriptingInterface() :
@ -78,19 +79,27 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
EntityItemProperties propertiesWithSimID = properties;
EntityItemID id(NEW_ENTITY, creatorTokenID, false );
EntityItemID id(NEW_ENTITY, creatorTokenID, false);
// If we have a local entity tree set, then also update it.
bool success = true;
if (_entityTree) {
_entityTree->lockForWrite();
EntityItem* entity = _entityTree->addEntity(id, propertiesWithSimID);
// This Node is creating a new object. If it's in motion, set this Node as the simulator.
setSimId(propertiesWithSimID, entity);
if (entity) {
// This Node is creating a new object. If it's in motion, set this Node as the simulator.
setSimId(propertiesWithSimID, entity);
} else {
qCDebug(entities) << "script failed to add new Entity to local Octree";
success = false;
}
_entityTree->unlock();
}
// queue the packet
queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID);
if (success) {
queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID);
}
return id;
}

View file

@ -192,6 +192,14 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro
EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = NULL;
if (getIsClient()) {
// if our Node isn't allowed to create entities in this domain, don't try.
auto nodeList = DependencyManager::get<NodeList>();
if (!nodeList->getThisNodeCanRez()) {
return NULL;
}
}
// NOTE: This method is used in the client and the server tree. In the client, it's possible to create EntityItems
// that do not yet have known IDs. In the server tree however we don't want to have entities without known IDs.
bool recordCreationTime = false;