mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:28:09 +02:00
Refactor handleOctreeFileReplacement, style changes, align with handler for other file types
This commit is contained in:
parent
c0fa446b75
commit
49eab847fd
3 changed files with 42 additions and 75 deletions
|
@ -935,39 +935,7 @@ void OctreeServer::handleOctreeFileReplacement(QSharedPointer<ReceivedMessage> m
|
||||||
// so here we just store a special file at our persist path
|
// so here we just store a special file at our persist path
|
||||||
// and then force a stop of the server so that it can pick it up when it relaunches
|
// and then force a stop of the server so that it can pick it up when it relaunches
|
||||||
if (!_persistAbsoluteFilePath.isEmpty()) {
|
if (!_persistAbsoluteFilePath.isEmpty()) {
|
||||||
|
OctreeServer::replaceContentFromMessageData(message->getMessage());
|
||||||
// before we restart the server and make it try and load this data, let's make sure it is valid
|
|
||||||
auto compressedOctree = message->getMessage();
|
|
||||||
QByteArray jsonOctree;
|
|
||||||
|
|
||||||
// assume we have GZipped content
|
|
||||||
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 {
|
} else {
|
||||||
qDebug() << "Cannot perform octree file replacement since current persist file path is not yet known";
|
qDebug() << "Cannot perform octree file replacement since current persist file path is not yet known";
|
||||||
}
|
}
|
||||||
|
@ -995,9 +963,21 @@ void OctreeServer::handleOctreeFileReplacementFromURL(QSharedPointer<ReceivedMes
|
||||||
QNetworkReply::NetworkError networkError = reply->error();
|
QNetworkReply::NetworkError networkError = reply->error();
|
||||||
if (networkError == QNetworkReply::NoError) {
|
if (networkError == QNetworkReply::NoError) {
|
||||||
QByteArray contents = reply->readAll();
|
QByteArray contents = reply->readAll();
|
||||||
|
OctreeServer::replaceContentFromMessageData(contents);
|
||||||
|
} else {
|
||||||
|
qDebug() << "Error downloading JSON from specified file";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
qDebug() << "Cannot perform octree file replacement since current persist file path is not yet known";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Like above, assume we have compressed data
|
void OctreeServer::replaceContentFromMessageData(QByteArray content) {
|
||||||
auto compressedOctree = contents;
|
//Assume we have compressed data
|
||||||
|
auto compressedOctree = content;
|
||||||
QByteArray jsonOctree;
|
QByteArray jsonOctree;
|
||||||
|
|
||||||
bool wasCompressed = gunzip(compressedOctree, jsonOctree);
|
bool wasCompressed = gunzip(compressedOctree, jsonOctree);
|
||||||
|
@ -1011,7 +991,6 @@ void OctreeServer::handleOctreeFileReplacementFromURL(QSharedPointer<ReceivedMes
|
||||||
// source was not compressed, we compress it before we write it locally
|
// source was not compressed, we compress it before we write it locally
|
||||||
gzip(jsonOctree, compressedOctree);
|
gzip(jsonOctree, compressedOctree);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the compressed octree data to a special file
|
// write the compressed octree data to a special file
|
||||||
auto replacementFilePath = _persistAbsoluteFilePath.append(OctreePersistThread::REPLACEMENT_FILE_EXTENSION);
|
auto replacementFilePath = _persistAbsoluteFilePath.append(OctreePersistThread::REPLACEMENT_FILE_EXTENSION);
|
||||||
QFile replacementFile(replacementFilePath);
|
QFile replacementFile(replacementFilePath);
|
||||||
|
@ -1026,15 +1005,6 @@ void OctreeServer::handleOctreeFileReplacementFromURL(QSharedPointer<ReceivedMes
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Received replacement octree file that is invalid - refusing to process";
|
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) {
|
bool OctreeServer::readOptionBool(const QString& optionName, const QJsonObject& settingsSectionObject, bool& result) {
|
||||||
|
|
|
@ -162,6 +162,8 @@ protected:
|
||||||
UniqueSendThread createSendThread(const SharedNodePointer& node);
|
UniqueSendThread createSendThread(const SharedNodePointer& node);
|
||||||
virtual UniqueSendThread newSendThread(const SharedNodePointer& node);
|
virtual UniqueSendThread newSendThread(const SharedNodePointer& node);
|
||||||
|
|
||||||
|
void replaceContentFromMessageData(QByteArray content);
|
||||||
|
|
||||||
int _argc;
|
int _argc;
|
||||||
const char** _argv;
|
const char** _argv;
|
||||||
char** _parsedArgV;
|
char** _parsedArgV;
|
||||||
|
|
|
@ -166,7 +166,6 @@
|
||||||
#include "scripting/WindowScriptingInterface.h"
|
#include "scripting/WindowScriptingInterface.h"
|
||||||
#include "scripting/ControllerScriptingInterface.h"
|
#include "scripting/ControllerScriptingInterface.h"
|
||||||
#include "scripting/RatesScriptingInterface.h"
|
#include "scripting/RatesScriptingInterface.h"
|
||||||
#include "scripting/DomainManagementScriptingInterface.h"
|
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||||
#include "SpeechRecognizer.h"
|
#include "SpeechRecognizer.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -560,7 +559,6 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
||||||
DependencyManager::set<BandwidthRecorder>();
|
DependencyManager::set<BandwidthRecorder>();
|
||||||
DependencyManager::set<ResourceCacheSharedItems>();
|
DependencyManager::set<ResourceCacheSharedItems>();
|
||||||
DependencyManager::set<DesktopScriptingInterface>();
|
DependencyManager::set<DesktopScriptingInterface>();
|
||||||
DependencyManager::set<DomainManagementScriptingInterface>();
|
|
||||||
DependencyManager::set<EntityScriptingInterface>(true);
|
DependencyManager::set<EntityScriptingInterface>(true);
|
||||||
DependencyManager::set<RecordingScriptingInterface>();
|
DependencyManager::set<RecordingScriptingInterface>();
|
||||||
DependencyManager::set<WindowScriptingInterface>();
|
DependencyManager::set<WindowScriptingInterface>();
|
||||||
|
@ -2154,7 +2152,6 @@ void Application::initializeUi() {
|
||||||
surfaceContext->setContextProperty("Render", _renderEngine->getConfiguration().get());
|
surfaceContext->setContextProperty("Render", _renderEngine->getConfiguration().get());
|
||||||
surfaceContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface());
|
surfaceContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface());
|
||||||
surfaceContext->setContextProperty("Snapshot", DependencyManager::get<Snapshot>().data());
|
surfaceContext->setContextProperty("Snapshot", DependencyManager::get<Snapshot>().data());
|
||||||
surfaceContext->setContextProperty("DomainManagement", DependencyManager::get<DomainManagementScriptingInterface>().data());
|
|
||||||
|
|
||||||
surfaceContext->setContextProperty("ApplicationCompositor", &getApplicationCompositor());
|
surfaceContext->setContextProperty("ApplicationCompositor", &getApplicationCompositor());
|
||||||
|
|
||||||
|
@ -5834,7 +5831,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("OffscreenFlags", DependencyManager::get<OffscreenUi>()->getFlags());
|
scriptEngine->registerGlobalObject("OffscreenFlags", DependencyManager::get<OffscreenUi>()->getFlags());
|
||||||
scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
|
scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
|
||||||
scriptEngine->registerGlobalObject("DomainManagement", DependencyManager::get<DomainManagementScriptingInterface>().data());
|
|
||||||
|
|
||||||
qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<ToolbarProxy>, wrapperFromScriptValue<ToolbarProxy>);
|
qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<ToolbarProxy>, wrapperFromScriptValue<ToolbarProxy>);
|
||||||
qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<ToolbarButtonProxy>, wrapperFromScriptValue<ToolbarButtonProxy>);
|
qScriptRegisterMetaType(scriptEngine, wrapperToScriptValue<ToolbarButtonProxy>, wrapperFromScriptValue<ToolbarButtonProxy>);
|
||||||
|
@ -6143,15 +6139,14 @@ bool Application::askToReplaceDomainContent(const QString& url) {
|
||||||
if (agreeToReplaceContent) {
|
if (agreeToReplaceContent) {
|
||||||
// Given confirmation, send request to domain server to replace content
|
// Given confirmation, send request to domain server to replace content
|
||||||
qCDebug(interfaceapp) << "Attempting to replace domain content: " << url;
|
qCDebug(interfaceapp) << "Attempting to replace domain content: " << url;
|
||||||
QByteArray _url(url.toUtf8());
|
QByteArray urlData(url.toUtf8());
|
||||||
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
|
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
limitedNodeList->eachMatchingNode([](const SharedNodePointer& node) {
|
limitedNodeList->eachMatchingNode([](const SharedNodePointer& node) {
|
||||||
return node->getType() == NodeType::EntityServer && node->getActiveSocket();
|
return node->getType() == NodeType::EntityServer && node->getActiveSocket();
|
||||||
}, [&_url, limitedNodeList](const SharedNodePointer& octreeNode) {
|
}, [&urlData, limitedNodeList](const SharedNodePointer& octreeNode) {
|
||||||
auto octreeFilePacket = NLPacket::create(PacketType::OctreeFileReplacementFromUrl, _url.size(), true);
|
auto octreeFilePacket = NLPacket::create(PacketType::OctreeFileReplacementFromUrl, urlData.size(), true);
|
||||||
octreeFilePacket->write(_url);
|
octreeFilePacket->write(urlData);
|
||||||
limitedNodeList->sendPacket(std::move(octreeFilePacket), *octreeNode);
|
limitedNodeList->sendPacket(std::move(octreeFilePacket), *octreeNode);
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(DOMAIN_SPAWNING_POINT);
|
DependencyManager::get<AddressManager>()->handleLookupString(DOMAIN_SPAWNING_POINT);
|
||||||
methodDetails = "SuccessfulRequestToReplaceContent";
|
methodDetails = "SuccessfulRequestToReplaceContent";
|
||||||
|
@ -6171,7 +6166,7 @@ bool Application::askToReplaceDomainContent(const QString& url) {
|
||||||
{ "content_set_url", url }
|
{ "content_set_url", url }
|
||||||
};
|
};
|
||||||
UserActivityLogger::getInstance().logAction("replace_domain_content", messageProperties);
|
UserActivityLogger::getInstance().logAction("replace_domain_content", messageProperties);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::displayAvatarAttachmentWarning(const QString& message) const {
|
void Application::displayAvatarAttachmentWarning(const QString& message) const {
|
||||||
|
|
Loading…
Reference in a new issue