mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-06 11:34:27 +02:00
filter gets isAdd argument
This commit is contained in:
parent
f4e57898c6
commit
4499a92a82
2 changed files with 11 additions and 6 deletions
|
@ -934,7 +934,7 @@ void EntityTree::initEntityEditFilterEngine(QScriptEngine* engine, std::function
|
||||||
_hasEntityEditFilter = true;
|
_hasEntityEditFilter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged) {
|
bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, bool isAdd) {
|
||||||
if (!_entityEditFilterEngine) {
|
if (!_entityEditFilterEngine) {
|
||||||
propertiesOut = propertiesIn;
|
propertiesOut = propertiesIn;
|
||||||
wasChanged = false; // not changed
|
wasChanged = false; // not changed
|
||||||
|
@ -953,6 +953,7 @@ bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItem
|
||||||
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
|
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
|
||||||
QScriptValueList args;
|
QScriptValueList args;
|
||||||
args << inputValues;
|
args << inputValues;
|
||||||
|
args << isAdd;
|
||||||
|
|
||||||
QScriptValue result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
|
QScriptValue result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
|
||||||
if (_entityEditFilterHadUncaughtExceptions()) {
|
if (_entityEditFilterHadUncaughtExceptions()) {
|
||||||
|
@ -989,6 +990,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
}
|
}
|
||||||
|
|
||||||
int processedBytes = 0;
|
int processedBytes = 0;
|
||||||
|
bool isAdd = false;
|
||||||
// we handle these types of "edit" packets
|
// we handle these types of "edit" packets
|
||||||
switch (message.getType()) {
|
switch (message.getType()) {
|
||||||
case PacketType::EntityErase: {
|
case PacketType::EntityErase: {
|
||||||
|
@ -998,6 +1000,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
}
|
}
|
||||||
|
|
||||||
case PacketType::EntityAdd:
|
case PacketType::EntityAdd:
|
||||||
|
isAdd = true; // fall through to next case
|
||||||
case PacketType::EntityEdit: {
|
case PacketType::EntityEdit: {
|
||||||
quint64 startDecode = 0, endDecode = 0;
|
quint64 startDecode = 0, endDecode = 0;
|
||||||
quint64 startLookup = 0, endLookup = 0;
|
quint64 startLookup = 0, endLookup = 0;
|
||||||
|
@ -1040,7 +1043,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this was an add, we also want to tell the client that sent this edit that the entity was not added.
|
// If this was an add, we also want to tell the client that sent this edit that the entity was not added.
|
||||||
if (message.getType() == PacketType::EntityAdd) {
|
if (isAdd) {
|
||||||
QWriteLocker locker(&_recentlyDeletedEntitiesLock);
|
QWriteLocker locker(&_recentlyDeletedEntitiesLock);
|
||||||
_recentlyDeletedEntityItemIDs.insert(usecTimestampNow(), entityItemID);
|
_recentlyDeletedEntityItemIDs.insert(usecTimestampNow(), entityItemID);
|
||||||
validEditPacket = passedWhiteList;
|
validEditPacket = passedWhiteList;
|
||||||
|
@ -1050,7 +1053,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((message.getType() == PacketType::EntityAdd ||
|
if ((isAdd ||
|
||||||
(message.getType() == PacketType::EntityEdit && properties.lifetimeChanged())) &&
|
(message.getType() == PacketType::EntityEdit && properties.lifetimeChanged())) &&
|
||||||
!senderNode->getCanRez() && senderNode->getCanRezTmp()) {
|
!senderNode->getCanRez() && senderNode->getCanRezTmp()) {
|
||||||
// this node is only allowed to rez temporary entities. if need be, cap the lifetime.
|
// this node is only allowed to rez temporary entities. if need be, cap the lifetime.
|
||||||
|
@ -1068,9 +1071,11 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
startFilter = usecTimestampNow();
|
startFilter = usecTimestampNow();
|
||||||
bool wasChanged = false;
|
bool wasChanged = false;
|
||||||
// Having (un)lock rights bypasses the filter.
|
// Having (un)lock rights bypasses the filter.
|
||||||
bool allowed = senderNode->isAllowedEditor() || filterProperties(properties, properties, wasChanged);
|
bool allowed = senderNode->isAllowedEditor() || filterProperties(properties, properties, wasChanged, isAdd);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
|
auto timestamp = properties.getLastEdited();
|
||||||
properties = EntityItemProperties();
|
properties = EntityItemProperties();
|
||||||
|
properties.setLastEdited(timestamp);
|
||||||
}
|
}
|
||||||
if (!allowed || wasChanged) {
|
if (!allowed || wasChanged) {
|
||||||
bumpTimestamp(properties);
|
bumpTimestamp(properties);
|
||||||
|
@ -1110,7 +1115,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
existingEntity->markAsChangedOnServer();
|
existingEntity->markAsChangedOnServer();
|
||||||
endUpdate = usecTimestampNow();
|
endUpdate = usecTimestampNow();
|
||||||
_totalUpdates++;
|
_totalUpdates++;
|
||||||
} else if (message.getType() == PacketType::EntityAdd) {
|
} else if (isAdd) {
|
||||||
bool failedAdd = !allowed;
|
bool failedAdd = !allowed;
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
qCDebug(entities) << "Filtered entity add. ID:" << entityItemID;
|
qCDebug(entities) << "Filtered entity add. ID:" << entityItemID;
|
||||||
|
|
|
@ -357,7 +357,7 @@ protected:
|
||||||
|
|
||||||
float _maxTmpEntityLifetime { DEFAULT_MAX_TMP_ENTITY_LIFETIME };
|
float _maxTmpEntityLifetime { DEFAULT_MAX_TMP_ENTITY_LIFETIME };
|
||||||
|
|
||||||
bool filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged);
|
bool filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, bool isAdd);
|
||||||
bool _hasEntityEditFilter{ false };
|
bool _hasEntityEditFilter{ false };
|
||||||
QScriptEngine* _entityEditFilterEngine{};
|
QScriptEngine* _entityEditFilterEngine{};
|
||||||
QScriptValue _entityEditFilterFunction{};
|
QScriptValue _entityEditFilterFunction{};
|
||||||
|
|
Loading…
Reference in a new issue