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

View File

@@ -77,10 +77,10 @@ void PlayerRenderer::render(Entity* mob_, float x, float y, float z, float rot,
model = 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(),
humanoidModel->texWidth, humanoidModel->texHeight,
(desired == playerModel64 ? "64" : "32"));
(desired == playerModel64 ? "64" : "32")); */
HumanoidMobRenderer::render(mob_, x, y, z, rot, a);
}

View File

@@ -21,6 +21,7 @@
#include "../raknet/RakPeerInterface.h"
#include "../raknet/PacketPriority.h"
#include "platform/log.h"
#include "util/Mth.h"
#include "world/item/ItemInstance.h"
#include "world/phys/Vec3.h"
#include "world/item/crafting/Recipe.h"
@@ -360,12 +361,22 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
//LOGI("MovePlayerPacket\n");
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);
float vectorDist = sqrt( (packet->x - entity->x) * (packet->x - entity->x) +
(packet->y - entity->y) * (packet->y - entity->y) +
(packet->z - entity->z) * (packet->z - entity->z));
float speed = vectorDist / (minecraft->getTicks() - player->lastMoveTicks);
// broadcast this packet to other clients
redistributePacket(packet, source);
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() {
bool allPlayersWasSleeping = allPlayersAreSleeping;
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;
if(!player->isSleeping()) {
if (!player->isSleeping()) {
allPlayersAreSleeping = false;
break;
}
}
if(!allPlayersWasSleeping && allPlayersAreSleeping) {
if (!allPlayersWasSleeping && allPlayersAreSleeping) {
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();
}
}
@@ -29,23 +32,26 @@ void ServerLevel::updateSleepingPlayerList() {
void ServerLevel::awakenAllPlayers() {
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;
if(player->isSleeping()) {
if (player->isSleeping()) {
player->stopSleepInBed(false, false, true);
player->health = Player::MAX_HEALTH;
player->lastHealth = Player::MAX_HEALTH;
}
}
SetHealthPacket packet(Player::MAX_HEALTH);
raknetInstance->send(packet);
}
bool ServerLevel::allPlayersSleeping() {
if(allPlayersAreSleeping && !isClientSide) {
if (allPlayersAreSleeping && !isClientSide) {
// all players are sleeping, but have they slept long enough?
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
if(!(*it)->isSleepingLongEnough()) {
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
if (!(*it)->isSleepingLongEnough()) {
return false;
}
}
@@ -55,13 +61,17 @@ bool ServerLevel::allPlayersSleeping() {
return false;
}
void ServerLevel::tick(){
void ServerLevel::tick() {
super::tick();
if(allPlayersSleeping()) {
if (allPlayersSleeping()) {
long newTime = levelData.getTime() + TICKS_PER_DAY;
levelData.setTime(newTime - (newTime % TICKS_PER_DAY));
SetTimePacket packet(levelData.getTime());
raknetInstance->send(packet);
awakenAllPlayers();
}
}

View File

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