forked from SteamWar/SteamWar
Add bundle packet handling
This commit is contained in:
@@ -140,18 +140,6 @@ public class HullHider implements Listener {
|
|||||||
return false;
|
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)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onSpawn(EntitySpawnEvent e) {
|
public void onSpawn(EntitySpawnEvent e) {
|
||||||
for (Hull hull : hulls) {
|
for (Hull hull : hulls) {
|
||||||
|
|||||||
+9
-2
@@ -37,6 +37,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
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);
|
return !hiddenRegion.inRegion(blockX, blockY, blockZ) || !blocksToObfuscate.contains(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ 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.ShortArraySet;
|
||||||
import it.unimi.dsi.fastutil.shorts.ShortSets;
|
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.BlockPos;
|
||||||
import net.minecraft.core.SectionPos;
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.network.PacketListener;
|
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.cookie.ClientboundCookieRequestPacket;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.network.protocol.login.*;
|
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.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
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.*;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@@ -182,19 +188,14 @@ public abstract class TechHider {
|
|||||||
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)
|
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;
|
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<>();
|
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 -
|
// --- Entity packets -
|
||||||
// 7.1.2 Spawn Entity: entity type and position can reveal hidden contraptions.
|
// 7.1.2 Spawn Entity: entity type and position can reveal hidden contraptions.
|
||||||
processors.put(ClientboundAddEntityPacket.class, (p, packet) -> this.processAddEntityPacket(p, (ClientboundAddEntityPacket) packet));
|
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.
|
// 7.1.46 World Event: block position/event id can leak activity.
|
||||||
processors.put(ClientboundLevelEventPacket.class, buildPositionBasedPacketProcessor(ClientboundLevelEventPacket::getPos));
|
processors.put(ClientboundLevelEventPacket.class, buildPositionBasedPacketProcessor(ClientboundLevelEventPacket::getPos));
|
||||||
// 7.1.59 Open Sign Editor: block position.
|
// 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.
|
// 7.1.37 Explosion: position, affected blocks, and knockback can reveal TNT/tech.
|
||||||
processors.put(ClientboundExplodePacket.class, (p, rawPacket) -> {
|
processors.put(ClientboundExplodePacket.class, (p, rawPacket) -> {
|
||||||
ClientboundExplodePacket packet = (ClientboundExplodePacket) rawPacket;
|
ClientboundExplodePacket packet = (ClientboundExplodePacket) rawPacket;
|
||||||
@@ -314,25 +315,41 @@ public abstract class TechHider {
|
|||||||
|
|
||||||
this.packetProcessors = processors;
|
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(bypassingPackets.contains(packet.getClass())) {
|
if(processedPacket != null) {
|
||||||
return packet;
|
processedPackets.add(processedPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ClientboundBundlePacket(processedPackets);
|
||||||
}
|
}
|
||||||
else if(packetProcessors.containsKey(packet.getClass())) {
|
else if(rawPacket instanceof Packet) {
|
||||||
//System.out.println("processing");
|
return processPacket(player, (Packet<?>) rawPacket);
|
||||||
//System.out.println(packet.getClass());
|
|
||||||
return packetProcessors.get(packet.getClass()).apply(player, (Packet<? extends PacketListener>) packet);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("dropping");
|
|
||||||
System.out.println(packet.getClass());
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Packet<?> processPacket(Player player, Packet<?> packet) {
|
||||||
|
if(bypassingPackets.contains(packet.getClass())) {
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
else if(packetProcessors.containsKey(packet.getClass())) {
|
||||||
|
return packetProcessors.get(packet.getClass()).apply(player, (Packet<? extends PacketListener>) packet);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Packet<? extends PacketListener> processAddEntityPacket(Player player, ClientboundAddEntityPacket packet) {
|
private Packet<? extends PacketListener> processAddEntityPacket(Player player, ClientboundAddEntityPacket packet) {
|
||||||
if(isPlayerPrivilegedToAccessEntity(player, packet.getId()) && isPlayerPrivilegedToAccessPosition(player, (int) packet.getX(), (int) packet.getY(), (int) packet.getZ())) {
|
if(isPlayerPrivilegedToAccessEntity(player, packet.getId()) && isPlayerPrivilegedToAccessPosition(player, (int) packet.getX(), (int) packet.getY(), (int) packet.getZ())) {
|
||||||
return packet;
|
return packet;
|
||||||
|
|||||||
Reference in New Issue
Block a user