1
0

Anticheat fastbreak (#3411)

Added block hardness checks when breaking blocks.
This commit is contained in:
mohe2015 2016-11-06 19:30:19 +01:00 committed by Mattes D
parent 733401ec5f
commit 32b38fb264
20 changed files with 2701 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -215,10 +215,32 @@ enum BLOCKTYPE
E_BLOCK_JUNGLE_DOOR = 195,
E_BLOCK_ACACIA_DOOR = 196,
E_BLOCK_DARK_OAK_DOOR = 197,
E_BLOCK_END_ROD = 198,
E_BLOCK_CHORUS_PLANT = 199,
E_BLOCK_CHORUS_FLOWER = 200,
E_BLOCK_PURPUR_BLOCK = 201,
E_BLOCK_PURPUR_PILLAR = 202,
E_BLOCK_PURPUR_STAIRS = 203,
E_BLOCK_PURPUR_DOUBLE_SLAB = 204,
E_BLOCK_PURPUR_SLAB = 205,
E_BLOCK_END_BRICKS = 206,
E_BLOCK_BEETROOTS = 207,
E_BLOCK_GRASS_PATH = 208,
E_BLOCK_END_GATEWAY = 209,
E_BLOCK_REPEATING_COMMAND_BLOCK = 210,
E_BLOCK_CHAIN_COMMAND_BLOCK = 211,
E_BLOCK_FROSTED_ICE = 212,
E_BLOCK_MAGMA = 213,
E_BLOCK_NETHER_WART_BLOCK = 214,
E_BLOCK_RED_NETHER_BRICK = 215,
E_BLOCK_BONE_BLOCK = 216,
E_BLOCK_STRUCTURE_VOID = 217,
// ...
E_BLOCK_STRUCTURE_BLOCK = 255,
// Keep these two as the last values. Update the last block value when adding another block
// IsValidBlock() depends on this
E_BLOCK_NUMBER_OF_TYPES = E_BLOCK_DARK_OAK_DOOR + 1, ///< Number of individual (different) blocktypes
// Keep these two as the last values. Update the last block value to the last block with an id less than 255 when adding another block
// IsValidBlock() depends on this (255 gets checked additionally because there is a gap. See http://minecraft.gamepedia.com/Data_values#Block_IDs
E_BLOCK_NUMBER_OF_TYPES = E_BLOCK_STRUCTURE_VOID + 1, ///< Number of individual (different) blocktypes
E_BLOCK_MAX_TYPE_ID = E_BLOCK_NUMBER_OF_TYPES - 1, ///< Maximum BlockType number used
// Synonym or ID compatibility

View File

@ -802,6 +802,205 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info)
a_Info[E_BLOCK_JUNGLE_DOOR ].m_PlaceSound = "dig.wood";
a_Info[E_BLOCK_ACACIA_DOOR ].m_PlaceSound = "dig.wood";
a_Info[E_BLOCK_DARK_OAK_DOOR ].m_PlaceSound = "dig.wood";
a_Info[E_BLOCK_AIR ].m_Hardness = 0.0f;
a_Info[E_BLOCK_STONE ].m_Hardness = 1.5f;
a_Info[E_BLOCK_GRASS ].m_Hardness = 0.6f;
a_Info[E_BLOCK_DIRT ].m_Hardness = 0.5f;
a_Info[E_BLOCK_COBBLESTONE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_PLANKS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_SAPLING ].m_Hardness = 0.0f;
a_Info[E_BLOCK_BEDROCK ].m_Hardness = -1.0f;
a_Info[E_BLOCK_WATER ].m_Hardness = 100.0f;
a_Info[E_BLOCK_STATIONARY_WATER ].m_Hardness = 100.0f;
a_Info[E_BLOCK_LAVA ].m_Hardness = 100.0f;
a_Info[E_BLOCK_STATIONARY_LAVA ].m_Hardness = 100.0f;
a_Info[E_BLOCK_SAND ].m_Hardness = 0.5f;
a_Info[E_BLOCK_GRAVEL ].m_Hardness = 0.6f;
a_Info[E_BLOCK_GOLD_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_IRON_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_COAL_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_LOG ].m_Hardness = 2.0f;
a_Info[E_BLOCK_LEAVES ].m_Hardness = 0.2f;
a_Info[E_BLOCK_SPONGE ].m_Hardness = 0.6f;
a_Info[E_BLOCK_GLASS ].m_Hardness = 0.3f;
a_Info[E_BLOCK_LAPIS_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_LAPIS_BLOCK ].m_Hardness = 3.0f;
a_Info[E_BLOCK_DISPENSER ].m_Hardness = 3.5f;
a_Info[E_BLOCK_SANDSTONE ].m_Hardness = 0.8f;
a_Info[E_BLOCK_NOTE_BLOCK ].m_Hardness = 0.8f;
a_Info[E_BLOCK_BED ].m_Hardness = 0.2f;
a_Info[E_BLOCK_POWERED_RAIL ].m_Hardness = 0.7f;
a_Info[E_BLOCK_DETECTOR_RAIL ].m_Hardness = 0.7f;
a_Info[E_BLOCK_STICKY_PISTON ].m_Hardness = 0.5f;
a_Info[E_BLOCK_COBWEB ].m_Hardness = 4.0f;
a_Info[E_BLOCK_TALL_GRASS ].m_Hardness = 0.0f;
a_Info[E_BLOCK_DEAD_BUSH ].m_Hardness = 0.0f;
a_Info[E_BLOCK_PISTON ].m_Hardness = 0.5f;
a_Info[E_BLOCK_PISTON_EXTENSION ].m_Hardness = 0.5f;
a_Info[E_BLOCK_WOOL ].m_Hardness = 0.8f;
a_Info[E_BLOCK_PISTON_MOVED_BLOCK ].m_Hardness = -1.0f;
a_Info[E_BLOCK_DANDELION ].m_Hardness = 0.0f;
a_Info[E_BLOCK_FLOWER ].m_Hardness = 0.0f;
a_Info[E_BLOCK_BROWN_MUSHROOM ].m_Hardness = 0.0f;
a_Info[E_BLOCK_RED_MUSHROOM ].m_Hardness = 0.0f;
a_Info[E_BLOCK_GOLD_BLOCK ].m_Hardness = 3.0f;
a_Info[E_BLOCK_IRON_BLOCK ].m_Hardness = 5.0f;
a_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_Hardness = 2.0f;
a_Info[E_BLOCK_STONE_SLAB ].m_Hardness = 2.0f;
a_Info[E_BLOCK_BRICK ].m_Hardness = 2.0f;
a_Info[E_BLOCK_TNT ].m_Hardness = 0.0f;
a_Info[E_BLOCK_BOOKCASE ].m_Hardness = 1.5f;
a_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_OBSIDIAN ].m_Hardness = 50.0f;
a_Info[E_BLOCK_TORCH ].m_Hardness = 0.0f;
a_Info[E_BLOCK_FIRE ].m_Hardness = 0.0f;
a_Info[E_BLOCK_MOB_SPAWNER ].m_Hardness = 5.0f;
a_Info[E_BLOCK_OAK_WOOD_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_CHEST ].m_Hardness = 2.5f;
a_Info[E_BLOCK_REDSTONE_WIRE ].m_Hardness = 0.0f;
a_Info[E_BLOCK_DIAMOND_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_DIAMOND_BLOCK ].m_Hardness = 5.0f;
a_Info[E_BLOCK_CRAFTING_TABLE ].m_Hardness = 2.5f;
a_Info[E_BLOCK_CROPS ].m_Hardness = 0.0f;
a_Info[E_BLOCK_FARMLAND ].m_Hardness = 0.6f;
a_Info[E_BLOCK_FURNACE ].m_Hardness = 3.5f;
a_Info[E_BLOCK_LIT_FURNACE ].m_Hardness = 3.5f;
a_Info[E_BLOCK_SIGN_POST ].m_Hardness = 1.0f;
a_Info[E_BLOCK_OAK_DOOR ].m_Hardness = 3.0f;
a_Info[E_BLOCK_LADDER ].m_Hardness = 0.4f;
a_Info[E_BLOCK_RAIL ].m_Hardness = 0.7f;
a_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_WALLSIGN ].m_Hardness = 1.0f;
a_Info[E_BLOCK_LEVER ].m_Hardness = 0.5f;
a_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_Hardness = 0.5f;
a_Info[E_BLOCK_IRON_DOOR ].m_Hardness = 5.0f;
a_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_Hardness = 0.5f;
a_Info[E_BLOCK_REDSTONE_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_Hardness = 0.625f;
a_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_Hardness = 0.0f;
a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_Hardness = 0.0f;
a_Info[E_BLOCK_STONE_BUTTON ].m_Hardness = 0.5f;
a_Info[E_BLOCK_SNOW ].m_Hardness = 0.1f;
a_Info[E_BLOCK_ICE ].m_Hardness = 0.5f;
a_Info[E_BLOCK_SNOW_BLOCK ].m_Hardness = 0.2f;
a_Info[E_BLOCK_CACTUS ].m_Hardness = 0.4f;
a_Info[E_BLOCK_CLAY ].m_Hardness = 0.6f;
a_Info[E_BLOCK_SUGARCANE ].m_Hardness = 0.0f;
a_Info[E_BLOCK_JUKEBOX ].m_Hardness = 2.0f;
a_Info[E_BLOCK_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_PUMPKIN ].m_Hardness = 1.0f;
a_Info[E_BLOCK_NETHERRACK ].m_Hardness = 0.4f;
a_Info[E_BLOCK_SOULSAND ].m_Hardness = 0.5f;
a_Info[E_BLOCK_GLOWSTONE ].m_Hardness = 0.3f;
a_Info[E_BLOCK_NETHER_PORTAL ].m_Hardness = -1.0f;
a_Info[E_BLOCK_JACK_O_LANTERN ].m_Hardness = 1.0f;
a_Info[E_BLOCK_CAKE ].m_Hardness = 0.5f;
a_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_Hardness = 0.0f;
a_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_Hardness = 0.0f;
a_Info[E_BLOCK_STAINED_GLASS ].m_Hardness = 0.3f;
a_Info[E_BLOCK_TRAPDOOR ].m_Hardness = 3.0f;
a_Info[E_BLOCK_SILVERFISH_EGG ].m_Hardness = 0.75f;
a_Info[E_BLOCK_STONE_BRICKS ].m_Hardness = 1.5f;
a_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_Hardness = 0.2f;
a_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_Hardness = 0.2f;
a_Info[E_BLOCK_IRON_BARS ].m_Hardness = 5.0f;
a_Info[E_BLOCK_GLASS_PANE ].m_Hardness = 0.3f;
a_Info[E_BLOCK_MELON ].m_Hardness = 1.0f;
a_Info[E_BLOCK_PUMPKIN_STEM ].m_Hardness = 0.0f;
a_Info[E_BLOCK_MELON_STEM ].m_Hardness = 0.0f;
a_Info[E_BLOCK_VINES ].m_Hardness = 0.2f;
a_Info[E_BLOCK_OAK_FENCE_GATE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_BRICK_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_STONE_BRICK_STAIRS ].m_Hardness = 1.5f;
a_Info[E_BLOCK_MYCELIUM ].m_Hardness = 0.6f;
a_Info[E_BLOCK_LILY_PAD ].m_Hardness = 0.0f;
a_Info[E_BLOCK_NETHER_BRICK ].m_Hardness = 2.0f;
a_Info[E_BLOCK_NETHER_BRICK_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_NETHER_BRICK_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_NETHER_WART ].m_Hardness = 0.0f;
a_Info[E_BLOCK_ENCHANTMENT_TABLE ].m_Hardness = 5.0f;
a_Info[E_BLOCK_BREWING_STAND ].m_Hardness = 0.5f;
a_Info[E_BLOCK_CAULDRON ].m_Hardness = 2.0f;
a_Info[E_BLOCK_END_PORTAL ].m_Hardness = -1.0f;
a_Info[E_BLOCK_END_PORTAL_FRAME ].m_Hardness = -1.0f;
a_Info[E_BLOCK_END_STONE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_DRAGON_EGG ].m_Hardness = 3.0f;
a_Info[E_BLOCK_REDSTONE_LAMP_OFF ].m_Hardness = 0.3f;
a_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_Hardness = 0.3f;
a_Info[E_BLOCK_DOUBLE_WOODEN_SLAB ].m_Hardness = 2.0f;
a_Info[E_BLOCK_WOODEN_SLAB ].m_Hardness = 2.0f;
a_Info[E_BLOCK_COCOA_POD ].m_Hardness = 0.2f;
a_Info[E_BLOCK_SANDSTONE_STAIRS ].m_Hardness = 0.8f;
a_Info[E_BLOCK_EMERALD_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_ENDER_CHEST ].m_Hardness = 22.5f;
a_Info[E_BLOCK_TRIPWIRE_HOOK ].m_Hardness = 0.0f;
a_Info[E_BLOCK_TRIPWIRE ].m_Hardness = 0.0f;
a_Info[E_BLOCK_EMERALD_BLOCK ].m_Hardness = 5.0f;
a_Info[E_BLOCK_SPRUCE_WOOD_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_BIRCH_WOOD_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_JUNGLE_WOOD_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_COMMAND_BLOCK ].m_Hardness = -1.0f;
a_Info[E_BLOCK_BEACON ].m_Hardness = 3.0f;
a_Info[E_BLOCK_COBBLESTONE_WALL ].m_Hardness = 2.0f;
a_Info[E_BLOCK_FLOWER_POT ].m_Hardness = 0.0f;
a_Info[E_BLOCK_CARROTS ].m_Hardness = 0.0f;
a_Info[E_BLOCK_POTATOES ].m_Hardness = 0.0f;
a_Info[E_BLOCK_WOODEN_BUTTON ].m_Hardness = 0.5f;
a_Info[E_BLOCK_HEAD ].m_Hardness = 1.0f;
a_Info[E_BLOCK_ANVIL ].m_Hardness = 5.0f;
a_Info[E_BLOCK_TRAPPED_CHEST ].m_Hardness = 2.5f;
a_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_Hardness = 0.5f;
a_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Hardness = 0.5f;
a_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_Hardness = 0.0f;
a_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_Hardness = 0.0f;
a_Info[E_BLOCK_DAYLIGHT_SENSOR ].m_Hardness = 0.2f;
a_Info[E_BLOCK_BLOCK_OF_REDSTONE ].m_Hardness = 5.0f;
a_Info[E_BLOCK_NETHER_QUARTZ_ORE ].m_Hardness = 3.0f;
a_Info[E_BLOCK_HOPPER ].m_Hardness = 3.0f;
a_Info[E_BLOCK_QUARTZ_BLOCK ].m_Hardness = 0.8f;
a_Info[E_BLOCK_QUARTZ_STAIRS ].m_Hardness = 0.8f;
a_Info[E_BLOCK_ACTIVATOR_RAIL ].m_Hardness = 0.7f;
a_Info[E_BLOCK_DROPPER ].m_Hardness = 3.5f;
a_Info[E_BLOCK_STAINED_CLAY ].m_Hardness = 1.25f;
a_Info[E_BLOCK_STAINED_GLASS_PANE ].m_Hardness = 0.3f;
a_Info[E_BLOCK_NEW_LEAVES ].m_Hardness = 0.2f;
a_Info[E_BLOCK_NEW_LOG ].m_Hardness = 2.0f;
a_Info[E_BLOCK_ACACIA_WOOD_STAIRS ].m_Hardness = 2.0f;
a_Info[E_BLOCK_DARK_OAK_WOOD_STAIRS].m_Hardness = 2.0f;
a_Info[E_BLOCK_SLIME_BLOCK ].m_Hardness = 0.0f;
a_Info[E_BLOCK_BARRIER ].m_Hardness = -1.0f;
a_Info[E_BLOCK_IRON_TRAPDOOR ].m_Hardness = 5.0f;
a_Info[E_BLOCK_PRISMARINE_BLOCK ].m_Hardness = 1.5f;
a_Info[E_BLOCK_SEA_LANTERN ].m_Hardness = 0.3f;
a_Info[E_BLOCK_HAY_BALE ].m_Hardness = 0.5f;
a_Info[E_BLOCK_CARPET ].m_Hardness = 0.1f;
a_Info[E_BLOCK_HARDENED_CLAY ].m_Hardness = 1.25f;
a_Info[E_BLOCK_BLOCK_OF_COAL ].m_Hardness = 5.0f;
a_Info[E_BLOCK_PACKED_ICE ].m_Hardness = 0.5f;
a_Info[E_BLOCK_BIG_FLOWER ].m_Hardness = 0.0f;
a_Info[E_BLOCK_STANDING_BANNER ].m_Hardness = 1.0f;
a_Info[E_BLOCK_WALL_BANNER ].m_Hardness = 1.0f;
a_Info[E_BLOCK_INVERTED_DAYLIGHT_SENSOR].m_Hardness = 0.2f;
a_Info[E_BLOCK_RED_SANDSTONE ].m_Hardness = 0.8f;
a_Info[E_BLOCK_RED_SANDSTONE_STAIRS].m_Hardness = 0.8f;
a_Info[E_BLOCK_DOUBLE_RED_SANDSTONE_SLAB].m_Hardness = 2.0f;
a_Info[E_BLOCK_RED_SANDSTONE_SLAB ].m_Hardness = 2.0f;
a_Info[E_BLOCK_SPRUCE_FENCE_GATE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_BIRCH_FENCE_GATE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_JUNGLE_FENCE_GATE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_DARK_OAK_FENCE_GATE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_ACACIA_FENCE_GATE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_SPRUCE_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_BIRCH_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_JUNGLE_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_DARK_OAK_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_ACACIA_FENCE ].m_Hardness = 2.0f;
a_Info[E_BLOCK_SPRUCE_DOOR ].m_Hardness = 3.0f;
a_Info[E_BLOCK_BIRCH_DOOR ].m_Hardness = 3.0f;
a_Info[E_BLOCK_JUNGLE_DOOR ].m_Hardness = 3.0f;
a_Info[E_BLOCK_ACACIA_DOOR ].m_Hardness = 3.0f;
a_Info[E_BLOCK_DARK_OAK_DOOR ].m_Hardness = 3.0f;
}

View File

@ -70,6 +70,9 @@ public:
/** Sound when placing this block */
AString m_PlaceSound;
/** Block's hardness. The greater the value the longer the player needs to break the block. */
float m_Hardness;
// tolua_end
/** Associated block handler. */
@ -89,6 +92,7 @@ public:
inline static bool CanBeTerraformed (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed; }
inline static float GetBlockHeight (BLOCKTYPE a_Type) { return Get(a_Type).m_BlockHeight; }
inline static AString GetPlaceSound (BLOCKTYPE a_Type) { return Get(a_Type).m_PlaceSound; }
inline static float GetHardness (BLOCKTYPE a_Type) { return Get(a_Type).m_Hardness; }
// tolua_end
@ -112,6 +116,7 @@ protected:
, m_CanBeTerraformed(false)
, m_BlockHeight(1.0)
, m_PlaceSound("")
, m_Hardness(0.0f)
, m_Handler(nullptr)
{}

View File

@ -56,6 +56,7 @@ static const std::chrono::milliseconds PING_TIME_MS = std::chrono::milliseconds(
int cClientHandle::s_ClientCount = 0;
float cClientHandle::FASTBREAK_PERCENTAGE;
@ -1187,6 +1188,8 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
return;
}
m_BreakProgress = 0;
// Start dig animation
// TODO: calculate real animation speed
// TODO: Send animation packets even without receiving any other packets
@ -1243,6 +1246,22 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
}
}
if (!m_Player->IsGameModeCreative() && !cBlockInfo::IsOneHitDig(a_OldBlock))
{
// Fix for very fast tools.
m_BreakProgress += m_Player->GetPlayerRelativeBlockHardness(a_OldBlock);
if (m_BreakProgress < FASTBREAK_PERCENTAGE)
{
LOGD("Break progress of player %s was less than expected: %f < %f\n", m_Player->GetName().c_str(), m_BreakProgress * 100, FASTBREAK_PERCENTAGE * 100);
// AntiFastBreak doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows:
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // Strange bug with doors
SendPlayerPosition(); // Prevents the player from falling through the block that was temporarily broken client side.
m_Player->SendMessage("FastBreak?"); // TODO Anticheat hook
return;
}
}
cWorld * World = m_Player->GetWorld();
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
@ -1250,6 +1269,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
{
// A plugin doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows:
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // Strange bug with doors
SendPlayerPosition(); // Prevents the player from falling through the block that was temporarily broken client side.
return;
}
@ -1980,6 +2000,13 @@ bool cClientHandle::CheckBlockInteractionsRate(void)
void cClientHandle::Tick(float a_Dt)
{
// anticheat fastbreak
if (m_HasStartedDigging)
{
BLOCKTYPE Block = m_Player->GetWorld()->GetBlock(m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ);
m_BreakProgress += m_Player->GetPlayerRelativeBlockHardness(Block);
}
// Process received network data:
AString IncomingData;
{

View File

@ -63,6 +63,11 @@ public: // tolua_export
static const int MAX_VIEW_DISTANCE = 32;
static const int MIN_VIEW_DISTANCE = 1;
/** The percentage how much a block has to be broken.
Should be a value between 0.7 (70% broken) and 1 (100% broken) depending on lag.
Can be set in settings.ini [AntiCheat] FastBreakPercentage=(from 0 to 100) */
static float FASTBREAK_PERCENTAGE;
/** Creates a new client with the specified IP address in its description and the specified initial view distance. */
cClientHandle(const AString & a_IPString, int a_ViewDistance);
@ -519,6 +524,7 @@ private:
/** Shared pointer to self, so that this instance can keep itself alive when needed. */
cClientHandlePtr m_Self;
float m_BreakProgress;
/** Returns true if the rate block interactions is within a reasonable limit (bot protection) */
bool CheckBlockInteractionsRate(void);

View File

@ -370,8 +370,11 @@ inline AString BlockFaceToString(eBlockFace a_BlockFace)
inline bool IsValidBlock(int a_BlockType)
{
if (
(
(a_BlockType > -1) &&
(a_BlockType <= E_BLOCK_MAX_TYPE_ID)
) ||
(a_BlockType == 255) // the blocks 235-254 don't exist yet -> http://minecraft.gamepedia.com/Data_values#Block_IDs
)
{
return true;
@ -509,6 +512,304 @@ inline bool IsBlockFence(BLOCKTYPE a_BlockType)
inline bool IsBlockMaterialWood(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)
{
case E_BLOCK_PLANKS:
case E_BLOCK_LOG:
case E_BLOCK_NOTE_BLOCK:
case E_BLOCK_BOOKCASE:
case E_BLOCK_OAK_WOOD_STAIRS:
case E_BLOCK_CHEST:
case E_BLOCK_CRAFTING_TABLE:
case E_BLOCK_SIGN_POST:
case E_BLOCK_OAK_DOOR:
case E_BLOCK_WALLSIGN:
case E_BLOCK_WOODEN_PRESSURE_PLATE:
case E_BLOCK_JUKEBOX:
case E_BLOCK_FENCE:
case E_BLOCK_TRAPDOOR:
case E_BLOCK_HUGE_BROWN_MUSHROOM:
case E_BLOCK_HUGE_RED_MUSHROOM:
case E_BLOCK_OAK_FENCE_GATE:
case E_BLOCK_DOUBLE_WOODEN_SLAB:
case E_BLOCK_WOODEN_SLAB:
case E_BLOCK_SPRUCE_WOOD_STAIRS:
case E_BLOCK_BIRCH_WOOD_STAIRS:
case E_BLOCK_JUNGLE_WOOD_STAIRS:
case E_BLOCK_TRAPPED_CHEST:
case E_BLOCK_DAYLIGHT_SENSOR:
case E_BLOCK_NEW_LOG:
case E_BLOCK_ACACIA_WOOD_STAIRS:
case E_BLOCK_DARK_OAK_WOOD_STAIRS:
case E_BLOCK_STANDING_BANNER:
case E_BLOCK_WALL_BANNER:
case E_BLOCK_INVERTED_DAYLIGHT_SENSOR:
case E_BLOCK_SPRUCE_FENCE_GATE:
case E_BLOCK_BIRCH_FENCE_GATE:
case E_BLOCK_JUNGLE_FENCE_GATE:
case E_BLOCK_DARK_OAK_FENCE_GATE:
case E_BLOCK_ACACIA_FENCE_GATE:
case E_BLOCK_SPRUCE_FENCE:
case E_BLOCK_BIRCH_FENCE:
case E_BLOCK_JUNGLE_FENCE:
case E_BLOCK_DARK_OAK_FENCE:
case E_BLOCK_ACACIA_FENCE:
case E_BLOCK_SPRUCE_DOOR:
case E_BLOCK_BIRCH_DOOR:
case E_BLOCK_JUNGLE_DOOR:
case E_BLOCK_ACACIA_DOOR:
case E_BLOCK_DARK_OAK_DOOR:
{
return true;
}
default:
{
return false;
}
}
}
inline bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)
{
case E_BLOCK_SAPLING:
case E_BLOCK_DANDELION:
case E_BLOCK_FLOWER:
case E_BLOCK_BROWN_MUSHROOM:
case E_BLOCK_RED_MUSHROOM:
case E_BLOCK_CROPS:
case E_BLOCK_REEDS:
case E_BLOCK_PUMPKIN_STEM:
case E_BLOCK_MELON_STEM:
case E_BLOCK_LILY_PAD:
case E_BLOCK_NETHER_WART:
case E_BLOCK_COCOA_POD:
case E_BLOCK_CARROTS:
case E_BLOCK_POTATOES:
case E_BLOCK_CHORUS_PLANT:
case E_BLOCK_CHORUS_FLOWER:
case E_BLOCK_BEETROOTS:
{
return true;
}
default:
{
return false;
}
}
}
inline bool IsBlockMaterialVine(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)
{
case E_BLOCK_TALL_GRASS:
case E_BLOCK_DEAD_BUSH:
case E_BLOCK_VINES:
case E_BLOCK_BIG_FLOWER:
{
return true;
}
default:
{
return false;
}
}
}
inline bool IsBlockMaterialIron(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)
{
case E_BLOCK_LAPIS_BLOCK:
case E_BLOCK_GOLD_BLOCK:
case E_BLOCK_IRON_BLOCK:
case E_BLOCK_DIAMOND_BLOCK:
case E_BLOCK_IRON_DOOR:
case E_BLOCK_IRON_BARS:
case E_BLOCK_BREWING_STAND:
case E_BLOCK_CAULDRON:
case E_BLOCK_EMERALD_BLOCK:
case E_BLOCK_COMMAND_BLOCK:
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE:
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
case E_BLOCK_BLOCK_OF_REDSTONE:
case E_BLOCK_HOPPER:
case E_BLOCK_IRON_TRAPDOOR:
case E_BLOCK_REPEATING_COMMAND_BLOCK:
case E_BLOCK_CHAIN_COMMAND_BLOCK:
case E_BLOCK_STRUCTURE_BLOCK:
{
return true;
}
default:
{
return false;
}
}
}
inline bool IsBlockMaterialAnvil(BLOCKTYPE a_BlockType)
{
return (a_BlockType == E_BLOCK_ANVIL);
}
inline bool IsBlocksWeb(BLOCKTYPE a_BlockType)
{
return (a_BlockType == E_BLOCK_COBWEB);
}
inline bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType)
{
return (a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES);
}
inline bool IsBlocksWool(BLOCKTYPE a_BlockType)
{
return (a_BlockType == E_BLOCK_WOOL);
}
inline bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)
{
case E_BLOCK_PUMPKIN:
case E_BLOCK_JACK_O_LANTERN:
case E_BLOCK_MELON:
{
return true;
}
default:
{
return false;
}
}
}
inline bool IsBlockMaterialCoral(BLOCKTYPE a_BlockType)
{
return false; // yes, there is no block in minecraft which belongs to this type.
}
inline bool IsBlockMaterialRock(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)
{
case E_BLOCK_STONE:
case E_BLOCK_COBBLESTONE:
case E_BLOCK_BEDROCK:
case E_BLOCK_GOLD_ORE:
case E_BLOCK_IRON_ORE:
case E_BLOCK_COAL_ORE:
case E_BLOCK_LAPIS_ORE:
case E_BLOCK_DISPENSER:
case E_BLOCK_SANDSTONE:
case E_BLOCK_DOUBLE_STONE_SLAB:
case E_BLOCK_STONE_SLAB:
case E_BLOCK_BRICK:
case E_BLOCK_MOSSY_COBBLESTONE:
case E_BLOCK_OBSIDIAN:
case E_BLOCK_MOB_SPAWNER:
case E_BLOCK_DIAMOND_ORE:
case E_BLOCK_FURNACE:
case E_BLOCK_LIT_FURNACE:
case E_BLOCK_COBBLESTONE_STAIRS:
case E_BLOCK_STONE_PRESSURE_PLATE:
case E_BLOCK_REDSTONE_ORE:
case E_BLOCK_REDSTONE_ORE_GLOWING:
case E_BLOCK_NETHERRACK:
case E_BLOCK_STONE_BRICKS:
case E_BLOCK_BRICK_STAIRS:
case E_BLOCK_STONE_BRICK_STAIRS:
case E_BLOCK_NETHER_BRICK:
case E_BLOCK_NETHER_BRICK_FENCE:
case E_BLOCK_NETHER_BRICK_STAIRS:
case E_BLOCK_ENCHANTMENT_TABLE:
case E_BLOCK_END_PORTAL_FRAME:
case E_BLOCK_END_STONE:
case E_BLOCK_SANDSTONE_STAIRS:
case E_BLOCK_EMERALD_ORE:
case E_BLOCK_ENDER_CHEST:
case E_BLOCK_COBBLESTONE_WALL:
case E_BLOCK_NETHER_QUARTZ_ORE:
case E_BLOCK_QUARTZ_BLOCK:
case E_BLOCK_QUARTZ_STAIRS:
case E_BLOCK_DROPPER:
case E_BLOCK_STAINED_CLAY:
case E_BLOCK_PRISMARINE_BLOCK:
case E_BLOCK_HARDENED_CLAY:
case E_BLOCK_BLOCK_OF_COAL:
case E_BLOCK_RED_SANDSTONE:
case E_BLOCK_RED_SANDSTONE_STAIRS:
case E_BLOCK_DOUBLE_RED_SANDSTONE_SLAB:
case E_BLOCK_RED_SANDSTONE_SLAB:
case E_BLOCK_PURPUR_BLOCK:
case E_BLOCK_PURPUR_PILLAR:
case E_BLOCK_PURPUR_STAIRS:
case E_BLOCK_PURPUR_DOUBLE_SLAB:
case E_BLOCK_PURPUR_SLAB:
case E_BLOCK_END_BRICKS:
case E_BLOCK_MAGMA:
case E_BLOCK_RED_NETHER_BRICK:
case E_BLOCK_BONE_BLOCK:
{
return true;
}
default:
{
return false;
}
}
}
inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse = false) // tolua_export
{ // tolua_export
if (!a_bInverse)

View File

@ -441,3 +441,24 @@ void cPawn::StopEveryoneFromTargetingMe()
}
ASSERT(m_TargetingMe.size() == 0);
}
std::map<cEntityEffect::eType, cEntityEffect *> cPawn::GetEntityEffects()
{
return m_EntityEffects;
}
cEntityEffect *cPawn::GetEntityEffect(cEntityEffect::eType a_EffectType)
{
return m_EntityEffects.at(a_EffectType);
}

View File

@ -63,6 +63,12 @@ public:
/** Add the monster to the list of monsters targeting this pawn. (Does not check if already in list!) */
void TargetingMe(cMonster * a_Monster);
/** Returns all entity effects */
std::map<cEntityEffect::eType, cEntityEffect *> GetEntityEffects();
/** Returns the entity effect, if it is currently applied. */
cEntityEffect *GetEntityEffect(cEntityEffect::eType a_EffectType);
protected:
typedef std::map<cEntityEffect::eType, cEntityEffect *> tEffectMap;
tEffectMap m_EntityEffects;

View File

@ -2636,3 +2636,95 @@ void cPlayer::FreezeInternal(const Vector3d & a_Location, bool a_ManuallyFrozen)
m_FlyingMaxSpeed = FlyingMaxpeed;
m_IsFlying = IsFlying;
}
float cPlayer::GetLiquidHeightPercent(NIBBLETYPE a_Meta)
{
if (a_Meta >= 8)
{
a_Meta = 0;
}
return static_cast<float>(a_Meta + 1) / 9.0f;
}
bool cPlayer::IsInsideWater()
{
BLOCKTYPE Block = m_World->GetBlock(FloorC(GetPosX()), FloorC(m_Stance), FloorC(GetPosZ()));
if ((Block != E_BLOCK_WATER) && (Block != E_BLOCK_STATIONARY_WATER))
{
return false;
}
NIBBLETYPE Meta = GetWorld()->GetBlockMeta(FloorC(GetPosX()), FloorC(m_Stance), FloorC(GetPosZ()));
float f = GetLiquidHeightPercent(Meta) - 0.11111111f;
float f1 = static_cast<float>(m_Stance + 1) - f;
bool flag = (m_Stance < f1);
return flag;
}
float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
{
float f = GetEquippedItem().GetHandler()->GetBlockBreakingStrength(a_Block);
if (f > 1.0f)
{
unsigned int efficiencyModifier = GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchEfficiency);
if (efficiencyModifier > 0)
{
f += (efficiencyModifier * efficiencyModifier) + 1;
}
}
if (HasEntityEffect(cEntityEffect::effHaste))
{
int intensity = GetEntityEffect(cEntityEffect::effHaste)->GetIntensity() + 1;
f *= 1.0f + (intensity * 0.2f);
}
if (HasEntityEffect(cEntityEffect::effMiningFatigue))
{
int intensity = GetEntityEffect(cEntityEffect::effMiningFatigue)->GetIntensity();
switch (intensity)
{
case 0: f *= 0.3f; break;
case 1: f *= 0.09f; break;
case 2: f *= 0.0027f; break;
default: f *= 0.00081f; break;
}
}
if (IsInsideWater() && !(GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchAquaAffinity) > 0))
{
f /= 5.0f;
}
if (!IsOnGround())
{
f /= 5.0f;
}
return f;
}
float cPlayer::GetPlayerRelativeBlockHardness(BLOCKTYPE a_Block)
{
float blockHardness = cBlockInfo::GetHardness(a_Block);
float digSpeed = GetDigSpeed(a_Block);
float canHarvestBlockDivisor = GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block) ? 30.0f : 100.0f;
// LOGD("blockHardness: %f, digSpeed: %f, canHarvestBlockDivisor: %f\n", blockHardness, digSpeed, canHarvestBlockDivisor);
return (blockHardness < 0) ? 0 : ((digSpeed / blockHardness) / canHarvestBlockDivisor);
}

View File

@ -529,6 +529,12 @@ public:
The player removes its m_ClientHandle ownership so that the ClientHandle gets deleted. */
void RemoveClientHandle(void);
/** Returns the relative block hardness for the block a_Block.
The bigger it is the faster the player can break the block.
Returns zero if the block is instant breakable.
Otherwise it returns the dig speed (float GetDigSpeed(BLOCKTYPE a_Block)) divided by the block hardness (cBlockInfo::GetHardness(BLOCKTYPE a_Block)) divided by 30 if the player can harvest the block and divided by 100 if he can't. */
float GetPlayerRelativeBlockHardness(BLOCKTYPE a_Block);
protected:
typedef std::vector<std::vector<AString> > AStringVectorVector;
@ -710,4 +716,19 @@ private:
/** Pins the player to a_Location until Unfreeze() is called.
If ManuallyFrozen is false, the player will unfreeze when the chunk is loaded. */
void FreezeInternal(const Vector3d & a_Location, bool a_ManuallyFrozen);
/** Returns how high the liquid is in percent. Used by IsInsideWater */
float GetLiquidHeightPercent(NIBBLETYPE a_Meta);
/** Checks if the player is inside of water */
bool IsInsideWater();
/** Returns the dig speed using the current tool on the block a_Block.
Returns one if using hand.
If the player is using a tool that is good to break the block the value is higher.
If he has an enchanted tool with efficiency or he has a haste or mining fatique effect it gets multiplied by a specific factor depending on the strength of the effect or enchantment.
In he is in water it gets divided by 5 except his tool is enchanted with aqa affinity.
If he is not on ground it also gets divided by 5. */
float GetDigSpeed(BLOCKTYPE a_Block);
} ; // tolua_export

View File

@ -55,6 +55,7 @@ SET (HDRS
ItemSugarcane.h
ItemSword.h
ItemThrowable.h
ItemAxe.h
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

48
src/Items/ItemAxe.h Normal file
View File

@ -0,0 +1,48 @@
#pragma once
#include "ItemHandler.h"
#include "../World.h"
#include "../Entities/Player.h"
class cItemAxeHandler :
public cItemHandler
{
typedef cItemHandler super;
public:
cItemAxeHandler(int a_ItemType)
: cItemHandler(a_ItemType)
{
}
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
{
if (!IsBlockMaterialWood(a_Block) && !IsBlockMaterialPlants(a_Block) && !IsBlockMaterialVine(a_Block))
{
return super::GetBlockBreakingStrength(a_Block);
}
else
{
switch (m_ItemType)
{
case E_ITEM_WOODEN_AXE: return 2.0f;
case E_ITEM_STONE_AXE: return 4.0f;
case E_ITEM_IRON_AXE: return 6.0f;
case E_ITEM_GOLD_AXE: return 12.0f;
case E_ITEM_DIAMOND_AXE: return 8.0f;
}
}
ASSERT(!"Something is wrong here... Maybe they are axes out of a new material?");
return 1.0f;
}
} ;

View File

@ -56,6 +56,7 @@
#include "ItemSugarcane.h"
#include "ItemSword.h"
#include "ItemThrowable.h"
#include "ItemAxe.h"
#include "../Blocks/BlockHandler.h"
@ -180,6 +181,15 @@ cItemHandler * cItemHandler::CreateItemHandler(int a_ItemType)
return new cItemShovelHandler(a_ItemType);
}
case E_ITEM_WOODEN_AXE:
case E_ITEM_STONE_AXE:
case E_ITEM_IRON_AXE:
case E_ITEM_GOLD_AXE:
case E_ITEM_DIAMOND_AXE:
{
return new cItemAxeHandler(a_ItemType);
}
case E_ITEM_WOODEN_SWORD:
case E_ITEM_STONE_SWORD:
case E_ITEM_IRON_SWORD:
@ -866,3 +876,13 @@ cItemHandler::FoodInfo cItemHandler::GetFoodInfo()
float cItemHandler::GetBlockBreakingStrength(BLOCKTYPE a_Block)
{
return 1.0f;
}

View File

@ -154,6 +154,10 @@ public:
Defaults to false unless overridden. */
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType);
/** Returns the strength to break a specific block.
Defaults to 1 unless overriden. */
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block);
static cItemHandler * GetItemHandler(int a_ItemType);
static cItemHandler * GetItemHandler(const cItem & a_Item) { return GetItemHandler(a_Item.m_ItemType); }

View File

@ -107,6 +107,29 @@ public:
}
return false;
}
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
{
if (!IsBlockMaterialIron(a_Block) && !IsBlockMaterialAnvil(a_Block) && !IsBlockMaterialRock(a_Block))
{
return super::GetBlockBreakingStrength(a_Block);
}
else
{
switch (m_ItemType)
{
case E_ITEM_WOODEN_PICKAXE: return 2.0f;
case E_ITEM_STONE_PICKAXE: return 4.0f;
case E_ITEM_IRON_PICKAXE: return 6.0f;
case E_ITEM_GOLD_PICKAXE: return 12.0f;
case E_ITEM_DIAMOND_PICKAXE: return 8.0f;
}
}
ASSERT(!"Something is wrong here... Maybe they are pickaxes out of a new material?");
return 1.0f;
}
} ;

View File

@ -90,6 +90,28 @@ public:
}
}
}
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
{
if (IsBlocksWeb(a_Block) || IsBlockMaterialLeaves(a_Block))
{
return 15.0f;
}
else
{
if (IsBlocksWool(a_Block))
{
return 5.0f;
}
else
{
return super::GetBlockBreakingStrength(a_Block);
}
}
}
} ;

View File

@ -59,4 +59,35 @@ public:
return false;
}
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
{
switch (a_Block)
{
case E_BLOCK_CLAY:
case E_BLOCK_DIRT:
case E_BLOCK_FARMLAND:
case E_BLOCK_GRASS:
case E_BLOCK_GRAVEL:
case E_BLOCK_MYCELIUM:
case E_BLOCK_SAND:
case E_BLOCK_SNOW:
case E_BLOCK_SNOW_BLOCK:
case E_BLOCK_SOULSAND:
case E_BLOCK_GRASS_PATH:
{
switch (m_ItemType)
{
case E_ITEM_WOODEN_SHOVEL: return 2.0f;
case E_ITEM_STONE_SHOVEL: return 4.0f;
case E_ITEM_IRON_SHOVEL: return 6.0f;
case E_ITEM_GOLD_SHOVEL: return 12.0f;
case E_ITEM_DIAMOND_SHOVEL: return 8.0f;
}
break;
}
default: return super::GetBlockBreakingStrength(a_Block);
}
ASSERT(!"Something is wrong here... Maybe they are shovels out of a new material?");
return 1.0f;
}
};

View File

@ -56,6 +56,34 @@ public:
return 0;
#endif
}
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
{
if (a_Block == E_BLOCK_COBWEB)
{
return 15.0f;
}
else
{
if (
IsBlockMaterialPlants(a_Block) ||
IsBlockMaterialVine(a_Block) ||
IsBlockMaterialCoral(a_Block) ||
IsBlockMaterialLeaves(a_Block) ||
IsBlockMaterialGourd(a_Block)
)
{
return 1.5f;
}
else
{
return 1.0f;
}
}
}
} ;

View File

@ -150,6 +150,9 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo)
auto settingsRepo = cpp14::make_unique<cOverridesSettingsRepository>(std::move(IniFile), std::move(a_OverridesRepo));
LOG("Starting server...");
cClientHandle::FASTBREAK_PERCENTAGE = settingsRepo->GetValueSetI("AntiCheat", "FastBreakPercentage", 97) / 100.0f;
m_MojangAPI = new cMojangAPI;
bool ShouldAuthenticate = settingsRepo->GetValueSetB("Authentication", "Authenticate", true);
m_MojangAPI->Start(*settingsRepo, ShouldAuthenticate); // Mojang API needs to be started before plugins, so that plugins may use it for DB upgrades on server init