1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

UnitSAO: Prevent circular attachments

This commit is contained in:
SmallJoker 2021-05-29 11:44:48 +02:00 committed by GitHub
parent ff48619a85
commit 5bf72468f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -124,6 +124,19 @@ void UnitSAO::sendOutdatedData()
void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position,
v3f rotation, bool force_visible)
{
auto *obj = parent_id ? m_env->getActiveObject(parent_id) : nullptr;
if (obj) {
// Do checks to avoid circular references
// The chain of wanted parent must not refer or contain "this"
for (obj = obj->getParent(); obj; obj = obj->getParent()) {
if (obj == this) {
warningstream << "Mod bug: Attempted to attach object " << m_id << " to parent "
<< parent_id << " but former is an (in)direct parent of latter." << std::endl;
return;
}
}
}
// Attachments need to be handled on both the server and client.
// If we just attach on the server, we can only copy the position of the parent.
// Attachments are still sent to clients at an interval so players might see them