Finish out the feature, i think

This commit is contained in:
Zach Fox 2019-05-06 10:47:58 -07:00
parent d0e5087b20
commit a68da2bca7
5 changed files with 46 additions and 2 deletions

View file

@ -56,6 +56,7 @@ EntityScriptingInterface::EntityScriptingInterface(bool bidOnSimulationOwnership
connect(nodeList.data(), &NodeList::canRezCertifiedChanged, this, &EntityScriptingInterface::canRezCertifiedChanged);
connect(nodeList.data(), &NodeList::canRezTmpCertifiedChanged, this, &EntityScriptingInterface::canRezTmpCertifiedChanged);
connect(nodeList.data(), &NodeList::canWriteAssetsChanged, this, &EntityScriptingInterface::canWriteAssetsChanged);
connect(nodeList.data(), &NodeList::canGetAndSetPrivateUserDataChanged, this, &EntityScriptingInterface::canGetAndSetPrivateUserDataChanged);
auto& packetReceiver = nodeList->getPacketReceiver();
packetReceiver.registerListener(PacketType::EntityScriptCallMethod, this, "handleEntityScriptCallMethodPacket");

View file

@ -236,6 +236,14 @@ public slots:
*/
Q_INVOKABLE bool canReplaceContent();
/**jsdoc
* Check whether or not you can get and set private user data.
* @function Entities.canGetAndSetPrivateUserData
* @returns {boolean} <code>true</code> if the domain server will allow the user to get and set private user data,
* otherwise <code>false</code>.
*/
Q_INVOKABLE bool canGetAndSetPrivateUserData();
/**jsdoc
* <p>How an entity is sent over the wire.</p>
* <table>
@ -1861,6 +1869,15 @@ signals:
*/
void canWriteAssetsChanged(bool canWriteAssets);
/**jsdoc
* Triggered when your ability to get and set private user data changes.
* @function Entities.canGetAndSetPrivateUserDataChanged
* @param {boolean} canGetAndSetPrivateUserData - <code>true</code> if you can change the <code>privateUserData</code> property of an entity,
* otherwise <code>false</code>.
* @returns {Signal}
*/
void canGetAndSetPrivateUserDataChanged(bool canGetAndSetPrivateUserData);
/**jsdoc
* Triggered when a mouse button is clicked while the mouse cursor is on an entity, or a controller trigger is fully

View file

@ -1780,6 +1780,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
bool suppressDisallowedClientScript = false;
bool suppressDisallowedServerScript = false;
bool suppressDisallowedPrivateUserData = false;
bool isPhysics = message.getType() == PacketType::EntityPhysics;
_totalEditMessages++;
@ -1869,6 +1870,27 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
}
}
if (!properties.getPrivateUserData().isEmpty()) {
if (!senderNode->getCanGetAndSetPrivateUserData()) {
if (wantEditLogging()) {
qCDebug(entities) << "User [" << senderNode->getUUID()
<< "] is attempting to set private user data but user isn't allowed; edit rejected...";
}
// If this was an add, we also want to tell the client that sent this edit that the entity was not added.
if (isAdd) {
// Make sure we didn't already need to send back a delete because the client script failed
// the whitelist check
if (!wasDeletedBecauseOfClientScript) {
QWriteLocker locker(&_recentlyDeletedEntitiesLock);
_recentlyDeletedEntityItemIDs.insert(usecTimestampNow(), entityItemID);
validEditPacket = false;
}
} else {
suppressDisallowedPrivateUserData = true;
}
}
}
}
if (!isClone) {
@ -1923,6 +1945,11 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
properties.setServerScripts(existingEntity->getServerScripts());
}
if (suppressDisallowedPrivateUserData) {
bumpTimestamp(properties);
properties.setPrivateUserData(existingEntity->getPrivateUserData());
}
// if the EntityItem exists, then update it
startLogging = usecTimestampNow();
if (wantEditLogging()) {

View file

@ -202,7 +202,6 @@ void LimitedNodeList::setPermissions(const NodePermissions& newPermissions) {
emit canGetAndSetPrivateUserDataChanged(_permissions.can(NodePermissions::Permission::canGetAndSetPrivateUserData));
}
}
}
void LimitedNodeList::setSocketLocalPort(quint16 socketLocalPort) {
if (QThread::currentThread() != thread()) {

View file

@ -135,7 +135,6 @@ public:
AudioSoloRequest,
BulkAvatarTraitsAck,
StopInjector,
PrivateUserData,
NUM_PACKET_TYPE
};
@ -270,6 +269,7 @@ enum class EntityVersion : PacketVersion {
CertificateTypeProperty,
DisableWebMedia,
ParticleShapeType,
PrivateUserData,
// Add new versions above here
NUM_PACKET_TYPE,