mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
minimum entity edit filter
This commit is contained in:
parent
f9a36d68ad
commit
f6446c6806
6 changed files with 72 additions and 0 deletions
|
@ -285,6 +285,12 @@ void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectio
|
|||
} else {
|
||||
tree->setEntityScriptSourceWhitelist("");
|
||||
}
|
||||
|
||||
QString entityEditFilter;
|
||||
if (readOptionString("entityEditFilter", settingsSectionObject, entityEditFilter)) {
|
||||
tree->setEntityEditFilter(entityEditFilter);
|
||||
}
|
||||
tree->initEntityEditFilterEngine(); // whether supplied or not.
|
||||
}
|
||||
|
||||
void EntityServer::nodeAdded(SharedNodePointer node) {
|
||||
|
|
|
@ -660,6 +660,7 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
quint64 averageUpdateTime = _tree->getAverageUpdateTime();
|
||||
quint64 averageCreateTime = _tree->getAverageCreateTime();
|
||||
quint64 averageLoggingTime = _tree->getAverageLoggingTime();
|
||||
quint64 averageFilterTime = _tree->getAverageFilterTime();
|
||||
|
||||
int FLOAT_PRECISION = 3;
|
||||
|
||||
|
@ -699,6 +700,8 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
.arg(locale.toString((uint)averageCreateTime).rightJustified(COLUMN_WIDTH, ' '));
|
||||
statsString += QString(" Average Logging Time: %1 usecs\r\n")
|
||||
.arg(locale.toString((uint)averageLoggingTime).rightJustified(COLUMN_WIDTH, ' '));
|
||||
statsString += QString(" Average Filter Time: %1 usecs\r\n")
|
||||
.arg(locale.toString((uint)averageFilterTime).rightJustified(COLUMN_WIDTH, ' '));
|
||||
|
||||
|
||||
int senderNumber = 0;
|
||||
|
|
|
@ -1290,6 +1290,14 @@
|
|||
"default": "",
|
||||
"advanced": true
|
||||
},
|
||||
{
|
||||
"name": "entityEditFilter",
|
||||
"label": "Filter Entity Edits",
|
||||
"help": "Check all entity edits against this filter function.",
|
||||
"placeholder": "function filter(properties) { return properties; }",
|
||||
"default": "",
|
||||
"advanced": true
|
||||
},
|
||||
{
|
||||
"name": "persistFilePath",
|
||||
"label": "Entities File Path",
|
||||
|
|
|
@ -918,6 +918,31 @@ void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList<Q
|
|||
}
|
||||
}
|
||||
|
||||
void EntityTree::initEntityEditFilterEngine() {
|
||||
_entityEditFilterEngine.evaluate(_entityEditFilter);
|
||||
auto global = _entityEditFilterEngine.globalObject();
|
||||
_entityEditFilterFunction = global.property("filter");
|
||||
_hasEntityEditFilter = _entityEditFilterFunction.isFunction();
|
||||
}
|
||||
|
||||
bool EntityTree::filterProperties(const EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged) {
|
||||
if (!_hasEntityEditFilter) {
|
||||
propertiesOut = propertiesIn;
|
||||
wasChanged = false; // not changed
|
||||
return true; // allowed
|
||||
}
|
||||
QScriptValue inputValues = propertiesIn.copyToScriptValue(&_entityEditFilterEngine, false);
|
||||
QScriptValueList args;
|
||||
args << inputValues;
|
||||
|
||||
QScriptValue result = _entityEditFilterEngine.newObject();
|
||||
result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
|
||||
|
||||
propertiesOut.copyFromScriptValue(result, false);
|
||||
wasChanged = result.equals(inputValues); // not changed
|
||||
return result.isObject(); // filters should return null or false to completely reject edit or add
|
||||
}
|
||||
|
||||
int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,
|
||||
const SharedNodePointer& senderNode) {
|
||||
|
||||
|
@ -941,6 +966,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
quint64 startLookup = 0, endLookup = 0;
|
||||
quint64 startUpdate = 0, endUpdate = 0;
|
||||
quint64 startCreate = 0, endCreate = 0;
|
||||
quint64 startFilter = 0, endFilter = 0;
|
||||
quint64 startLogging = 0, endLogging = 0;
|
||||
|
||||
const quint64 LAST_EDITED_SERVERSIDE_BUMP = 1; // usec
|
||||
|
@ -1000,6 +1026,21 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
// If we got a valid edit packet, then it could be a new entity or it could be an update to
|
||||
// an existing entity... handle appropriately
|
||||
if (validEditPacket) {
|
||||
|
||||
startFilter = usecTimestampNow();
|
||||
QScriptValue originalValues = properties.copyToScriptValue(&_entityEditFilterEngine, true);
|
||||
bool wasChanged = false;
|
||||
bool allowed = filterProperties(properties, properties, wasChanged);
|
||||
QScriptValue filteredResult = properties.copyToScriptValue(&_entityEditFilterEngine, true);
|
||||
if (wasChanged) {
|
||||
if (properties.getLastEdited() == UNKNOWN_CREATED_TIME) {
|
||||
properties.setLastEdited(usecTimestampNow());
|
||||
}
|
||||
properties.setLastEdited(properties.getLastEdited() + LAST_EDITED_SERVERSIDE_BUMP);
|
||||
}
|
||||
qDebug() << "FIXME changed/allowed" << wasChanged << allowed;
|
||||
endFilter = usecTimestampNow();
|
||||
|
||||
// search for the entity by EntityItemID
|
||||
startLookup = usecTimestampNow();
|
||||
EntityItemPointer existingEntity = findEntityByEntityItemID(entityItemID);
|
||||
|
@ -1077,6 +1118,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
_totalUpdateTime += endUpdate - startUpdate;
|
||||
_totalCreateTime += endCreate - startCreate;
|
||||
_totalLoggingTime += endLogging - startLogging;
|
||||
_totalFilterTime += endFilter - startFilter;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
|
||||
void setEntityMaxTmpLifetime(float maxTmpEntityLifetime) { _maxTmpEntityLifetime = maxTmpEntityLifetime; }
|
||||
void setEntityScriptSourceWhitelist(const QString& entityScriptSourceWhitelist);
|
||||
void setEntityEditFilter(const QString& entityEditFilter) { _entityEditFilter = entityEditFilter; }
|
||||
|
||||
/// Implements our type specific root element factory
|
||||
virtual OctreeElementPointer createNewElement(unsigned char* octalCode = NULL) override;
|
||||
|
@ -235,6 +236,7 @@ public:
|
|||
virtual quint64 getAverageUpdateTime() const override { return _totalUpdates == 0 ? 0 : _totalUpdateTime / _totalUpdates; }
|
||||
virtual quint64 getAverageCreateTime() const override { return _totalCreates == 0 ? 0 : _totalCreateTime / _totalCreates; }
|
||||
virtual quint64 getAverageLoggingTime() const override { return _totalEditMessages == 0 ? 0 : _totalLoggingTime / _totalEditMessages; }
|
||||
virtual quint64 getAverageFilterTime() const override { return _totalEditMessages == 0 ? 0 : _totalFilterTime / _totalEditMessages; }
|
||||
|
||||
void trackIncomingEntityLastEdited(quint64 lastEditedTime, int bytesRead);
|
||||
quint64 getAverageEditDeltas() const
|
||||
|
@ -261,6 +263,8 @@ public:
|
|||
|
||||
void notifyNewCollisionSoundURL(const QString& newCollisionSoundURL, const EntityItemID& entityID);
|
||||
|
||||
void initEntityEditFilterEngine();
|
||||
|
||||
static const float DEFAULT_MAX_TMP_ENTITY_LIFETIME;
|
||||
|
||||
public slots:
|
||||
|
@ -327,6 +331,7 @@ protected:
|
|||
quint64 _totalUpdateTime = 0;
|
||||
quint64 _totalCreateTime = 0;
|
||||
quint64 _totalLoggingTime = 0;
|
||||
quint64 _totalFilterTime = 0;
|
||||
|
||||
// these performance statistics are only used in the client
|
||||
void resetClientEditStats();
|
||||
|
@ -346,6 +351,13 @@ protected:
|
|||
|
||||
float _maxTmpEntityLifetime { DEFAULT_MAX_TMP_ENTITY_LIFETIME };
|
||||
|
||||
bool filterProperties(const EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged);
|
||||
QString _entityEditFilter;
|
||||
bool _hasEntityEditFilter{ false };
|
||||
QScriptEngine _entityEditFilterEngine;
|
||||
QScriptValue _entityEditFilterFunction;
|
||||
QScriptValue _nullObjectForFilter;
|
||||
|
||||
QStringList _entityScriptSourceWhitelist;
|
||||
};
|
||||
|
||||
|
|
|
@ -349,6 +349,7 @@ public:
|
|||
virtual quint64 getAverageUpdateTime() const { return 0; }
|
||||
virtual quint64 getAverageCreateTime() const { return 0; }
|
||||
virtual quint64 getAverageLoggingTime() const { return 0; }
|
||||
virtual quint64 getAverageFilterTime() const { return 0; }
|
||||
|
||||
signals:
|
||||
void importSize(float x, float y, float z);
|
||||
|
|
Loading…
Reference in a new issue