mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 23:22:24 +01:00
Fix various bugs (Anticheat, Lua helpers) (#8013)
* Fix various bugs (Anticheat, Lua helpers) Anticheat: Use camera position instead of player position for shoot line calculations Lua helpers: Increase 'i' to not overwrite earlier added table values * Remove lag compensation * * 1.5 for larger selection boxes
This commit is contained in:
parent
70bf3439ab
commit
a122ba0ef4
@ -627,7 +627,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
|
|||||||
// Check for out-of-range interaction
|
// Check for out-of-range interaction
|
||||||
if (remote->type == InventoryLocation::NODEMETA) {
|
if (remote->type == InventoryLocation::NODEMETA) {
|
||||||
v3f node_pos = intToFloat(remote->p, BS);
|
v3f node_pos = intToFloat(remote->p, BS);
|
||||||
v3f player_pos = player->getPlayerSAO()->getBasePosition();
|
v3f player_pos = player->getPlayerSAO()->getEyePosition();
|
||||||
f32 d = player_pos.getDistanceFrom(node_pos);
|
f32 d = player_pos.getDistanceFrom(node_pos);
|
||||||
if (!checkInteractDistance(player, d, "inventory"))
|
if (!checkInteractDistance(player, d, "inventory"))
|
||||||
return;
|
return;
|
||||||
@ -969,8 +969,9 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std:
|
|||||||
else if (max_d < 0)
|
else if (max_d < 0)
|
||||||
max_d = BS * 4.0f;
|
max_d = BS * 4.0f;
|
||||||
|
|
||||||
// cube diagonal: sqrt(3) = 1.732
|
// Cube diagonal * 1.5 for maximal supported node extents:
|
||||||
if (d > max_d * 1.732) {
|
// sqrt(3) * 1.5 ≅ 2.6
|
||||||
|
if (d > max_d + 2.6f * BS) {
|
||||||
actionstream << "Player " << player->getName()
|
actionstream << "Player " << player->getName()
|
||||||
<< " tried to access " << what
|
<< " tried to access " << what
|
||||||
<< " from too far: "
|
<< " from too far: "
|
||||||
@ -1109,7 +1110,9 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||||||
|
|
||||||
if ((action == 0 || action == 2 || action == 3 || action == 4) &&
|
if ((action == 0 || action == 2 || action == 3 || action == 4) &&
|
||||||
enable_anticheat && !isSingleplayer()) {
|
enable_anticheat && !isSingleplayer()) {
|
||||||
float d = player_pos.getDistanceFrom(pointed_pos_under);
|
float d = playersao->getEyePosition()
|
||||||
|
.getDistanceFrom(pointed_pos_under);
|
||||||
|
|
||||||
if (!checkInteractDistance(player, d, pointed.dump())) {
|
if (!checkInteractDistance(player, d, pointed.dump())) {
|
||||||
// Re-send block to revert change on client-side
|
// Re-send block to revert change on client-side
|
||||||
RemoteClient *client = getClient(pkt->getPeerId());
|
RemoteClient *client = getClient(pkt->getPeerId());
|
||||||
|
@ -348,7 +348,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
|
|||||||
u16 i = 1;
|
u16 i = 1;
|
||||||
for (const std::string &texture : prop->textures) {
|
for (const std::string &texture : prop->textures) {
|
||||||
lua_pushlstring(L, texture.c_str(), texture.size());
|
lua_pushlstring(L, texture.c_str(), texture.size());
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
}
|
}
|
||||||
lua_setfield(L, -2, "textures");
|
lua_setfield(L, -2, "textures");
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
|
|||||||
i = 1;
|
i = 1;
|
||||||
for (const video::SColor &color : prop->colors) {
|
for (const video::SColor &color : prop->colors) {
|
||||||
push_ARGB8(L, color);
|
push_ARGB8(L, color);
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
}
|
}
|
||||||
lua_setfield(L, -2, "colors");
|
lua_setfield(L, -2, "colors");
|
||||||
|
|
||||||
@ -838,7 +838,7 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
|
|||||||
u16 i = 1;
|
u16 i = 1;
|
||||||
for (const std::string &it : c.connects_to) {
|
for (const std::string &it : c.connects_to) {
|
||||||
lua_pushlstring(L, it.c_str(), it.size());
|
lua_pushlstring(L, it.c_str(), it.size());
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
}
|
}
|
||||||
lua_setfield(L, -2, "connects_to");
|
lua_setfield(L, -2, "connects_to");
|
||||||
|
|
||||||
@ -961,7 +961,7 @@ void push_box(lua_State *L, const std::vector<aabb3f> &box)
|
|||||||
u8 i = 1;
|
u8 i = 1;
|
||||||
for (const aabb3f &it : box) {
|
for (const aabb3f &it : box) {
|
||||||
push_aabb3f(L, it);
|
push_aabb3f(L, it);
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,8 +532,7 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
for (const auto &dep : spec.depends) {
|
for (const auto &dep : spec.depends) {
|
||||||
lua_pushstring(L, dep.c_str());
|
lua_pushstring(L, dep.c_str());
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
lua_setfield(L, -2, "depends");
|
lua_setfield(L, -2, "depends");
|
||||||
|
|
||||||
@ -542,8 +541,7 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
|
|||||||
i = 1;
|
i = 1;
|
||||||
for (const auto &dep : spec.optdepends) {
|
for (const auto &dep : spec.optdepends) {
|
||||||
lua_pushstring(L, dep.c_str());
|
lua_pushstring(L, dep.c_str());
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
lua_setfield(L, -2, "optional_depends");
|
lua_setfield(L, -2, "optional_depends");
|
||||||
}
|
}
|
||||||
|
@ -1042,8 +1042,7 @@ int ModApiMapgen::l_get_gen_notify(lua_State *L)
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
for (u32 gen_notify_on_deco_id : emerge->gen_notify_on_deco_ids) {
|
for (u32 gen_notify_on_deco_id : emerge->gen_notify_on_deco_ids) {
|
||||||
lua_pushnumber(L, gen_notify_on_deco_id);
|
lua_pushnumber(L, gen_notify_on_deco_id);
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -1681,8 +1681,7 @@ int ObjectRef::l_get_sky(lua_State *L)
|
|||||||
s16 i = 1;
|
s16 i = 1;
|
||||||
for (const std::string ¶m : params) {
|
for (const std::string ¶m : params) {
|
||||||
lua_pushlstring(L, param.c_str(), param.size());
|
lua_pushlstring(L, param.c_str(), param.size());
|
||||||
lua_rawseti(L, -2, i);
|
lua_rawseti(L, -2, i++);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
lua_pushboolean(L, clouds);
|
lua_pushboolean(L, clouds);
|
||||||
return 4;
|
return 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user