1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Server-side authority for attached players (#10952)

The server must have authority about attachments. This commit ignores any player movement packets as long they're attached.
This commit is contained in:
SmallJoker 2021-02-15 20:41:19 +01:00 committed by GitHub
parent f018737b06
commit 7832b6843e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 35 deletions

View file

@ -260,10 +260,13 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// otherwise it's calculated normally.
// If the object gets detached this comes into effect automatically from
// the last known origin.
if (isAttached()) {
v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
if (auto *parent = getParent()) {
v3f pos = parent->getBasePosition();
m_last_good_position = pos;
setBasePosition(pos);
if (m_player)
m_player->setSpeed(v3f());
}
if (!send_recommended)
@ -570,34 +573,11 @@ void PlayerSAO::setMaxSpeedOverride(const v3f &vel)
bool PlayerSAO::checkMovementCheat()
{
if (m_is_singleplayer ||
isAttached() ||
g_settings->getBool("disable_anticheat")) {
m_last_good_position = m_base_position;
return false;
}
if (UnitSAO *parent = dynamic_cast<UnitSAO *>(getParent())) {
v3f attachment_pos;
{
int parent_id;
std::string bone;
v3f attachment_rot;
bool force_visible;
getAttachment(&parent_id, &bone, &attachment_pos, &attachment_rot, &force_visible);
}
v3f parent_pos = parent->getBasePosition();
f32 diff = m_base_position.getDistanceFromSQ(parent_pos) - attachment_pos.getLengthSQ();
const f32 maxdiff = 4.0f * BS; // fair trade-off value for various latencies
if (diff > maxdiff * maxdiff) {
setBasePosition(parent_pos);
actionstream << "Server: " << m_player->getName()
<< " moved away from parent; diff=" << sqrtf(diff) / BS
<< " resetting position." << std::endl;
return true;
}
// Player movement is locked to the entity. Skip further checks
return false;
}
bool cheated = false;
/*