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
This commit is contained in:
@@ -1007,6 +1007,9 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
|
||||
#endif
|
||||
levels[i]->getLevelData()->setGameType(gameType);
|
||||
|
||||
// Apply hardcore flag from host option to level data so loaded worlds respect server.properties
|
||||
levels[i]->getLevelData()->setHardcore(isHardcore());
|
||||
|
||||
if(app.getLevelGenerationOptions() != nullptr)
|
||||
{
|
||||
LevelGenerationOptions *mapOptions = app.getLevelGenerationOptions();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "..\Minecraft.World\StringHelpers.h"
|
||||
#include "..\Minecraft.World\Socket.h"
|
||||
#include "..\Minecraft.World\Achievements.h"
|
||||
#include "..\Minecraft.World\LevelData.h"
|
||||
#include "..\Minecraft.World\net.minecraft.h"
|
||||
#include "EntityTracker.h"
|
||||
#include "ServerConnection.h"
|
||||
@@ -142,6 +143,14 @@ void PlayerConnection::tick()
|
||||
{
|
||||
dropSpamTickCount--;
|
||||
}
|
||||
|
||||
// Ensure server-side player tick runs even when no move packet was received this tick.
|
||||
// Without this, environmental damage (drowning, fire, lava) is never applied to clients
|
||||
// that don't send frequent move packets.
|
||||
if (!didTick && player != nullptr)
|
||||
{
|
||||
player->doTick(false);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerConnection::disconnect(DisconnectPacket::eDisconnectReason reason)
|
||||
@@ -1109,22 +1118,12 @@ void PlayerConnection::handleClientCommand(shared_ptr<ClientCommandPacket> packe
|
||||
{
|
||||
player = server->getPlayers()->respawn(player, player->m_enteredEndExitPortal?0:player->dimension, true);
|
||||
}
|
||||
//else if (player.getLevel().getLevelData().isHardcore())
|
||||
//{
|
||||
// if (server.isSingleplayer() && player.name.equals(server.getSingleplayerName()))
|
||||
// {
|
||||
// player.connection.disconnect("You have died. Game over, man, it's game over!");
|
||||
// server.selfDestruct();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// BanEntry ban = new BanEntry(player.name);
|
||||
// ban.setReason("Death in Hardcore");
|
||||
|
||||
// server.getPlayers().getBans().add(ban);
|
||||
// player.connection.disconnect("You have died. Game over, man, it's game over!");
|
||||
// }
|
||||
//}
|
||||
else if (player->level->getLevelData()->isHardcore())
|
||||
{
|
||||
// Hardcore mode — server rejects respawn. Ban and disconnect are already
|
||||
// handled in ServerPlayer::die() via banPlayerForHardcoreDeath().
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player->getHealth() > 0) return;
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
|
||||
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
||||
#include "..\Minecraft.Server\Access\Access.h"
|
||||
#include "..\Minecraft.Server\Common\StringUtils.h"
|
||||
#include "..\Minecraft.Server\ServerLogger.h"
|
||||
#include "..\Minecraft.Server\ServerLogManager.h"
|
||||
extern bool g_Win64DedicatedServer;
|
||||
#endif
|
||||
|
||||
@@ -1729,6 +1732,71 @@ void PlayerList::banXuid(PlayerUID xuid)
|
||||
LeaveCriticalSection(&m_banCS);
|
||||
}
|
||||
|
||||
void PlayerList::banPlayerForHardcoreDeath(ServerPlayer *player)
|
||||
{
|
||||
if (player == nullptr) return;
|
||||
|
||||
// Always apply the in-memory XUID ban (works for both client-hosted and dedicated)
|
||||
banXuid(player->getOnlineXuid());
|
||||
|
||||
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
||||
if (g_Win64DedicatedServer)
|
||||
{
|
||||
const std::string playerName = ServerRuntime::StringUtils::WideToUtf8(player->getName());
|
||||
|
||||
ServerRuntime::Access::BanMetadata metadata = ServerRuntime::Access::BanManager::BuildDefaultMetadata("Hardcore Death");
|
||||
metadata.reason = "Died in hardcore mode";
|
||||
|
||||
// Ban online XUID
|
||||
ServerRuntime::Access::AddPlayerBan(player->getOnlineXuid(), playerName, metadata);
|
||||
|
||||
// Also ban offline XUID if it differs (follows CliCommandBan pattern)
|
||||
PlayerUID offlineXuid = player->getXuid();
|
||||
if (offlineXuid != INVALID_XUID && offlineXuid != player->getOnlineXuid())
|
||||
{
|
||||
ServerRuntime::Access::AddPlayerBan(offlineXuid, playerName, metadata);
|
||||
}
|
||||
|
||||
// Ban the player's IP address (uses same access path as CliCommandBanIp)
|
||||
if (player->connection != nullptr && player->connection->connection != nullptr && player->connection->connection->getSocket() != nullptr)
|
||||
{
|
||||
const unsigned char smallId = player->connection->connection->getSocket()->getSmallId();
|
||||
std::string ip;
|
||||
if (smallId != 0 && ServerRuntime::ServerLogManager::TryGetConnectionRemoteIp(smallId, &ip))
|
||||
{
|
||||
ServerRuntime::Access::AddIpBan(ip, metadata);
|
||||
ServerRuntime::LogInfof("Hardcore", "Player %s banned (XUID + IP %s) for dying in hardcore mode.", playerName.c_str(), ip.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerRuntime::LogInfof("Hardcore", "Player %s banned (XUID only, IP not available) for dying in hardcore mode.", playerName.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerRuntime::LogInfof("Hardcore", "Player %s banned (XUID only, no connection) for dying in hardcore mode.", playerName.c_str());
|
||||
}
|
||||
|
||||
// Send ban reason then defer the actual close to the next tick, because this
|
||||
// method runs mid-tick inside ServerPlayer::die(). A synchronous disconnect
|
||||
// can invalidate the player/connection while the tick is still executing.
|
||||
if (player->connection != nullptr)
|
||||
{
|
||||
player->connection->send(std::make_shared<DisconnectPacket>(DisconnectPacket::eDisconnect_Banned));
|
||||
player->connection->closeOnTick();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// Client-hosted: force-save so the host cannot circumvent death by quitting without saving.
|
||||
// On dedicated server the autosave handles persistence, so skip the forced save to avoid
|
||||
// the client getting stuck on a "host is saving" screen during disconnect.
|
||||
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), eXuiServerAction_SaveGame);
|
||||
}
|
||||
}
|
||||
|
||||
// AP added for Vita so the range can be increased once the level starts
|
||||
void PlayerList::setViewDistance(int newViewDistance)
|
||||
{
|
||||
|
||||
@@ -137,6 +137,7 @@ public:
|
||||
void queueSmallIdForRecycle(BYTE smallId);
|
||||
bool isXuidBanned(PlayerUID xuid);
|
||||
void banXuid(PlayerUID xuid); // 4J Added - for hardcore mode ban-on-death
|
||||
void banPlayerForHardcoreDeath(ServerPlayer *player); // Persistent XUID + IP ban on hardcore death
|
||||
// AP added for Vita so the range can be increased once the level starts
|
||||
void setViewDistance(int newViewDistance);
|
||||
};
|
||||
|
||||
@@ -574,10 +574,10 @@ void ServerPlayer::die(DamageSource *source)
|
||||
{
|
||||
setGameMode(GameType::ADVENTURE);
|
||||
|
||||
// Ban this player's XUID and force-save so the host
|
||||
// cannot circumvent the death by quitting without saving.
|
||||
server->getPlayers()->banXuid(getOnlineXuid());
|
||||
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), eXuiServerAction_SaveGame);
|
||||
// Ban this player's XUID and queue disconnect.
|
||||
// The force-save is triggered inside banPlayerForHardcoreDeath after the
|
||||
// disconnect is queued, so the client doesn't get stuck on a save screen.
|
||||
server->getPlayers()->banPlayerForHardcoreDeath(this);
|
||||
}
|
||||
|
||||
if (!level->getGameRules()->getBoolean(GameRules::RULE_KEEPINVENTORY))
|
||||
|
||||
Reference in New Issue
Block a user