diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 48068779..c3a467cc 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -7,12 +7,17 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.ToDoubleFunction; import java.util.function.ToIntFunction; +import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; +import it.unimi.dsi.fastutil.shorts.ShortArraySet; +import it.unimi.dsi.fastutil.shorts.ShortSets; import net.minecraft.server.packs.repository.Pack; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.phys.Vec3; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -259,6 +264,7 @@ public abstract class TechHider { ClientboundSetBorderSizePacket.class, // 7.1.89 Set Border Size ClientboundSetBorderWarningDelayPacket.class, // 7.1.90 Set Border Warning Delay ClientboundSetBorderWarningDistancePacket.class, // 7.1.91 Set Border Warning Distance + ClientboundSetCameraPacket.class, // 7.1.92 Set Camera ClientboundSetChunkCacheRadiusPacket.class, // 7.1.94 Set Render Distance ClientboundSetCursorItemPacket.class, // 7.1.95 Set Cursor Item ClientboundSetDefaultSpawnPositionPacket.class, // 7.1.96 Set Default Spawn Position @@ -267,8 +273,8 @@ public abstract class TechHider { ClientboundSetHealthPacket.class, // 7.1.103 Set Health, Saturation and food (Player owning the channel) ClientboundSetHeldSlotPacket.class, // 7.1.104 Set Held Item (Player owning the channel) ClientboundSetObjectivePacket.class, // 7.1.105 Update Objectives - ClientboundSetPlayerInventoryPacket.class, // 7.1.107 Set Player Inventory Slot (Player owning the - // channel) + ClientboundSetPlayerInventoryPacket.class, // 7.1.107 Set Player Inventory Slot (Player owning the channel) + ClientboundSetPlayerTeamPacket.class, // 7.1.108 Update Teams ClientboundSetScorePacket.class, // 7.1.109 Update Score ClientboundSetSimulationDistancePacket.class, // 7.1.110 Set Simulation Distance ClientboundSetSubtitleTextPacket.class, // 7.1.111 Set Subtitle Text @@ -289,8 +295,7 @@ public abstract class TechHider { ClientboundClearDialogPacket.class, // 7.1.138 Clear Dialog (play) ClientboundShowDialogPacket.class, // 7.1.139 Show Dialog (play) - // --- Mostly safe packets; Are involved with critical subdomain, but in not - // critical way --- + // --- Mostly safe packets; Are involved with critical subdomain, but in not critical way --- ClientboundBlockChangedAckPacket.class, // 7.1.5 Acknowledge Block Change ClientboundChunkBatchFinishedPacket.class, // 7.1.12 Chunk Batch Finished (Delimiter) ClientboundChunkBatchStartPacket.class, // 7.1.13 Chunk Batch Start (Delimiter) @@ -300,7 +305,8 @@ public abstract class TechHider { ClientboundForgetLevelChunkPacket.class, // 7.1.38 Unload Chunk ClientboundUpdateTagsPacket.class, // 7.1.133 Update Tags (play) ClientboundPlayerInfoRemovePacket.class, // 7.1.68 Player Info Remove - ClientboundPlayerInfoUpdatePacket.class // 7.1.69 Player Info Update + ClientboundPlayerInfoUpdatePacket.class, // 7.1.69 Player Info Update + ClientboundMoveVehiclePacket.class // 7.1.56 Move Vehicle (vehicle the player is in) )); BiFunction, Packet> tossPacket = (p, packet) -> null; @@ -337,12 +343,22 @@ public abstract class TechHider { processors.put(ClientboundSetEntityDataPacket.class, this.buildEntityPacketProcessor(ClientboundSetEntityDataPacket::id)); // 7.1.26 Damage Event: entity ids and damage source location can leak hidde activity. processors.put(ClientboundDamageEventPacket.class, this.buildEntityPacketProcessor(ClientboundDamageEventPacket::entityId)); + // 7.1.54 Move Minecart Along Track: entity path and position signal. + processors.put(ClientboundMoveMinecartPacket.class, this.buildEntityPacketProcessor(ClientboundMoveMinecartPacket::entityId)); + // 7.1.124 Synchronize Vehicle Position: entity/vehicle position. + processors.put(ClientboundEntityPositionSyncPacket.class, this.buildEntityPacketProcessor(ClientboundEntityPositionSyncPacket::id)); + // 7.1.134 Projectile Power: projectile/entity signal. + processors.put(ClientboundProjectilePowerPacket.class, this.buildEntityPacketProcessor(ClientboundProjectilePowerPacket::getId)); + // 7.1.123 Pickup Item: item/entity ids and pickup activity. + processors.put(ClientboundTakeItemEntityPacket.class, this.buildEntityPacketProcessor(ClientboundTakeItemEntityPacket::getItemId)); + // 7.1.67 Combat Death: entity/player ids and death message context. + processors.put(ClientboundPlayerCombatKillPacket.class, this.buildEntityPacketProcessor(ClientboundPlayerCombatKillPacket::playerId)); // 7.1.52/53/55 Update Entity Position/Rotation: entity id and movement signal. processors.put(ClientboundMoveEntityPacket.class, (p, packet) -> this.processMoveEntityPacket(p, (ClientboundMoveEntityPacket) packet)); // 7.1.82 Set Head Rotation: entity id and rotation. processors.put(ClientboundRotateHeadPacket.class, (p, packet) -> this.processRotateHeadPacket(p, (ClientboundRotateHeadPacket) packet)); // 7.1.76 Remove Entities: entity id visibility side channel. - processors.put(ClientboundRemoveEntitiesPacket.class, tossPacket); + processors.put(ClientboundRemoveEntitiesPacket.class, (p, packet) -> this.processRemoveEntitiesPacket(p, (ClientboundRemoveEntitiesPacket) packet)); // 7.1.99 Link Entities: entity relationship signal. processors.put(ClientboundSetEntityLinkPacket.class, (p, packet) -> this.processSetEntityLinkPacket(p, (ClientboundSetEntityLinkPacket) packet)); @@ -384,39 +400,7 @@ public abstract class TechHider { // 7.1.21 Set Container Slot processors.put(ClientboundContainerSetSlotPacket.class, buildContainerPacketProcessor(ClientboundContainerSetSlotPacket::getContainerId)); - // --- Others --- - // 7.1.37 Explosion: position, affected blocks, and knockback can reveal - // TNT/tech. - processors.put(ClientboundExplodePacket.class, tossPacket); - // 7.1.46 World Event: block position/event id can leak activity. - processors.put(ClientboundLevelEventPacket.class, tossPacket); - // 7.1.50 Map Data: map pixels/icons can reveal player/world state. - processors.put(ClientboundMapItemDataPacket.class, tossPacket); - // 7.1.54 Move Minecart Along Track: entity path and position signal. - processors.put(ClientboundMoveMinecartPacket.class, tossPacket); - // 7.1.56 Move Vehicle (clientbound): vehicle position signal. - processors.put(ClientboundMoveVehiclePacket.class, tossPacket); - // 7.1.59 Open Sign Editor: block position. - processors.put(ClientboundOpenSignEditorPacket.class, tossPacket); - // 7.1.124 Synchronize Vehicle Position: entity/vehicle position. - processors.put(ClientboundEntityPositionSyncPacket.class, tossPacket); - // 7.1.134 Projectile Power: projectile/entity signal. - processors.put(ClientboundProjectilePowerPacket.class, tossPacket); - // 7.1.137 Waypoint: world/entity tracking signal. - processors.put(ClientboundTrackedWaypointPacket.class, tossPacket); - - // --- Safe enough (not enough relevant data) to leak critical information; - // review and add to bypass --- - // 7.1.123 Pickup Item: item/entity ids and pickup activity. - processors.put(ClientboundTakeItemEntityPacket.class, tossPacket); - // 7.1.92 Set Camera: entity id. - processors.put(ClientboundSetCameraPacket.class, tossPacket); - // 7.1.108 Update Teams: player/team membership can be used as intel. - processors.put(ClientboundSetPlayerTeamPacket.class, tossPacket); - // 7.1.67 Combat Death: entity/player ids and death message context. - processors.put(ClientboundPlayerCombatKillPacket.class, tossPacket); - - // --- Sound packets natural part of the game -> should not be hidden --- + // --- Sound packets --- // 7.1.115 Entity Sound Effect: entity id and sound. processors.put(ClientboundSoundEntityPacket.class, tossPacket); // 7.1.116 Sound Effect: sound type and position. @@ -424,6 +408,27 @@ public abstract class TechHider { // 7.1.118 Stop Sound: sound state side channel. processors.put(ClientboundStopSoundPacket.class, tossPacket); + // --- Others --- + // 7.1.137 Waypoint: world/entity tracking signal. + processors.put(ClientboundTrackedWaypointPacket.class, tossPacket); + // 7.1.50 Map Data: map pixels/icons can reveal player/world state. + processors.put(ClientboundMapItemDataPacket.class, tossPacket); + // 7.1.46 World Event: block position/event id can leak activity. + processors.put(ClientboundLevelEventPacket.class, buildPositionBasedPacketProcessor(ClientboundLevelEventPacket::getPos)); + // 7.1.59 Open Sign Editor: block position. + processors.put(ClientboundOpenSignEditorPacket.class, buildPositionBasedPacketProcessor(ClientboundLevelEventPacket::getPos)); + // 7.1.37 Explosion: position, affected blocks, and knockback can reveal TNT/tech. + processors.put(ClientboundExplodePacket.class, (p, rawPacket) -> { + ClientboundExplodePacket packet = (ClientboundExplodePacket) rawPacket; + Vec3 pos = packet.center(); + int blockX = (int) pos.x; + int blockY = (int) pos.y; + int blockZ = (int) pos.z; + + + return proccessPositionBasedPacket(p, blockX, blockY, blockZ, packet); + }); + this.packetProcessors = processors; } @@ -474,8 +479,13 @@ public abstract class TechHider { } private Packet processRemoveEntitiesPacket(Player player, ClientboundRemoveEntitiesPacket packet) { - // TODO - return null; + IntList entityIdsToRemove = packet.getEntityIds(); + + IntList filteredEntitiesToRemove = entityIdsToRemove.intStream() + .filter((id) -> isPlayerPrivilegedToAccessEntity(player, id)) + .collect(IntArrayList::new, IntList::add, IntList::addAll); + + return new ClientboundRemoveEntitiesPacket(filteredEntitiesToRemove); } public Packet processSetEntityLinkPacket(Player player, ClientboundSetEntityLinkPacket packet) { @@ -600,9 +610,9 @@ public abstract class TechHider { return new ClientboundSectionBlocksUpdatePacket( sectionPos, - it.unimi.dsi.fastutil.shorts.ShortSets - .unmodifiable(new it.unimi.dsi.fastutil.shorts.ShortArraySet(newPos)), - newStates); + ShortSets.unmodifiable(new ShortArraySet(newPos)), + newStates + ); } private Packet processLevelParticlesPacket(Player player, ClientboundLevelParticlesPacket packet) { @@ -638,6 +648,25 @@ public abstract class TechHider { }; } + private Packet proccessPositionBasedPacket(Player player, int blockX, int blockY, int blockZ, Packet packet) { + if(isPlayerPrivilegedToAccessPosition(player, blockX, blockY, blockZ)) { + return packet; + } else { + return null; + } + } + private > BiFunction, Packet> buildPositionBasedPacketProcessor(Function positionExtractor) { + return (p, rawPacket) -> { + TTargetPacket packet = (TTargetPacket) rawPacket; + BlockPos pos = positionExtractor.apply(packet); + int blockX = pos.getX(); + int blockY = pos.getY(); + int blockZ = pos.getZ(); + + return proccessPositionBasedPacket(p, blockX, blockY, blockZ, packet); + }; + } + public abstract boolean isPlayerPrivilegedToAccessPosition(Player p, int blockX, int blockY, int blockZ); public abstract boolean isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block); public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);