forked from SteamWar/SteamWar
Add bundle packet handling
This commit is contained in:
@@ -140,18 +140,6 @@ public class HullHider implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) {
|
||||
if (!TechHiderWrapper.ENABLED) return false;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
if (hull.blockPrecise(player, chunkX, chunkY, chunkZ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSpawn(EntitySpawnEvent e) {
|
||||
for (Hull hull : hulls) {
|
||||
|
||||
+9
-2
@@ -37,6 +37,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -89,10 +90,16 @@ public class TechHiderWrapper extends StateDependent implements Listener {
|
||||
return !hiddenRegion.inRegion(blockX, blockY, blockZ) || !blocksToObfuscate.contains(block);
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId) {
|
||||
return true;
|
||||
net.minecraft.world.entity.Entity nmsEntity = ((CraftWorld) p.getWorld()).getHandle().moonrise$getEntityLookup().get(entityId);
|
||||
|
||||
if(nmsEntity != null) {
|
||||
return !hullHider.isBlockHidden(p, nmsEntity.getBlockX(), nmsEntity.getBlockY(), nmsEntity.getBlockZ());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,11 @@ 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.network.protocol.game.*;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.entity.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.network.PacketListener;
|
||||
@@ -18,12 +23,13 @@ import net.minecraft.network.protocol.configuration.ClientboundUpdateEnabledFeat
|
||||
import net.minecraft.network.protocol.cookie.ClientboundCookieRequestPacket;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.network.protocol.login.*;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundHelloPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundLoginCompressionPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundLoginFinishedPacket;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -182,19 +188,14 @@ public abstract class TechHider {
|
||||
ClientboundPlayerInfoRemovePacket.class, // 7.1.68 Player Info Remove
|
||||
ClientboundPlayerInfoUpdatePacket.class, // 7.1.69 Player Info Update
|
||||
ClientboundMoveVehiclePacket.class, // 7.1.56 Move Vehicle (vehicle the player is in)
|
||||
ClientboundStopSoundPacket.class, // 7.1.118 Stop Sound: sound state side channel
|
||||
ClientboundStopSoundPacket.class // 7.1.118 Stop Sound: sound state side channel
|
||||
|
||||
|
||||
//TODO rem later
|
||||
ClientboundBundlePacket.class
|
||||
));
|
||||
|
||||
BiFunction<Player, Packet<? extends PacketListener>, Packet<? extends PacketListener>> tossPacket = (p, packet) -> null;
|
||||
Map<Class<? extends Packet<? extends PacketListener>>, BiFunction<Player, Packet<? extends PacketListener>, Packet<? extends PacketListener>>> processors = new HashMap<>();
|
||||
|
||||
// 7.1.x Bundle Packet: packet container; blocked until nested packets are
|
||||
// safely unbundled/processed.
|
||||
processors.put(ClientboundBundlePacket.class, tossPacket);
|
||||
|
||||
// --- Entity packets -
|
||||
// 7.1.2 Spawn Entity: entity type and position can reveal hidden contraptions.
|
||||
processors.put(ClientboundAddEntityPacket.class, (p, packet) -> this.processAddEntityPacket(p, (ClientboundAddEntityPacket) packet));
|
||||
@@ -299,7 +300,7 @@ public abstract class TechHider {
|
||||
// 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));
|
||||
processors.put(ClientboundOpenSignEditorPacket.class, buildPositionBasedPacketProcessor(ClientboundOpenSignEditorPacket::getPos));
|
||||
// 7.1.37 Explosion: position, affected blocks, and knockback can reveal TNT/tech.
|
||||
processors.put(ClientboundExplodePacket.class, (p, rawPacket) -> {
|
||||
ClientboundExplodePacket packet = (ClientboundExplodePacket) rawPacket;
|
||||
@@ -314,23 +315,39 @@ public abstract class TechHider {
|
||||
|
||||
this.packetProcessors = processors;
|
||||
|
||||
TinyProtocol.instance.addGlobalClientboundFilter((player, packet) -> {
|
||||
TinyProtocol.instance.addGlobalClientboundFilter((player, rawPacket) -> {
|
||||
if(rawPacket instanceof ClientboundBundlePacket bundlePacket) {
|
||||
List<Packet<? super ClientGamePacketListener>> processedPackets = new ArrayList<>();
|
||||
|
||||
for(Packet<? super ClientGamePacketListener> packet : bundlePacket.subPackets()) {
|
||||
Packet<? super ClientGamePacketListener> processedPacket = (Packet<? super ClientGamePacketListener>) processPacket(player, packet);
|
||||
|
||||
if(processedPacket != null) {
|
||||
processedPackets.add(processedPacket);
|
||||
}
|
||||
}
|
||||
|
||||
return new ClientboundBundlePacket(processedPackets);
|
||||
}
|
||||
else if(rawPacket instanceof Packet) {
|
||||
return processPacket(player, (Packet<?>) rawPacket);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Packet<?> processPacket(Player player, Packet<?> packet) {
|
||||
if(bypassingPackets.contains(packet.getClass())) {
|
||||
return packet;
|
||||
}
|
||||
else if(packetProcessors.containsKey(packet.getClass())) {
|
||||
//System.out.println("processing");
|
||||
//System.out.println(packet.getClass());
|
||||
return packetProcessors.get(packet.getClass()).apply(player, (Packet<? extends PacketListener>) packet);
|
||||
}
|
||||
else {
|
||||
System.out.println("dropping");
|
||||
System.out.println(packet.getClass());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Packet<? extends PacketListener> processAddEntityPacket(Player player, ClientboundAddEntityPacket packet) {
|
||||
|
||||
Reference in New Issue
Block a user