Files
neoStudiosLCE-neoLegacy/Minecraft.World/RespawnPacket.cpp
Revela 8a6934c83c Implement persistent hardcore death bans (XUID + IP) for dedicated server
On the dedicated server, hardcore death now persists XUID and IP bans to
banned-players.json and banned-ips.json via the Access system, and
disconnects the player. Bans survive server restarts. Client-hosted games
retain the existing in-memory XUID ban with force-save behavior.

- Add hardcore property to server.properties (forces Hard difficulty)
- Add LevelData::setHardcore() so loaded worlds respect the server config
- Add PlayerList::banPlayerForHardcoreDeath() with persistent XUID + IP bans
- Reject respawn requests server-side in hardcore mode
- Ensure server-side player ticks run without move packets (fixes
  environmental damage not applying for some clients)
- Restore 0x8 hardcore bit on LoginPacket/RespawnPacket wire format so
  the client-side death screen detects hardcore mode correctly
2026-03-16 02:52:16 -05:00

102 lines
2.6 KiB
C++

#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "PacketListener.h"
#include "RespawnPacket.h"
#include "LevelType.h"
RespawnPacket::RespawnPacket()
{
this->dimension = 0;
this->difficulty = 1;
this->mapSeed = 0;
this->mapHeight = 0;
this->playerGameType = nullptr;
this->m_newSeaLevel = false;
m_pLevelType = nullptr;
m_newEntityId = 0;
m_xzSize = LEVEL_MAX_WIDTH;
m_hellScale = HELL_LEVEL_MAX_SCALE;
m_isHardcore = false;
}
RespawnPacket::RespawnPacket(char dimension, int64_t mapSeed, int mapHeight, GameType *playerGameType, char difficulty, LevelType *pLevelType, bool newSeaLevel, int newEntityId, int xzSize, int hellScale, bool isHardcore)
{
this->dimension = dimension;
this->mapSeed = mapSeed;
this->mapHeight = mapHeight;
this->playerGameType = playerGameType;
this->difficulty = difficulty;
this->m_newSeaLevel = newSeaLevel;
this->m_pLevelType=pLevelType;
this->m_newEntityId = newEntityId;
m_xzSize = xzSize;
m_hellScale = hellScale;
m_isHardcore = isHardcore;
app.DebugPrintf("RespawnPacket - Difficulty = %d\n",difficulty);
}
void RespawnPacket::handle(PacketListener *listener)
{
listener->handleRespawn(shared_from_this());
}
void RespawnPacket::read(DataInputStream *dis) //throws IOException
{
dimension = dis->readByte();
int rawGameType = dis->readByte();
m_isHardcore = (rawGameType & 0x8) != 0;
playerGameType = GameType::byId(rawGameType & ~0x8);
mapHeight = dis->readShort();
wstring typeName = readUtf(dis, 16);
m_pLevelType = LevelType::getLevelType(typeName);
if (m_pLevelType == nullptr)
{
m_pLevelType = LevelType::lvl_normal;
}
mapSeed = dis->readLong();
difficulty = dis->readByte();
m_newSeaLevel = dis->readBoolean();
m_newEntityId = dis->readShort();
#ifdef _LARGE_WORLDS
m_xzSize = dis->readShort();
m_hellScale = dis->read();
#endif
app.DebugPrintf("RespawnPacket::read - Difficulty = %d\n",difficulty);
}
void RespawnPacket::write(DataOutputStream *dos) //throws IOException
{
dos->writeByte(dimension);
dos->writeByte(m_isHardcore ? (playerGameType->getId() | 0x8) : playerGameType->getId());
dos->writeShort(mapHeight);
if (m_pLevelType == nullptr)
{
writeUtf(L"", dos);
}
else
{
writeUtf(m_pLevelType->getGeneratorName(), dos);
}
dos->writeLong(mapSeed);
dos->writeByte(difficulty);
dos->writeBoolean(m_newSeaLevel);
dos->writeShort(m_newEntityId);
#ifdef _LARGE_WORLDS
dos->writeShort(m_xzSize);
dos->write(m_hellScale);
#endif
}
int RespawnPacket::getEstimatedSize()
{
int length=0;
if (m_pLevelType != nullptr)
{
length = static_cast<int>(m_pLevelType->getGeneratorName().length());
}
return 13+length;
}