From 31abc24e81f2e8f7a5e176e8d0747edeb173271f Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 19 Apr 2026 09:10:59 -0700 Subject: [PATCH] don't allow players to pick up items if they are too far away --- src/CommonFileFormats.hh | 8 ++++++++ src/ReceiveSubcommands.cc | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/CommonFileFormats.hh b/src/CommonFileFormats.hh index 01b31e18..539701bd 100644 --- a/src/CommonFileFormats.hh +++ b/src/CommonFileFormats.hh @@ -37,6 +37,14 @@ struct VectorXZF { inline double norm2() const { return ((this->x * this->x) + (this->z * this->z)); } + inline double dist(const VectorXZF& other) const { + return sqrt(this->dist2(other)); + } + inline double dist2(const VectorXZF& other) const { + double x = this->x - other.x; + double z = this->z - other.z; + return ((x * x) + (z * z)); + } inline VectorXZF rotate_y(double angle) const { double s = sin(angle); diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 5aed3636..55ee7d97 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -2264,6 +2264,15 @@ static asio::awaitable on_pick_up_item_generic( co_return; } + // TODO: Figure out what the actual max range is; 30 is an overestimate + double dist2 = fi->pos.dist2(c->pos); + if (dist2 > 900.0) { + l->log.warning_f("Player {} requests to pick up {:08X}, but it is too far away (dist2={})", + client_id, item_id, dist2); + l->add_item(floor, fi); + co_return; + } + try { p->add_item(fi->data, *s->item_stack_limits(c->version())); } catch (const out_of_range&) {