From bdb12c38cf069ec6750083c8e8668207553ada65 Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 20 Jul 2017 11:41:57 -0700 Subject: [PATCH] Move API call to Entities scripting and out of Users --- assignment-client/src/octree/OctreeServer.cpp | 60 ++++++++++++++++++- assignment-client/src/octree/OctreeServer.h | 1 + .../entities/src/EntityScriptingInterface.cpp | 10 ++++ .../entities/src/EntityScriptingInterface.h | 14 +++++ .../src/UsersScriptingInterface.cpp | 5 +- .../src/UsersScriptingInterface.h | 9 --- 6 files changed, 85 insertions(+), 14 deletions(-) diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index af5f2c904e..ee3d0ca0e6 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -928,7 +928,7 @@ void OctreeServer::handleJurisdictionRequestPacket(QSharedPointer message) { if (!_isFinished && !_isShuttingDown) { - // these messages are only allowed to come from the domain server, so make sure that is the case + // these messages are only allowed to come from the domain server or authenticated users, so make sure that is the case auto nodeList = DependencyManager::get(); if (message->getSenderSockAddr() == nodeList->getDomainHandler().getSockAddr()) { // it's far cleaner to load up the new content upon server startup @@ -977,6 +977,64 @@ void OctreeServer::handleOctreeFileReplacement(QSharedPointer m } } +void OctreeServer::handleOctreeFileReplacementFromURL(QString url) { + if (!_isFinished && !_isShuttingDown) { + // This call comes from Interface, so we skip our domain server check + if (!_persistAbsoluteFilePath.isEmpty()) { + // Download from our QString + QUrl modelsURL = QUrl(url, QUrl::StrictMode); + QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); + QNetworkRequest request(modelsURL); + QNetworkReply* reply = networkAccessManager.get(request); + connect(reply, &QNetworkReply::finished, [this, reply, modelsURL]() { + QNetworkReply::NetworkError networkError = reply->error(); + if (networkError == QNetworkReply::NoError) { + QByteArray contents = reply->readAll(); + + // Like above, assume we have compressed data + auto compressedOctree = contents; + QByteArray jsonOctree; + + bool wasCompressed = gunzip(compressedOctree, jsonOctree); + if (!wasCompressed) { + // the source was not compressed, assume we were sent regular JSON data + jsonOctree = compressedOctree; + } + // check the JSON data to verify it is an object + if (QJsonDocument::fromJson(jsonOctree).isObject()) { + if (!wasCompressed) { + // source was not compressed, we compress it before we write it locally + gzip(jsonOctree, compressedOctree); + } + + // write the compressed octree data to a special file + auto replacementFilePath = _persistAbsoluteFilePath.append(OctreePersistThread::REPLACEMENT_FILE_EXTENSION); + QFile replacementFile(replacementFilePath); + if (replacementFile.open(QIODevice::WriteOnly) && replacementFile.write(compressedOctree) != -1) { + // we've now written our replacement file, time to take the server down so it can + // process it when it comes back up + qInfo() << "Wrote octree replacement file to" << replacementFilePath << "- stopping server"; + setFinished(true); + } + else { + qWarning() << "Could not write replacement octree data to file - refusing to process"; + } + } + else { + qDebug() << "Received replacement octree file that is invalid - refusing to process"; + } + } + else { + qDebug() << "Error downloading JSON from specified file"; + } + }); + } + else { + qDebug() << "Cannot perform octree file replacement since current persist file path is not yet known"; + } + } +} + bool OctreeServer::readOptionBool(const QString& optionName, const QJsonObject& settingsSectionObject, bool& result) { result = false; // assume it doesn't exist bool optionAvailable = false; diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index 8db8d845de..96eafbc1e4 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -137,6 +137,7 @@ private slots: void handleOctreeDataNackPacket(QSharedPointer message, SharedNodePointer senderNode); void handleJurisdictionRequestPacket(QSharedPointer message, SharedNodePointer senderNode); void handleOctreeFileReplacement(QSharedPointer message); + void handleOctreeFileReplacementFromURL(QString url); void removeSendThread(); protected: diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index f22631d363..3f639cb17c 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -47,6 +47,8 @@ EntityScriptingInterface::EntityScriptingInterface(bool bidOnSimulationOwnership connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptingInterface::canRezChanged); connect(nodeList.data(), &NodeList::canRezTmpChanged, this, &EntityScriptingInterface::canRezTmpChanged); connect(nodeList.data(), &NodeList::canWriteAssetsChanged, this, &EntityScriptingInterface::canWriteAssetsChanged); + connect(nodeList.data(), &NodeList::canReplaceContentChanged, this, &EntityScriptingInterface::canReplaceDomainContentChanged); + } void EntityScriptingInterface::queueEntityMessage(PacketType packetType, @@ -80,6 +82,11 @@ bool EntityScriptingInterface::canWriteAssets() { return nodeList->getThisNodeCanWriteAssets(); } +bool EntityScriptingInterface::canReplaceDomainContent() { + auto nodeList = DependencyManager::get(); + return nodeList->getThisNodeCanReplaceContent(); +} + void EntityScriptingInterface::setEntityTree(EntityTreePointer elementTree) { if (_entityTree) { disconnect(_entityTree.get(), &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity); @@ -1158,6 +1165,9 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, return doTransmit; } +void EntityScriptingInterface::replaceDomainContentSet(const QString url){ + +} QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, const QUuid& entityID, diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 575528fa78..9f0d3f0d03 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -359,6 +359,19 @@ public slots: */ Q_INVOKABLE glm::mat4 getEntityLocalTransform(const QUuid& entityID); + /**jsdoc + * Returns true if the user has permissions to replace domain content sets + * @function Entities.canReplaceDomainContent + * @return {bool} true if the user has permissions to replace domain content sets, false if not + */ + Q_INVOKABLE bool canReplaceDomainContent(); + + /**jsdoc + * TODO: temporary placement for content set calls + */ + Q_INVOKABLE void replaceDomainContentSet(const QString fileURL); + + signals: void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); @@ -366,6 +379,7 @@ signals: void canRezChanged(bool canRez); void canRezTmpChanged(bool canRez); void canWriteAssetsChanged(bool canWriteAssets); + void canReplaceDomainContentChanged(); void mousePressOnEntity(const EntityItemID& entityItemID, const PointerEvent& event); void mouseMoveOnEntity(const EntityItemID& entityItemID, const PointerEvent& event); diff --git a/libraries/script-engine/src/UsersScriptingInterface.cpp b/libraries/script-engine/src/UsersScriptingInterface.cpp index ab8e62040b..0622d67d28 100644 --- a/libraries/script-engine/src/UsersScriptingInterface.cpp +++ b/libraries/script-engine/src/UsersScriptingInterface.cpp @@ -19,7 +19,6 @@ UsersScriptingInterface::UsersScriptingInterface() { connect(nodeList.data(), &LimitedNodeList::canKickChanged, this, &UsersScriptingInterface::canKickChanged); connect(nodeList.data(), &NodeList::ignoreRadiusEnabledChanged, this, &UsersScriptingInterface::ignoreRadiusEnabledChanged); connect(nodeList.data(), &NodeList::usernameFromIDReply, this, &UsersScriptingInterface::usernameFromIDReply); - connect(nodeList.data(), &NodeList::canReplaceContentChanged, this, &UsersScriptingInterface::canReplaceContentChanged); } void UsersScriptingInterface::ignore(const QUuid& nodeID, bool ignoreEnabled) { @@ -94,6 +93,4 @@ bool UsersScriptingInterface::getRequestsDomainListData() { void UsersScriptingInterface::setRequestsDomainListData(bool isRequesting) { DependencyManager::get()->setRequestsDomainListData(isRequesting); } -bool UsersScriptingInterface::getCanReplaceContent() { - return DependencyManager::get()->getThisNodeCanReplaceContent(); -} + diff --git a/libraries/script-engine/src/UsersScriptingInterface.h b/libraries/script-engine/src/UsersScriptingInterface.h index b39293dc0e..8aa6e8ce4d 100644 --- a/libraries/script-engine/src/UsersScriptingInterface.h +++ b/libraries/script-engine/src/UsersScriptingInterface.h @@ -25,8 +25,6 @@ class UsersScriptingInterface : public QObject, public Dependency { Q_PROPERTY(bool canKick READ getCanKick) Q_PROPERTY(bool requestsDomainListData READ getRequestsDomainListData WRITE setRequestsDomainListData) - Q_PROPERTY(bool canReplaceContent READ getCanReplaceContent) - public: UsersScriptingInterface(); @@ -132,12 +130,6 @@ public slots: */ bool getIgnoreRadiusEnabled(); - /**jsdoc - * Returns true if the user has permissions to replace domain content sets - * @function Users.getCanReplaceContent - * @return {bool} true if the user has permissions to replace domain content sets, false if not - */ - bool getCanReplaceContent(); signals: void canKickChanged(bool canKick); @@ -162,7 +154,6 @@ signals: * @param {nodeID} NodeID The session ID of the avatar that has disconnected */ void avatarDisconnected(const QUuid& nodeID); - void canReplaceContentChanged(bool canReplaceContent); private: bool getRequestsDomainListData();