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

Separate anticheat settings (#15040)

This commit is contained in:
Zemtzov7 2024-10-11 15:01:22 +05:00 committed by GitHub
parent d2b4c27f21
commit 1b2d24791a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 47 additions and 8 deletions

View file

@ -884,8 +884,13 @@ default_privs (Default privileges) string interact, shout
# Privileges that players with basic_privs can grant # Privileges that players with basic_privs can grant
basic_privs (Basic privileges) string interact, shout basic_privs (Basic privileges) string interact, shout
# If enabled, disable cheat prevention in multiplayer. # Server anticheat configuration.
disable_anticheat (Disable anticheat) bool false # Flags are positive. Uncheck the flag to disable corresponding anticheat module.
anticheat_flags (Anticheat flags) flags digging,interaction,movement digging,interaction,movement
# Tolerance of movement cheat detector.
# Increase the value if players experience stuttery movement.
anticheat_movement_tolerance (Anticheat movement tolerance) float 1.0 1.0
# If enabled, actions are recorded for rollback. # If enabled, actions are recorded for rollback.
# This option is only read when server starts. # This option is only read when server starts.

View file

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h" #include "porting.h"
#include "mapgen/mapgen.h" // Mapgen::setDefaultSettings #include "mapgen/mapgen.h" // Mapgen::setDefaultSettings
#include "util/string.h" #include "util/string.h"
#include "server.h"
/* /*
@ -459,7 +460,9 @@ void set_default_settings()
settings->setDefault("enable_pvp", "true"); settings->setDefault("enable_pvp", "true");
settings->setDefault("enable_mod_channels", "false"); settings->setDefault("enable_mod_channels", "false");
settings->setDefault("disallow_empty_password", "false"); settings->setDefault("disallow_empty_password", "false");
settings->setDefault("disable_anticheat", "false"); settings->setDefault("anticheat_flags", flagdesc_anticheat,
AC_DIGGING | AC_INTERACTION | AC_MOVEMENT);
settings->setDefault("anticheat_movement_tolerance", "1.0");
settings->setDefault("enable_rollback_recording", "false"); settings->setDefault("enable_rollback_recording", "false");
settings->setDefault("deprecated_lua_api_handling", "log"); settings->setDefault("deprecated_lua_api_handling", "log");

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-2.1-or-later // SPDX-License-Identifier: LGPL-2.1-or-later
#include "settings.h" #include "settings.h"
#include "server.h"
void migrate_settings() void migrate_settings()
{ {
@ -19,4 +20,12 @@ void migrate_settings()
g_settings->setBool("touch_gui", value); g_settings->setBool("touch_gui", value);
g_settings->remove("enable_touch"); g_settings->remove("enable_touch");
} }
// Disables anticheat
if (g_settings->existsLocal("disable_anticheat")) {
if (g_settings->getBool("disable_anticheat")) {
g_settings->setFlagStr("anticheat_flags", 0, flagdesc_anticheat);
}
g_settings->remove("disable_anticheat");
}
} }

View file

@ -1011,12 +1011,12 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
/* /*
Check that target is reasonably close Check that target is reasonably close
*/ */
static thread_local const bool enable_anticheat = static thread_local const u32 anticheat_flags =
!g_settings->getBool("disable_anticheat"); g_settings->getFlagStr("anticheat_flags", flagdesc_anticheat, nullptr);
if ((action == INTERACT_START_DIGGING || action == INTERACT_DIGGING_COMPLETED || if ((action == INTERACT_START_DIGGING || action == INTERACT_DIGGING_COMPLETED ||
action == INTERACT_PLACE || action == INTERACT_USE) && action == INTERACT_PLACE || action == INTERACT_USE) &&
enable_anticheat && !isSingleplayer()) { (anticheat_flags & AC_INTERACTION) && !isSingleplayer()) {
v3f target_pos = player_pos; v3f target_pos = player_pos;
if (pointed.type == POINTEDTHING_NODE) { if (pointed.type == POINTEDTHING_NODE) {
target_pos = intToFloat(pointed.node_undersurface, BS); target_pos = intToFloat(pointed.node_undersurface, BS);
@ -1119,7 +1119,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
/* Cheat prevention */ /* Cheat prevention */
bool is_valid_dig = true; bool is_valid_dig = true;
if (enable_anticheat && !isSingleplayer()) { if ((anticheat_flags & AC_DIGGING) && !isSingleplayer()) {
v3s16 nocheat_p = playersao->getNoCheatDigPos(); v3s16 nocheat_p = playersao->getNoCheatDigPos();
float nocheat_t = playersao->getNoCheatDigTime(); float nocheat_t = playersao->getNoCheatDigTime();
playersao->noCheatDigEnd(); playersao->noCheatDigEnd();

View file

@ -81,6 +81,20 @@ struct PackedValue;
struct ParticleParameters; struct ParticleParameters;
struct ParticleSpawnerParameters; struct ParticleSpawnerParameters;
// Anticheat flags
enum {
AC_DIGGING = 0x01,
AC_INTERACTION = 0x02,
AC_MOVEMENT = 0x04
};
constexpr const static FlagDesc flagdesc_anticheat[] = {
{"digging", AC_DIGGING},
{"interaction", AC_INTERACTION},
{"movement", AC_MOVEMENT},
{NULL, 0}
};
enum ClientDeletionReason { enum ClientDeletionReason {
CDR_LEAVE, CDR_LEAVE,
CDR_TIMEOUT, CDR_TIMEOUT,

View file

@ -646,9 +646,12 @@ void PlayerSAO::setMaxSpeedOverride(const v3f &vel)
bool PlayerSAO::checkMovementCheat() bool PlayerSAO::checkMovementCheat()
{ {
static thread_local const u32 anticheat_flags =
g_settings->getFlagStr("anticheat_flags", flagdesc_anticheat, nullptr);
if (m_is_singleplayer || if (m_is_singleplayer ||
isAttached() || isAttached() ||
g_settings->getBool("disable_anticheat")) { !(anticheat_flags & AC_MOVEMENT)) {
m_last_good_position = m_base_position; m_last_good_position = m_base_position;
return false; return false;
} }
@ -729,6 +732,11 @@ bool PlayerSAO::checkMovementCheat()
required_time = MYMAX(required_time, d_vert / s); required_time = MYMAX(required_time, d_vert / s);
} }
static thread_local float anticheat_movement_tolerance =
std::max(g_settings->getFloat("anticheat_movement_tolerance"), 1.0f);
required_time /= anticheat_movement_tolerance;
if (m_move_pool.grab(required_time)) { if (m_move_pool.grab(required_time)) {
m_last_good_position = m_base_position; m_last_good_position = m_base_position;
} else { } else {