forked from SteamWar/SteamWar
Even more handlers
This commit is contained in:
@@ -7,12 +7,17 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.ToDoubleFunction;
|
import java.util.function.ToDoubleFunction;
|
||||||
import java.util.function.ToIntFunction;
|
import java.util.function.ToIntFunction;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
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.server.packs.repository.Pack;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
@@ -259,6 +264,7 @@ public abstract class TechHider {
|
|||||||
ClientboundSetBorderSizePacket.class, // 7.1.89 Set Border Size
|
ClientboundSetBorderSizePacket.class, // 7.1.89 Set Border Size
|
||||||
ClientboundSetBorderWarningDelayPacket.class, // 7.1.90 Set Border Warning Delay
|
ClientboundSetBorderWarningDelayPacket.class, // 7.1.90 Set Border Warning Delay
|
||||||
ClientboundSetBorderWarningDistancePacket.class, // 7.1.91 Set Border Warning Distance
|
ClientboundSetBorderWarningDistancePacket.class, // 7.1.91 Set Border Warning Distance
|
||||||
|
ClientboundSetCameraPacket.class, // 7.1.92 Set Camera
|
||||||
ClientboundSetChunkCacheRadiusPacket.class, // 7.1.94 Set Render Distance
|
ClientboundSetChunkCacheRadiusPacket.class, // 7.1.94 Set Render Distance
|
||||||
ClientboundSetCursorItemPacket.class, // 7.1.95 Set Cursor Item
|
ClientboundSetCursorItemPacket.class, // 7.1.95 Set Cursor Item
|
||||||
ClientboundSetDefaultSpawnPositionPacket.class, // 7.1.96 Set Default Spawn Position
|
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)
|
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)
|
ClientboundSetHeldSlotPacket.class, // 7.1.104 Set Held Item (Player owning the channel)
|
||||||
ClientboundSetObjectivePacket.class, // 7.1.105 Update Objectives
|
ClientboundSetObjectivePacket.class, // 7.1.105 Update Objectives
|
||||||
ClientboundSetPlayerInventoryPacket.class, // 7.1.107 Set Player Inventory Slot (Player owning the
|
ClientboundSetPlayerInventoryPacket.class, // 7.1.107 Set Player Inventory Slot (Player owning the channel)
|
||||||
// channel)
|
ClientboundSetPlayerTeamPacket.class, // 7.1.108 Update Teams
|
||||||
ClientboundSetScorePacket.class, // 7.1.109 Update Score
|
ClientboundSetScorePacket.class, // 7.1.109 Update Score
|
||||||
ClientboundSetSimulationDistancePacket.class, // 7.1.110 Set Simulation Distance
|
ClientboundSetSimulationDistancePacket.class, // 7.1.110 Set Simulation Distance
|
||||||
ClientboundSetSubtitleTextPacket.class, // 7.1.111 Set Subtitle Text
|
ClientboundSetSubtitleTextPacket.class, // 7.1.111 Set Subtitle Text
|
||||||
@@ -289,8 +295,7 @@ public abstract class TechHider {
|
|||||||
ClientboundClearDialogPacket.class, // 7.1.138 Clear Dialog (play)
|
ClientboundClearDialogPacket.class, // 7.1.138 Clear Dialog (play)
|
||||||
ClientboundShowDialogPacket.class, // 7.1.139 Show Dialog (play)
|
ClientboundShowDialogPacket.class, // 7.1.139 Show Dialog (play)
|
||||||
|
|
||||||
// --- Mostly safe packets; Are involved with critical subdomain, but in not
|
// --- Mostly safe packets; Are involved with critical subdomain, but in not critical way ---
|
||||||
// critical way ---
|
|
||||||
ClientboundBlockChangedAckPacket.class, // 7.1.5 Acknowledge Block Change
|
ClientboundBlockChangedAckPacket.class, // 7.1.5 Acknowledge Block Change
|
||||||
ClientboundChunkBatchFinishedPacket.class, // 7.1.12 Chunk Batch Finished (Delimiter)
|
ClientboundChunkBatchFinishedPacket.class, // 7.1.12 Chunk Batch Finished (Delimiter)
|
||||||
ClientboundChunkBatchStartPacket.class, // 7.1.13 Chunk Batch Start (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
|
ClientboundForgetLevelChunkPacket.class, // 7.1.38 Unload Chunk
|
||||||
ClientboundUpdateTagsPacket.class, // 7.1.133 Update Tags (play)
|
ClientboundUpdateTagsPacket.class, // 7.1.133 Update Tags (play)
|
||||||
ClientboundPlayerInfoRemovePacket.class, // 7.1.68 Player Info Remove
|
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<Player, Packet<? extends PacketListener>, Packet<? extends PacketListener>> tossPacket = (p, packet) -> null;
|
BiFunction<Player, Packet<? extends PacketListener>, Packet<? extends PacketListener>> tossPacket = (p, packet) -> null;
|
||||||
@@ -337,12 +343,22 @@ public abstract class TechHider {
|
|||||||
processors.put(ClientboundSetEntityDataPacket.class, this.buildEntityPacketProcessor(ClientboundSetEntityDataPacket::id));
|
processors.put(ClientboundSetEntityDataPacket.class, this.buildEntityPacketProcessor(ClientboundSetEntityDataPacket::id));
|
||||||
// 7.1.26 Damage Event: entity ids and damage source location can leak hidde activity.
|
// 7.1.26 Damage Event: entity ids and damage source location can leak hidde activity.
|
||||||
processors.put(ClientboundDamageEventPacket.class, this.buildEntityPacketProcessor(ClientboundDamageEventPacket::entityId));
|
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.
|
// 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));
|
processors.put(ClientboundMoveEntityPacket.class, (p, packet) -> this.processMoveEntityPacket(p, (ClientboundMoveEntityPacket) packet));
|
||||||
// 7.1.82 Set Head Rotation: entity id and rotation.
|
// 7.1.82 Set Head Rotation: entity id and rotation.
|
||||||
processors.put(ClientboundRotateHeadPacket.class, (p, packet) -> this.processRotateHeadPacket(p, (ClientboundRotateHeadPacket) packet));
|
processors.put(ClientboundRotateHeadPacket.class, (p, packet) -> this.processRotateHeadPacket(p, (ClientboundRotateHeadPacket) packet));
|
||||||
// 7.1.76 Remove Entities: entity id visibility side channel.
|
// 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.
|
// 7.1.99 Link Entities: entity relationship signal.
|
||||||
processors.put(ClientboundSetEntityLinkPacket.class, (p, packet) -> this.processSetEntityLinkPacket(p, (ClientboundSetEntityLinkPacket) packet));
|
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
|
// 7.1.21 Set Container Slot
|
||||||
processors.put(ClientboundContainerSetSlotPacket.class, buildContainerPacketProcessor(ClientboundContainerSetSlotPacket::getContainerId));
|
processors.put(ClientboundContainerSetSlotPacket.class, buildContainerPacketProcessor(ClientboundContainerSetSlotPacket::getContainerId));
|
||||||
|
|
||||||
// --- Others ---
|
// --- Sound packets ---
|
||||||
// 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 ---
|
|
||||||
// 7.1.115 Entity Sound Effect: entity id and sound.
|
// 7.1.115 Entity Sound Effect: entity id and sound.
|
||||||
processors.put(ClientboundSoundEntityPacket.class, tossPacket);
|
processors.put(ClientboundSoundEntityPacket.class, tossPacket);
|
||||||
// 7.1.116 Sound Effect: sound type and position.
|
// 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.
|
// 7.1.118 Stop Sound: sound state side channel.
|
||||||
processors.put(ClientboundStopSoundPacket.class, tossPacket);
|
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;
|
this.packetProcessors = processors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,8 +479,13 @@ public abstract class TechHider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Packet<?> processRemoveEntitiesPacket(Player player, ClientboundRemoveEntitiesPacket packet) {
|
private Packet<?> processRemoveEntitiesPacket(Player player, ClientboundRemoveEntitiesPacket packet) {
|
||||||
// TODO
|
IntList entityIdsToRemove = packet.getEntityIds();
|
||||||
return null;
|
|
||||||
|
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) {
|
public Packet<?> processSetEntityLinkPacket(Player player, ClientboundSetEntityLinkPacket packet) {
|
||||||
@@ -600,9 +610,9 @@ public abstract class TechHider {
|
|||||||
|
|
||||||
return new ClientboundSectionBlocksUpdatePacket(
|
return new ClientboundSectionBlocksUpdatePacket(
|
||||||
sectionPos,
|
sectionPos,
|
||||||
it.unimi.dsi.fastutil.shorts.ShortSets
|
ShortSets.unmodifiable(new ShortArraySet(newPos)),
|
||||||
.unmodifiable(new it.unimi.dsi.fastutil.shorts.ShortArraySet(newPos)),
|
newStates
|
||||||
newStates);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet<?> processLevelParticlesPacket(Player player, ClientboundLevelParticlesPacket packet) {
|
private Packet<?> processLevelParticlesPacket(Player player, ClientboundLevelParticlesPacket packet) {
|
||||||
@@ -638,6 +648,25 @@ public abstract class TechHider {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Packet<? extends PacketListener> proccessPositionBasedPacket(Player player, int blockX, int blockY, int blockZ, Packet<? extends PacketListener> packet) {
|
||||||
|
if(isPlayerPrivilegedToAccessPosition(player, blockX, blockY, blockZ)) {
|
||||||
|
return packet;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private <TTargetPacket extends Packet<?>> BiFunction<Player, Packet<?>, Packet<?>> buildPositionBasedPacketProcessor(Function<TTargetPacket, BlockPos> 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 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 isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block);
|
||||||
public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);
|
public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);
|
||||||
|
|||||||
Reference in New Issue
Block a user