Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Allow packets to be written to the server using passthrouh ID, shouldn't break anything I also updated comment on why interaction is half broken
Dieser Commit ist enthalten in:
Ursprung
6197138380
Commit
d89a34cca3
@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.remapper.ValueCreator;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.TypeConverter;
|
import us.myles.ViaVersion.api.type.TypeConverter;
|
||||||
import us.myles.ViaVersion.exception.InformativeException;
|
import us.myles.ViaVersion.exception.InformativeException;
|
||||||
|
import us.myles.ViaVersion.handlers.ViaDecodeHandler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -263,4 +264,23 @@ public class PacketWrapper {
|
|||||||
this.readableObjects.addAll(packetValues);
|
this.readableObjects.addAll(packetValues);
|
||||||
this.packetValues.clear();
|
this.packetValues.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendToServer() throws Exception {
|
||||||
|
if (!isCancelled()) {
|
||||||
|
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
|
||||||
|
Type.VAR_INT.write(output, ViaDecodeHandler.PASSTHROUGH_ID); // Pass through
|
||||||
|
|
||||||
|
writeToBuffer(output);
|
||||||
|
|
||||||
|
boolean mark = false;
|
||||||
|
for (String s : user().getChannel().pipeline().names()) {
|
||||||
|
if (mark) {
|
||||||
|
user().getChannel().pipeline().context(user().getChannel().pipeline().get(s)).fireChannelRead(output);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (s.equalsIgnoreCase("decompress"))
|
||||||
|
mark = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import us.myles.ViaVersion.api.PacketWrapper;
|
|||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
import us.myles.ViaVersion.exception.InformativeException;
|
|
||||||
import us.myles.ViaVersion.packets.Direction;
|
import us.myles.ViaVersion.packets.Direction;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.util.PipelineUtil;
|
import us.myles.ViaVersion.util.PipelineUtil;
|
||||||
@ -19,6 +18,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
|||||||
|
|
||||||
private final ByteToMessageDecoder minecraftDecoder;
|
private final ByteToMessageDecoder minecraftDecoder;
|
||||||
private final UserConnection info;
|
private final UserConnection info;
|
||||||
|
public static int PASSTHROUGH_ID = 1000;
|
||||||
|
|
||||||
public ViaDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
|
public ViaDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
@ -37,10 +37,14 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
|||||||
// Transform
|
// Transform
|
||||||
ByteBuf newPacket = ctx.alloc().buffer();
|
ByteBuf newPacket = ctx.alloc().buffer();
|
||||||
try {
|
try {
|
||||||
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info);
|
if (id == ViaDecodeHandler.PASSTHROUGH_ID) {
|
||||||
ProtocolInfo protInfo = info.get(ProtocolInfo.class);
|
newPacket.writeBytes(bytebuf);
|
||||||
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
|
} else {
|
||||||
wrapper.writeToBuffer(newPacket);
|
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info);
|
||||||
|
ProtocolInfo protInfo = info.get(ProtocolInfo.class);
|
||||||
|
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
|
||||||
|
wrapper.writeToBuffer(newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
bytebuf.clear();
|
bytebuf.clear();
|
||||||
bytebuf = newPacket;
|
bytebuf = newPacket;
|
||||||
|
@ -7,7 +7,6 @@ import us.myles.ViaVersion.api.PacketWrapper;
|
|||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
import us.myles.ViaVersion.exception.InformativeException;
|
|
||||||
import us.myles.ViaVersion.packets.Direction;
|
import us.myles.ViaVersion.packets.Direction;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.util.PipelineUtil;
|
import us.myles.ViaVersion.util.PipelineUtil;
|
||||||
@ -48,11 +47,12 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
|
|||||||
// Transform
|
// Transform
|
||||||
ByteBuf oldPacket = bytebuf.copy();
|
ByteBuf oldPacket = bytebuf.copy();
|
||||||
bytebuf.clear();
|
bytebuf.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, info);
|
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, info);
|
||||||
ProtocolInfo protInfo = info.get(ProtocolInfo.class);
|
ProtocolInfo protInfo = info.get(ProtocolInfo.class);
|
||||||
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
|
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
|
||||||
wrapper.writeToBuffer(bytebuf);
|
wrapper.writeToBuffer(bytebuf);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
bytebuf.clear();
|
bytebuf.clear();
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -80,12 +80,12 @@ public class WorldPackets {
|
|||||||
}
|
}
|
||||||
wrapper.set(Type.STRING, 0, newname);
|
wrapper.set(Type.STRING, 0, newname);
|
||||||
wrapper.write(Type.VAR_INT, catid); // Write Category ID
|
wrapper.write(Type.VAR_INT, catid); // Write Category ID
|
||||||
if(effect != null && effect.isBreaksound()) {
|
if (effect != null && effect.isBreaksound()) {
|
||||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||||
int x = wrapper.passthrough(Type.INT); //Position X
|
int x = wrapper.passthrough(Type.INT); //Position X
|
||||||
int y = wrapper.passthrough(Type.INT); //Position Y
|
int y = wrapper.passthrough(Type.INT); //Position Y
|
||||||
int z = wrapper.passthrough(Type.INT); //Position Z
|
int z = wrapper.passthrough(Type.INT); //Position Z
|
||||||
if(tracker.interactedBlockRecently((int)Math.floor(x/8.0),(int)Math.floor(y/8.0),(int)Math.floor(z/8.0))) {
|
if (tracker.interactedBlockRecently((int) Math.floor(x / 8.0), (int) Math.floor(y / 8.0), (int) Math.floor(z / 8.0))) {
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -228,19 +228,6 @@ public class WorldPackets {
|
|||||||
protocol.registerIncoming(State.PLAY, -1, 0x1D, new PacketRemapper() {
|
protocol.registerIncoming(State.PLAY, -1, 0x1D, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
|
||||||
Long last = tracker.getLastPlaceBlock();
|
|
||||||
if (last != -1) {
|
|
||||||
if ((wrapper.user().getReceivedPackets() - last) < 5) {
|
|
||||||
wrapper.cancel();
|
|
||||||
}
|
|
||||||
tracker.setLastPlaceBlock(-1L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
@ -276,6 +263,46 @@ public class WorldPackets {
|
|||||||
wrapper.write(Type.BYTE, (byte) 0);
|
wrapper.write(Type.BYTE, (byte) 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
|
||||||
|
The thing i've discovered is when using an item in air, it needs to send 2 packets.
|
||||||
|
I believe the issue is that this needs to be flipped with the packet above while still
|
||||||
|
sending block info.
|
||||||
|
|
||||||
|
Otherwise no idea, the disadvantage: Interact does not get fired if you right click
|
||||||
|
special items. (there's quite a few...)
|
||||||
|
|
||||||
|
*/
|
||||||
|
// handler(new PacketHandler() {
|
||||||
|
// @Override
|
||||||
|
// public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
// if(wrapper.isCancelled()) return;
|
||||||
|
// EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||||
|
// if(tracker.isBlocking()) return;
|
||||||
|
//
|
||||||
|
// Long last = tracker.getLastPlaceBlock();
|
||||||
|
// if (last != -1) {
|
||||||
|
// if ((wrapper.user().getReceivedPackets() - last) < 3) {
|
||||||
|
// tracker.setLastPlaceBlock(-1L);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// tracker.setLastPlaceBlock(-1L);
|
||||||
|
// }
|
||||||
|
// final Item item = wrapper.get(Type.ITEM, 0);
|
||||||
|
// wrapper.create(0x08, new ValueCreator() {
|
||||||
|
// @Override
|
||||||
|
// public void write(PacketWrapper wrapper) throws Exception {
|
||||||
|
// wrapper.write(Type.POSITION, new Position(1L, 1L, 1L));
|
||||||
|
// wrapper.write(Type.BYTE, (byte) 2);
|
||||||
|
// wrapper.write(Type.ITEM, item); // hand
|
||||||
|
//
|
||||||
|
// wrapper.write(Type.UNSIGNED_BYTE, (short) 1);
|
||||||
|
// wrapper.write(Type.UNSIGNED_BYTE, (short) 1);
|
||||||
|
// wrapper.write(Type.UNSIGNED_BYTE, (short) 1);
|
||||||
|
// }
|
||||||
|
// }).sendToServer();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -322,11 +349,10 @@ public class WorldPackets {
|
|||||||
special = special || ArmorType.isArmor(m);
|
special = special || ArmorType.isArmor(m);
|
||||||
// Don't send data if special
|
// Don't send data if special
|
||||||
if (special && m != Material.AIR) {
|
if (special && m != Material.AIR) {
|
||||||
wrapper.set(Type.POSITION, 0, new Position(-1L, -1L, -1L));
|
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||||
wrapper.set(Type.BYTE, 0, (byte) 255);
|
tracker.setLastPlaceBlock(wrapper.user().getReceivedPackets());
|
||||||
}
|
}
|
||||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
|
||||||
tracker.setLastPlaceBlock(wrapper.user().getReceivedPackets());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,21 +362,35 @@ public class WorldPackets {
|
|||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
int face = wrapper.get(Type.BYTE,0);
|
int face = wrapper.get(Type.BYTE, 0);
|
||||||
if(face == 255)
|
if (face == 255)
|
||||||
return;
|
return;
|
||||||
Position p = wrapper.get(Type.POSITION, 0);
|
Position p = wrapper.get(Type.POSITION, 0);
|
||||||
long x = p.getX(); long y = p.getY(); long z = p.getZ();
|
long x = p.getX();
|
||||||
switch(face) {
|
long y = p.getY();
|
||||||
case 0: y--; break;
|
long z = p.getZ();
|
||||||
case 1: y++; break;
|
switch (face) {
|
||||||
case 2: z--; break;
|
case 0:
|
||||||
case 3: z++; break;
|
y--;
|
||||||
case 4: x--; break;
|
break;
|
||||||
case 5: x++; break;
|
case 1:
|
||||||
|
y++;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
z--;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
z++;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
x--;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
x++;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||||
tracker.addBlockInteraction(new Position(x,y,z));
|
tracker.addBlockInteraction(new Position(x, y, z));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren