3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Rename ChunkHandler

Introduce Packet Filtering
Dieser Commit ist enthalten in:
Myles 2016-03-22 15:36:11 +00:00
Ursprung f5a96b791d
Commit a5ba52ce05
6 geänderte Dateien mit 38 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -8,15 +8,8 @@ The things which stop this from going live:
Need to implement debug mode using deprecated PacketType for english Need to implement debug mode using deprecated PacketType for english
Need to implement a way for mappers to register listeners <--
and eventually we'll add a way to add things the way chunk handler works!!
and then javadocs. and then javadocs.
and maybe check for memory leaks.
It would be nice to have a Pipeline cache so it doesn't have to figure it out all the time. It would be nice to have a Pipeline cache so it doesn't have to figure it out all the time.
(and to ensure it uses the shortest pipeline) (and to ensure it uses the shortest pipeline)

Datei anzeigen

@ -11,6 +11,7 @@ import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class Protocol { public abstract class Protocol {
@ -22,6 +23,14 @@ public abstract class Protocol {
registerListeners(); registerListeners();
} }
public boolean isFiltered(Class packetClass) {
return false;
}
protected void filterPacket(UserConnection info, Object packet, List output) throws Exception {
output.add(packet);
}
protected void registerListeners() { protected void registerListeners() {
} }

Datei anzeigen

@ -2,10 +2,10 @@ package us.myles.ViaVersion.api.protocol;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.BaseProtocol;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.BaseProtocol;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -78,4 +78,15 @@ public class ProtocolPipeline extends Protocol {
} }
return false; return false;
} }
public boolean filter(Object o, List list) throws Exception {
for (Protocol protocol : protocolList) {
if (protocol.isFiltered(o.getClass())) {
protocol.filterPacket(userConnection, o, list);
return true;
}
}
return false;
}
} }

Datei anzeigen

@ -5,15 +5,13 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.handler.codec.MessageToMessageEncoder;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import java.util.List; import java.util.List;
public class ViaChunkHandler extends MessageToMessageEncoder { public class ViaPacketHandler extends MessageToMessageEncoder {
private final UserConnection info; private final UserConnection info;
public ViaChunkHandler(UserConnection info) { public ViaPacketHandler(UserConnection info) {
this.info = info; this.info = info;
} }
@ -25,9 +23,8 @@ public class ViaChunkHandler extends MessageToMessageEncoder {
if (!(o instanceof ByteBuf)) { if (!(o instanceof ByteBuf)) {
info.setLastPacket(o); info.setLastPacket(o);
/* This transformer is more for fixing issues which we find hard at packet level :) */ /* This transformer is more for fixing issues which we find hard at packet level :) */
if (o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk") && info.isActive()) { if (info.isActive()) {
if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) {
list.addAll(info.get(ClientChunks.class).transformMapChunkBulk(o));
return; return;
} }
} }

Datei anzeigen

@ -36,10 +36,10 @@ public class ViaVersionInitializer extends ChannelInitializer<SocketChannel> {
// Add our transformers // Add our transformers
ViaEncodeHandler encoder = new ViaEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder")); ViaEncodeHandler encoder = new ViaEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder"));
ViaDecodeHandler decoder = new ViaDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder")); ViaDecodeHandler decoder = new ViaDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder"));
ViaChunkHandler chunkHandler = new ViaChunkHandler(info); ViaPacketHandler chunkHandler = new ViaPacketHandler(info);
socketChannel.pipeline().replace("encoder", "encoder", encoder); socketChannel.pipeline().replace("encoder", "encoder", encoder);
socketChannel.pipeline().replace("decoder", "decoder", decoder); socketChannel.pipeline().replace("decoder", "decoder", decoder);
socketChannel.pipeline().addAfter("packet_handler", "viaversion_chunk_handler", chunkHandler); socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
} }
} }

Datei anzeigen

@ -99,6 +99,16 @@ public class Protocol1_9TO1_8 extends Protocol {
Bukkit.getPluginManager().registerEvents(new CommandBlockListener(plugin), plugin); Bukkit.getPluginManager().registerEvents(new CommandBlockListener(plugin), plugin);
} }
@Override
public boolean isFiltered(Class packetClass) {
return packetClass.getName().endsWith("PacketPlayOutMapChunkBulk");
}
@Override
protected void filterPacket(UserConnection info, Object packet, List output) throws Exception {
output.addAll(info.get(ClientChunks.class).transformMapChunkBulk(packet));
}
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
// Entity tracker // Entity tracker