FEAT: player anticheat speed

This commit is contained in:
2026-03-27 19:41:54 +02:00
parent 6957f144e1
commit 8be842a8ac
5 changed files with 48 additions and 19 deletions

View File

@@ -120,6 +120,8 @@ public:
void optionUpdated(OptionId option, bool value); void optionUpdated(OptionId option, bool value);
void optionUpdated(OptionId option, float value); void optionUpdated(OptionId option, float value);
void optionUpdated(OptionId option, int value); void optionUpdated(OptionId option, int value);
int getTicks() { return ticks; }
#ifdef __APPLE__ #ifdef __APPLE__
bool _isSuperFast; bool _isSuperFast;
bool isSuperFast() { return _isSuperFast; } bool isSuperFast() { return _isSuperFast; }
@@ -197,7 +199,8 @@ public:
std::string externalCacheStoragePath; std::string externalCacheStoragePath;
protected: protected:
Timer timer; Timer timer;
// @note @attn @warn: this is dangerous as fuck!
// @note @attn @warn: this is dangerous as fuck!
volatile bool isGeneratingLevel; volatile bool isGeneratingLevel;
bool _hasSignaledGeneratingLevelFinished; bool _hasSignaledGeneratingLevelFinished;

View File

@@ -77,10 +77,10 @@ void PlayerRenderer::render(Entity* mob_, float x, float y, float z, float rot,
model = desired; model = desired;
humanoidModel = desired; humanoidModel = desired;
} }
LOGI("[PlayerRenderer] %s: skin=%s, modelTex=%dx%d, desired=%s\n", /* LOGI("[PlayerRenderer] %s: skin=%s, modelTex=%dx%d, desired=%s\n",
((Player*)mob)->name.c_str(), mob->getTexture().c_str(), ((Player*)mob)->name.c_str(), mob->getTexture().c_str(),
humanoidModel->texWidth, humanoidModel->texHeight, humanoidModel->texWidth, humanoidModel->texHeight,
(desired == playerModel64 ? "64" : "32")); (desired == playerModel64 ? "64" : "32")); */
HumanoidMobRenderer::render(mob_, x, y, z, rot, a); HumanoidMobRenderer::render(mob_, x, y, z, rot, a);
} }

View File

@@ -21,6 +21,7 @@
#include "../raknet/RakPeerInterface.h" #include "../raknet/RakPeerInterface.h"
#include "../raknet/PacketPriority.h" #include "../raknet/PacketPriority.h"
#include "platform/log.h" #include "platform/log.h"
#include "util/Mth.h"
#include "world/item/ItemInstance.h" #include "world/item/ItemInstance.h"
#include "world/phys/Vec3.h" #include "world/phys/Vec3.h"
#include "world/item/crafting/Recipe.h" #include "world/item/crafting/Recipe.h"
@@ -360,12 +361,22 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
//LOGI("MovePlayerPacket\n"); //LOGI("MovePlayerPacket\n");
if (Entity* entity = level->getEntity(packet->entityId)) if (Entity* entity = level->getEntity(packet->entityId))
{ {
ServerPlayer* player = (ServerPlayer*) getPlayer(source);
entity->xd = entity->yd = entity->zd = 0;
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
// broadcast this packet to other clients float vectorDist = sqrt( (packet->x - entity->x) * (packet->x - entity->x) +
redistributePacket(packet, source); (packet->y - entity->y) * (packet->y - entity->y) +
(packet->z - entity->z) * (packet->z - entity->z));
float speed = vectorDist / (minecraft->getTicks() - player->lastMoveTicks);
if (speed < 2.5f) {
entity->xd = entity->yd = entity->zd = 0;
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
// broadcast this packet to other clients
redistributePacket(packet, source);
}
player->lastMoveTicks = minecraft->getTicks();
} }
} }

View File

@@ -12,16 +12,19 @@ ServerLevel::ServerLevel(LevelStorage* levelStorage, const std::string& levelNam
void ServerLevel::updateSleepingPlayerList() { void ServerLevel::updateSleepingPlayerList() {
bool allPlayersWasSleeping = allPlayersAreSleeping; bool allPlayersWasSleeping = allPlayersAreSleeping;
allPlayersAreSleeping = !players.empty(); allPlayersAreSleeping = !players.empty();
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
Player* player = *it; Player* player = *it;
if(!player->isSleeping()) {
if (!player->isSleeping()) {
allPlayersAreSleeping = false; allPlayersAreSleeping = false;
break; break;
} }
} }
if(!allPlayersWasSleeping && allPlayersAreSleeping) { if (!allPlayersWasSleeping && allPlayersAreSleeping) {
levelEvent(NULL, LevelEvent::ALL_PLAYERS_SLEEPING, 0, 0, 0, 0); levelEvent(NULL, LevelEvent::ALL_PLAYERS_SLEEPING, 0, 0, 0, 0);
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
(*it)->setAllPlayersSleeping(); (*it)->setAllPlayersSleeping();
} }
} }
@@ -29,23 +32,26 @@ void ServerLevel::updateSleepingPlayerList() {
void ServerLevel::awakenAllPlayers() { void ServerLevel::awakenAllPlayers() {
allPlayersAreSleeping = false; allPlayersAreSleeping = false;
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
Player* player = *it; Player* player = *it;
if(player->isSleeping()) {
if (player->isSleeping()) {
player->stopSleepInBed(false, false, true); player->stopSleepInBed(false, false, true);
player->health = Player::MAX_HEALTH; player->health = Player::MAX_HEALTH;
player->lastHealth = Player::MAX_HEALTH; player->lastHealth = Player::MAX_HEALTH;
} }
} }
SetHealthPacket packet(Player::MAX_HEALTH); SetHealthPacket packet(Player::MAX_HEALTH);
raknetInstance->send(packet); raknetInstance->send(packet);
} }
bool ServerLevel::allPlayersSleeping() { bool ServerLevel::allPlayersSleeping() {
if(allPlayersAreSleeping && !isClientSide) { if (allPlayersAreSleeping && !isClientSide) {
// all players are sleeping, but have they slept long enough? // all players are sleeping, but have they slept long enough?
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) { for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
if(!(*it)->isSleepingLongEnough()) { if (!(*it)->isSleepingLongEnough()) {
return false; return false;
} }
} }
@@ -55,13 +61,17 @@ bool ServerLevel::allPlayersSleeping() {
return false; return false;
} }
void ServerLevel::tick(){ void ServerLevel::tick() {
super::tick(); super::tick();
if(allPlayersSleeping()) {
if (allPlayersSleeping()) {
long newTime = levelData.getTime() + TICKS_PER_DAY; long newTime = levelData.getTime() + TICKS_PER_DAY;
levelData.setTime(newTime - (newTime % TICKS_PER_DAY)); levelData.setTime(newTime - (newTime % TICKS_PER_DAY));
SetTimePacket packet(levelData.getTime()); SetTimePacket packet(levelData.getTime());
raknetInstance->send(packet); raknetInstance->send(packet);
awakenAllPlayers(); awakenAllPlayers();
} }
} }

View File

@@ -43,6 +43,11 @@ public:
virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint); virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
void completeUsingItem(); void completeUsingItem();
// Getter and setter? Doesnt hear about that
// TODO: Getter and setter :trollface:
int lastMoveTicks = 0;
int ticksInAir = 0;
private: private:
void nextContainerCounter(); void nextContainerCounter();
void setContainerMenu( BaseContainerMenu* menu ); void setContainerMenu( BaseContainerMenu* menu );