diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts index 40f1662..347d95e 100644 --- a/proxy/build.gradle.kts +++ b/proxy/build.gradle.kts @@ -11,11 +11,13 @@ repositories { dependencies { implementation("io.netty:netty-all:4.0.23.Final") + implementation("com.google.guava:guava:17.0") + implementation("com.google.code.gson:gson:2.2.4") } java { toolchain { - languageVersion = JavaLanguageVersion.of(21) + languageVersion = JavaLanguageVersion.of(8) } } diff --git a/proxy/src/main/java/net/minecraft/network/handshake/client/C00Handshake.java b/proxy/src/main/java/net/minecraft/network/handshake/client/C00Handshake.java new file mode 100755 index 0000000..e9ec81a --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/handshake/client/C00Handshake.java @@ -0,0 +1,68 @@ +package net.minecraft.network.handshake.client; + +import java.io.IOException; + +import proxy.network.EnumConnectionState; +import proxy.network.NetHandlerHandshake; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C00Handshake implements Packet +{ + private int protocolVersion; + private String ip; + private int port; + private EnumConnectionState requestedState; + + public C00Handshake() + { + } + + public C00Handshake(int version, String ip, int port, EnumConnectionState requestedState) + { + this.protocolVersion = version; + this.ip = ip; + this.port = port; + this.requestedState = requestedState; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.protocolVersion = buf.readVarIntFromBuffer(); + this.ip = buf.readStringFromBuffer(255); + this.port = buf.readUnsignedShort(); + this.requestedState = EnumConnectionState.getById(buf.readVarIntFromBuffer()); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.protocolVersion); + buf.writeString(this.ip); + buf.writeShort(this.port); + buf.writeVarIntToBuffer(this.requestedState.getId()); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerHandshake handler) + { + handler.processHandshake(this); + } + + public EnumConnectionState getRequestedState() + { + return this.requestedState; + } + + public int getProtocolVersion() + { + return this.protocolVersion; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/login/client/C00PacketLoginStart.java b/proxy/src/main/java/net/minecraft/network/login/client/C00PacketLoginStart.java new file mode 100755 index 0000000..ec42882 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/login/client/C00PacketLoginStart.java @@ -0,0 +1,50 @@ +package net.minecraft.network.login.client; + +import java.io.IOException; + +import proxy.network.NetHandlerLoginServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C00PacketLoginStart implements Packet +{ + private String profile; + + public C00PacketLoginStart() + { + } + + public C00PacketLoginStart(String profileIn) + { + this.profile = profileIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.profile = buf.readStringFromBuffer(16); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.profile); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerLoginServer handler) + { + handler.processLoginStart(this); + } + + public String getProfile() + { + return this.profile; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/login/client/C01PacketEncryptionResponse.java b/proxy/src/main/java/net/minecraft/network/login/client/C01PacketEncryptionResponse.java new file mode 100755 index 0000000..054ce18 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/login/client/C01PacketEncryptionResponse.java @@ -0,0 +1,39 @@ +package net.minecraft.network.login.client; + +import java.io.IOException; + +import proxy.network.NetHandlerLoginServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C01PacketEncryptionResponse implements Packet +{ + private byte[] secretKeyEncrypted = new byte[0]; + private byte[] verifyTokenEncrypted = new byte[0]; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.secretKeyEncrypted = buf.readByteArray(); + this.verifyTokenEncrypted = buf.readByteArray(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByteArray(this.secretKeyEncrypted); + buf.writeByteArray(this.verifyTokenEncrypted); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerLoginServer handler) + { + handler.processEncryptionResponse(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/login/server/S00PacketDisconnect.java b/proxy/src/main/java/net/minecraft/network/login/server/S00PacketDisconnect.java new file mode 100755 index 0000000..f7ec977 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/login/server/S00PacketDisconnect.java @@ -0,0 +1,51 @@ +package net.minecraft.network.login.server; + +import java.io.IOException; + +import proxy.network.NetHandlerPlayServer.ProxyLoginHandler; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; + +public class S00PacketDisconnect implements Packet +{ + private ChatComponent reason; + + public S00PacketDisconnect() + { + } + + public S00PacketDisconnect(ChatComponent reasonIn) + { + this.reason = reasonIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.reason = buf.readChatComponent(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeChatComponent(this.reason); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(ProxyLoginHandler handler) + { + handler.handleDisconnect(this); + } + + public ChatComponent func_149603_c() + { + return this.reason; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/login/server/S01PacketEncryptionRequest.java b/proxy/src/main/java/net/minecraft/network/login/server/S01PacketEncryptionRequest.java new file mode 100755 index 0000000..8e843fc --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/login/server/S01PacketEncryptionRequest.java @@ -0,0 +1,42 @@ +package net.minecraft.network.login.server; + +import java.io.IOException; + +import proxy.network.NetHandlerPlayServer.ProxyLoginHandler; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S01PacketEncryptionRequest implements Packet +{ + private String hashedServerId; + private byte[] publicKey; + private byte[] verifyToken; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.hashedServerId = buf.readStringFromBuffer(20); + this.publicKey = buf.readByteArray(); + this.verifyToken = buf.readByteArray(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.hashedServerId); + buf.writeByteArray(this.publicKey); + buf.writeByteArray(this.verifyToken); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(ProxyLoginHandler handler) + { + handler.handleEncryptionRequest(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/login/server/S02PacketLoginSuccess.java b/proxy/src/main/java/net/minecraft/network/login/server/S02PacketLoginSuccess.java new file mode 100755 index 0000000..fcd119c --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/login/server/S02PacketLoginSuccess.java @@ -0,0 +1,61 @@ +package net.minecraft.network.login.server; + +import java.io.IOException; +import java.util.UUID; + +import proxy.network.NetHandlerPlayServer.ProxyLoginHandler; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S02PacketLoginSuccess implements Packet +{ + private UUID id; + private String name; + + public S02PacketLoginSuccess() + { + } + + public S02PacketLoginSuccess(UUID id, String name) + { + this.id = id; + this.name = name; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + String s = buf.readStringFromBuffer(36); + this.name = buf.readStringFromBuffer(16); + this.id = UUID.fromString(s); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.id == null ? "" : this.id.toString()); + buf.writeString(this.name); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(ProxyLoginHandler handler) + { + handler.handleLoginSuccess(this); + } + + public UUID getId() + { + return this.id; + } + + public String getName() + { + return this.name; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/login/server/S03PacketEnableCompression.java b/proxy/src/main/java/net/minecraft/network/login/server/S03PacketEnableCompression.java new file mode 100755 index 0000000..31c0720 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/login/server/S03PacketEnableCompression.java @@ -0,0 +1,50 @@ +package net.minecraft.network.login.server; + +import java.io.IOException; + +import proxy.network.NetHandlerPlayServer.ProxyLoginHandler; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S03PacketEnableCompression implements Packet +{ + private int compressionTreshold; + + public S03PacketEnableCompression() + { + } + + public S03PacketEnableCompression(int compressionTresholdIn) + { + this.compressionTreshold = compressionTresholdIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.compressionTreshold = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.compressionTreshold); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(ProxyLoginHandler handler) + { + handler.handleEnableCompression(this); + } + + public int getCompressionTreshold() + { + return this.compressionTreshold; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C00PacketKeepAlive.java b/proxy/src/main/java/net/minecraft/network/play/client/C00PacketKeepAlive.java new file mode 100755 index 0000000..5104998 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C00PacketKeepAlive.java @@ -0,0 +1,50 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C00PacketKeepAlive implements Packet +{ + private int key; + + public C00PacketKeepAlive() + { + } + + public C00PacketKeepAlive(int key) + { + this.key = key; + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processKeepAlive(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.key = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.key); + } + + public int getKey() + { + return this.key; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C01PacketChatMessage.java b/proxy/src/main/java/net/minecraft/network/play/client/C01PacketChatMessage.java new file mode 100755 index 0000000..59a06c0 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C01PacketChatMessage.java @@ -0,0 +1,55 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C01PacketChatMessage implements Packet +{ + private String message; + + public C01PacketChatMessage() + { + } + + public C01PacketChatMessage(String messageIn) + { + if (messageIn.length() > 100) + { + messageIn = messageIn.substring(0, 100); + } + + this.message = messageIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.message = buf.readStringFromBuffer(100); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.message); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processChatMessage(this); + } + + public String getMessage() + { + return this.message; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C02PacketUseEntity.java b/proxy/src/main/java/net/minecraft/network/play/client/C02PacketUseEntity.java new file mode 100755 index 0000000..15ec404 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C02PacketUseEntity.java @@ -0,0 +1,63 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C02PacketUseEntity implements Packet +{ + private int entityId; + private C02PacketUseEntity.Action action; + private float hitX; + private float hitY; + private float hitZ; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.action = (C02PacketUseEntity.Action)buf.readEnumValue(C02PacketUseEntity.Action.class); + + if (this.action == C02PacketUseEntity.Action.INTERACT_AT) + { + this.hitX = buf.readFloat(); + this.hitY = buf.readFloat(); + this.hitZ = buf.readFloat(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeEnumValue(this.action); + + if (this.action == C02PacketUseEntity.Action.INTERACT_AT) + { + buf.writeFloat(this.hitX); + buf.writeFloat(this.hitY); + buf.writeFloat(this.hitZ); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processUseEntity(this); + } + + public static enum Action + { + INTERACT, + ATTACK, + INTERACT_AT; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C03PacketPlayer.java b/proxy/src/main/java/net/minecraft/network/play/client/C03PacketPlayer.java new file mode 100755 index 0000000..34abcf0 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C03PacketPlayer.java @@ -0,0 +1,118 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C03PacketPlayer implements Packet +{ + protected double x; + protected double y; + protected double z; + protected float yaw; + protected float pitch; + protected boolean onGround; + protected boolean moving; + protected boolean rotating; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processPlayer(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.onGround = buf.readUnsignedByte() != 0; + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.onGround ? 1 : 0); + } + + public static class C04PacketPlayerPosition extends C03PacketPlayer + { + public C04PacketPlayerPosition() + { + this.moving = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + super.readPacketData(buf); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeDouble(this.x); + buf.writeDouble(this.y); + buf.writeDouble(this.z); + super.writePacketData(buf); + } + } + + public static class C05PacketPlayerLook extends C03PacketPlayer + { + public C05PacketPlayerLook() + { + this.rotating = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + this.yaw = buf.readFloat(); + this.pitch = buf.readFloat(); + super.readPacketData(buf); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeFloat(this.yaw); + buf.writeFloat(this.pitch); + super.writePacketData(buf); + } + } + + public static class C06PacketPlayerPosLook extends C03PacketPlayer + { + public C06PacketPlayerPosLook() + { + this.moving = true; + this.rotating = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + this.yaw = buf.readFloat(); + this.pitch = buf.readFloat(); + super.readPacketData(buf); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeDouble(this.x); + buf.writeDouble(this.y); + buf.writeDouble(this.z); + buf.writeFloat(this.yaw); + buf.writeFloat(this.pitch); + super.writePacketData(buf); + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C07PacketPlayerDigging.java b/proxy/src/main/java/net/minecraft/network/play/client/C07PacketPlayerDigging.java new file mode 100755 index 0000000..4fef1a1 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C07PacketPlayerDigging.java @@ -0,0 +1,53 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class C07PacketPlayerDigging implements Packet +{ + private BlockPos position; + private byte facing; + private C07PacketPlayerDigging.Action status; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.status = (C07PacketPlayerDigging.Action)buf.readEnumValue(C07PacketPlayerDigging.Action.class); + this.position = buf.readBlockPos(); + this.facing = (byte)buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.status); + buf.writeBlockPos(this.position); + buf.writeByte(this.facing); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processPlayerDigging(this); + } + + public static enum Action + { + START_DESTROY_BLOCK, + ABORT_DESTROY_BLOCK, + STOP_DESTROY_BLOCK, + DROP_ALL_ITEMS, + DROP_ITEM, + RELEASE_USE_ITEM; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C08PacketPlayerBlockPlacement.java b/proxy/src/main/java/net/minecraft/network/play/client/C08PacketPlayerBlockPlacement.java new file mode 100755 index 0000000..0a7ace4 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C08PacketPlayerBlockPlacement.java @@ -0,0 +1,53 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; +import proxy.util.ItemStack; + +public class C08PacketPlayerBlockPlacement implements Packet +{ + private BlockPos position; + private int placedBlockDirection; + private ItemStack stack; + private float facingX; + private float facingY; + private float facingZ; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.position = buf.readBlockPos(); + this.placedBlockDirection = buf.readUnsignedByte(); + this.stack = buf.readItemStackFromBuffer(); + this.facingX = (float)buf.readUnsignedByte() / 16.0F; + this.facingY = (float)buf.readUnsignedByte() / 16.0F; + this.facingZ = (float)buf.readUnsignedByte() / 16.0F; + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.position); + buf.writeByte(this.placedBlockDirection); + buf.writeItemStackToBuffer(this.stack); + buf.writeByte((int)(this.facingX * 16.0F)); + buf.writeByte((int)(this.facingY * 16.0F)); + buf.writeByte((int)(this.facingZ * 16.0F)); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processPlayerBlockPlacement(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C09PacketHeldItemChange.java b/proxy/src/main/java/net/minecraft/network/play/client/C09PacketHeldItemChange.java new file mode 100755 index 0000000..1efad53 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C09PacketHeldItemChange.java @@ -0,0 +1,36 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C09PacketHeldItemChange implements Packet +{ + private int slotId; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.slotId = buf.readShort(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeShort(this.slotId); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processHeldItemChange(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C0APacketAnimation.java b/proxy/src/main/java/net/minecraft/network/play/client/C0APacketAnimation.java new file mode 100755 index 0000000..154c29a --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C0APacketAnimation.java @@ -0,0 +1,32 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C0APacketAnimation implements Packet +{ + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.handleAnimation(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C0BPacketEntityAction.java b/proxy/src/main/java/net/minecraft/network/play/client/C0BPacketEntityAction.java new file mode 100755 index 0000000..4dde06e --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C0BPacketEntityAction.java @@ -0,0 +1,53 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C0BPacketEntityAction implements Packet +{ + private int entityID; + private C0BPacketEntityAction.Action action; + private int auxData; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityID = buf.readVarIntFromBuffer(); + this.action = (C0BPacketEntityAction.Action)buf.readEnumValue(C0BPacketEntityAction.Action.class); + this.auxData = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityID); + buf.writeEnumValue(this.action); + buf.writeVarIntToBuffer(this.auxData); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processEntityAction(this); + } + + public static enum Action + { + START_SNEAKING, + STOP_SNEAKING, + STOP_SLEEPING, + START_SPRINTING, + STOP_SPRINTING, + RIDING_JUMP, + OPEN_INVENTORY; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C0CPacketInput.java b/proxy/src/main/java/net/minecraft/network/play/client/C0CPacketInput.java new file mode 100755 index 0000000..d323ebd --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C0CPacketInput.java @@ -0,0 +1,57 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C0CPacketInput implements Packet +{ + private float strafeSpeed; + private float forwardSpeed; + private boolean jumping; + private boolean sneaking; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.strafeSpeed = buf.readFloat(); + this.forwardSpeed = buf.readFloat(); + byte b0 = buf.readByte(); + this.jumping = (b0 & 1) > 0; + this.sneaking = (b0 & 2) > 0; + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeFloat(this.strafeSpeed); + buf.writeFloat(this.forwardSpeed); + byte b0 = 0; + + if (this.jumping) + { + b0 = (byte)(b0 | 1); + } + + if (this.sneaking) + { + b0 = (byte)(b0 | 2); + } + + buf.writeByte(b0); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processInput(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C0DPacketCloseWindow.java b/proxy/src/main/java/net/minecraft/network/play/client/C0DPacketCloseWindow.java new file mode 100755 index 0000000..72569d8 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C0DPacketCloseWindow.java @@ -0,0 +1,36 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C0DPacketCloseWindow implements Packet +{ + private int windowId; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processCloseWindow(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C0EPacketClickWindow.java b/proxy/src/main/java/net/minecraft/network/play/client/C0EPacketClickWindow.java new file mode 100755 index 0000000..d35f477 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C0EPacketClickWindow.java @@ -0,0 +1,52 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ItemStack; + +public class C0EPacketClickWindow implements Packet +{ + private int windowId; + private int slotId; + private int usedButton; + private short actionNumber; + private ItemStack clickedItem; + private int mode; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processClickWindow(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readByte(); + this.slotId = buf.readShort(); + this.usedButton = buf.readByte(); + this.actionNumber = buf.readShort(); + this.mode = buf.readByte(); + this.clickedItem = buf.readItemStackFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeShort(this.slotId); + buf.writeByte(this.usedButton); + buf.writeShort(this.actionNumber); + buf.writeByte(this.mode); + buf.writeItemStackToBuffer(this.clickedItem); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C0FPacketConfirmTransaction.java b/proxy/src/main/java/net/minecraft/network/play/client/C0FPacketConfirmTransaction.java new file mode 100755 index 0000000..52d45da --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C0FPacketConfirmTransaction.java @@ -0,0 +1,42 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C0FPacketConfirmTransaction implements Packet +{ + private int windowId; + private short uid; + private boolean accepted; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processConfirmTransaction(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readByte(); + this.uid = buf.readShort(); + this.accepted = buf.readByte() != 0; + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeShort(this.uid); + buf.writeByte(this.accepted ? 1 : 0); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C10PacketCreativeInventoryAction.java b/proxy/src/main/java/net/minecraft/network/play/client/C10PacketCreativeInventoryAction.java new file mode 100755 index 0000000..af263d4 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C10PacketCreativeInventoryAction.java @@ -0,0 +1,45 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ItemStack; + +public class C10PacketCreativeInventoryAction implements Packet +{ + private int slotId; + private ItemStack stack; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processCreativeInventoryAction(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.slotId = buf.readShort(); + this.stack = buf.readItemStackFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeShort(this.slotId); + buf.writeItemStackToBuffer(this.stack); + } + + public ItemStack getStack() + { + return this.stack; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C11PacketEnchantItem.java b/proxy/src/main/java/net/minecraft/network/play/client/C11PacketEnchantItem.java new file mode 100755 index 0000000..ec05b65 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C11PacketEnchantItem.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C11PacketEnchantItem implements Packet +{ + private int windowId; + private int button; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processEnchantItem(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readByte(); + this.button = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeByte(this.button); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C12PacketUpdateSign.java b/proxy/src/main/java/net/minecraft/network/play/client/C12PacketUpdateSign.java new file mode 100755 index 0000000..5803222 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C12PacketUpdateSign.java @@ -0,0 +1,59 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; +import proxy.util.ChatComponent; + +public class C12PacketUpdateSign implements Packet +{ + private BlockPos pos; + private ChatComponent[] lines; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.pos = buf.readBlockPos(); + this.lines = new ChatComponent[4]; + + for (int i = 0; i < 4; ++i) + { + String s = buf.readStringFromBuffer(384); + ChatComponent ichatcomponent = ChatComponent.Serializer.jsonToComponent(s); + this.lines[i] = ichatcomponent; + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.pos); + + for (int i = 0; i < 4; ++i) + { + ChatComponent ichatcomponent = this.lines[i]; + String s = ChatComponent.Serializer.componentToJson(ichatcomponent); + buf.writeString(s); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processUpdateSign(this); + } + + public ChatComponent[] getLines() + { + return this.lines; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C13PacketPlayerAbilities.java b/proxy/src/main/java/net/minecraft/network/play/client/C13PacketPlayerAbilities.java new file mode 100755 index 0000000..b6f31ae --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C13PacketPlayerAbilities.java @@ -0,0 +1,121 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C13PacketPlayerAbilities implements Packet +{ + private boolean invulnerable; + private boolean flying; + private boolean allowFlying; + private boolean creativeMode; + private float flySpeed; + private float walkSpeed; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + byte b0 = buf.readByte(); + this.setInvulnerable((b0 & 1) > 0); + this.setFlying((b0 & 2) > 0); + this.setAllowFlying((b0 & 4) > 0); + this.setCreativeMode((b0 & 8) > 0); + this.setFlySpeed(buf.readFloat()); + this.setWalkSpeed(buf.readFloat()); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + byte b0 = 0; + + if (this.isInvulnerable()) + { + b0 = (byte)(b0 | 1); + } + + if (this.isFlying()) + { + b0 = (byte)(b0 | 2); + } + + if (this.isAllowFlying()) + { + b0 = (byte)(b0 | 4); + } + + if (this.isCreativeMode()) + { + b0 = (byte)(b0 | 8); + } + + buf.writeByte(b0); + buf.writeFloat(this.flySpeed); + buf.writeFloat(this.walkSpeed); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processPlayerAbilities(this); + } + + public boolean isInvulnerable() + { + return this.invulnerable; + } + + public void setInvulnerable(boolean isInvulnerable) + { + this.invulnerable = isInvulnerable; + } + + public boolean isFlying() + { + return this.flying; + } + + public void setFlying(boolean isFlying) + { + this.flying = isFlying; + } + + public boolean isAllowFlying() + { + return this.allowFlying; + } + + public void setAllowFlying(boolean isAllowFlying) + { + this.allowFlying = isAllowFlying; + } + + public boolean isCreativeMode() + { + return this.creativeMode; + } + + public void setCreativeMode(boolean isCreativeMode) + { + this.creativeMode = isCreativeMode; + } + + public void setFlySpeed(float flySpeedIn) + { + this.flySpeed = flySpeedIn; + } + + public void setWalkSpeed(float walkSpeedIn) + { + this.walkSpeed = walkSpeedIn; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C14PacketTabComplete.java b/proxy/src/main/java/net/minecraft/network/play/client/C14PacketTabComplete.java new file mode 100755 index 0000000..c95a196 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C14PacketTabComplete.java @@ -0,0 +1,76 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class C14PacketTabComplete implements Packet +{ + private String message; + private BlockPos targetBlock; + + public C14PacketTabComplete() + { + } + + public C14PacketTabComplete(String msg) + { + this(msg, (BlockPos)null); + } + + public C14PacketTabComplete(String msg, BlockPos target) + { + this.message = msg; + this.targetBlock = target; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.message = buf.readStringFromBuffer(32767); + boolean flag = buf.readBoolean(); + + if (flag) + { + this.targetBlock = buf.readBlockPos(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.message.length() > 32767 ? this.message.substring(0, 32767) : this.message); + boolean flag = this.targetBlock != null; + buf.writeBoolean(flag); + + if (flag) + { + buf.writeBlockPos(this.targetBlock); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processTabComplete(this); + } + + public String getMessage() + { + return this.message; + } + + public BlockPos getTargetBlock() + { + return this.targetBlock; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C15PacketClientSettings.java b/proxy/src/main/java/net/minecraft/network/play/client/C15PacketClientSettings.java new file mode 100755 index 0000000..e197eb1 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C15PacketClientSettings.java @@ -0,0 +1,48 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C15PacketClientSettings implements Packet +{ + private String lang; + private int view; + private byte chatVisibility; + private boolean enableColors; + private int modelPartFlags; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.lang = buf.readStringFromBuffer(7); + this.view = buf.readByte(); + this.chatVisibility = buf.readByte(); + this.enableColors = buf.readBoolean(); + this.modelPartFlags = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.lang); + buf.writeByte(this.view); + buf.writeByte(this.chatVisibility); + buf.writeBoolean(this.enableColors); + buf.writeByte(this.modelPartFlags); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processClientSettings(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C16PacketClientStatus.java b/proxy/src/main/java/net/minecraft/network/play/client/C16PacketClientStatus.java new file mode 100755 index 0000000..e050804 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C16PacketClientStatus.java @@ -0,0 +1,43 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C16PacketClientStatus implements Packet +{ + private C16PacketClientStatus.EnumState status; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.status = (C16PacketClientStatus.EnumState)buf.readEnumValue(C16PacketClientStatus.EnumState.class); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.status); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processClientStatus(this); + } + + public static enum EnumState + { + PERFORM_RESPAWN, + REQUEST_STATS, + OPEN_INVENTORY_ACHIEVEMENT; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C17PacketCustomPayload.java b/proxy/src/main/java/net/minecraft/network/play/client/C17PacketCustomPayload.java new file mode 100755 index 0000000..9520b6b --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C17PacketCustomPayload.java @@ -0,0 +1,61 @@ +package net.minecraft.network.play.client; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C17PacketCustomPayload implements Packet +{ + private String channel; + private PacketBuffer data; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.channel = buf.readStringFromBuffer(20); + int i = buf.readableBytes(); + + if (i >= 0 && i <= 32767) + { + this.data = new PacketBuffer(buf.readBytes(i)); + } + else + { + throw new IOException("Payload may not be larger than 32767 bytes"); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.channel); + buf.writeBytes((ByteBuf)this.data); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.processVanilla250Packet(this); + } + + public String getChannelName() + { + return this.channel; + } + + public PacketBuffer getBufferData() + { + return new PacketBuffer(Unpooled.wrappedBuffer(this.data)); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C18PacketSpectate.java b/proxy/src/main/java/net/minecraft/network/play/client/C18PacketSpectate.java new file mode 100755 index 0000000..f681712 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C18PacketSpectate.java @@ -0,0 +1,37 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; +import java.util.UUID; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C18PacketSpectate implements Packet +{ + private UUID id; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.id = buf.readUuid(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeUuid(this.id); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.handleSpectate(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/client/C19PacketResourcePackStatus.java b/proxy/src/main/java/net/minecraft/network/play/client/C19PacketResourcePackStatus.java new file mode 100755 index 0000000..5651490 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/client/C19PacketResourcePackStatus.java @@ -0,0 +1,47 @@ +package net.minecraft.network.play.client; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C19PacketResourcePackStatus implements Packet +{ + private String hash; + private C19PacketResourcePackStatus.Action status; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.hash = buf.readStringFromBuffer(40); + this.status = (C19PacketResourcePackStatus.Action)buf.readEnumValue(C19PacketResourcePackStatus.Action.class); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.hash); + buf.writeEnumValue(this.status); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayServer handler) + { + handler.handleResourcePackStatus(this); + } + + public static enum Action + { + SUCCESSFULLY_LOADED, + DECLINED, + FAILED_DOWNLOAD, + ACCEPTED; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S00PacketKeepAlive.java b/proxy/src/main/java/net/minecraft/network/play/server/S00PacketKeepAlive.java new file mode 100755 index 0000000..3477819 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S00PacketKeepAlive.java @@ -0,0 +1,50 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S00PacketKeepAlive implements Packet +{ + private int id; + + public S00PacketKeepAlive() + { + } + + public S00PacketKeepAlive(int idIn) + { + this.id = idIn; + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleKeepAlive(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.id = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.id); + } + + public int func_149134_c() + { + return this.id; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S01PacketJoinGame.java b/proxy/src/main/java/net/minecraft/network/play/server/S01PacketJoinGame.java new file mode 100755 index 0000000..177bf80 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S01PacketJoinGame.java @@ -0,0 +1,121 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S01PacketJoinGame implements Packet +{ + private int entityId; + private boolean hardcoreMode; + private byte gameType; + private int dimension; + private byte difficulty; + private int maxPlayers; + private String worldType; + private boolean reducedDebugInfo; + + public S01PacketJoinGame() + { + } + + public S01PacketJoinGame(int entityIdIn, boolean spectator) + { + this.entityId = entityIdIn; + this.dimension = 0; + this.difficulty = 2; + this.gameType = (byte)(spectator ? 3 : 0); + this.maxPlayers = 1; + this.hardcoreMode = false; + this.worldType = "flat"; + this.reducedDebugInfo = false; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readInt(); + int i = buf.readUnsignedByte(); + this.hardcoreMode = (i & 8) == 8; + i = i & -9; + this.gameType = (byte)i; + this.dimension = buf.readByte(); + this.difficulty = (byte)buf.readUnsignedByte(); + this.maxPlayers = buf.readUnsignedByte(); + this.worldType = buf.readStringFromBuffer(16); + this.reducedDebugInfo = buf.readBoolean(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.entityId); + int i = this.gameType; + + if (this.hardcoreMode) + { + i |= 8; + } + + buf.writeByte(i); + buf.writeByte(this.dimension); + buf.writeByte(this.difficulty); + buf.writeByte(this.maxPlayers); + buf.writeString(this.worldType); + buf.writeBoolean(this.reducedDebugInfo); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleJoinGame(this); + } + + public int getEntityId() + { + return this.entityId; + } + + public boolean isHardcoreMode() + { + return this.hardcoreMode; + } + + public byte getGameType() + { + return this.gameType; + } + + public int getDimension() + { + return this.dimension; + } + + public byte getDifficulty() + { + return this.difficulty; + } + + public int getMaxPlayers() + { + return this.maxPlayers; + } + + public String getWorldType() + { + return this.worldType; + } + + public boolean isReducedDebugInfo() + { + return this.reducedDebugInfo; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S02PacketChat.java b/proxy/src/main/java/net/minecraft/network/play/server/S02PacketChat.java new file mode 100755 index 0000000..9201716 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S02PacketChat.java @@ -0,0 +1,51 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; + +public class S02PacketChat implements Packet +{ + private ChatComponent chatComponent; + private byte type; + + public S02PacketChat() + { + } + + public S02PacketChat(String message) + { + this.chatComponent = new ChatComponentText(message); + this.type = 0; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.chatComponent = buf.readChatComponent(); + this.type = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeChatComponent(this.chatComponent); + buf.writeByte(this.type); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleChat(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S03PacketTimeUpdate.java b/proxy/src/main/java/net/minecraft/network/play/server/S03PacketTimeUpdate.java new file mode 100755 index 0000000..59f51ce --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S03PacketTimeUpdate.java @@ -0,0 +1,59 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S03PacketTimeUpdate implements Packet +{ + private long totalWorldTime; + private long worldTime; + + public S03PacketTimeUpdate() + { + } + + public S03PacketTimeUpdate(long totalTimeIn, boolean doDayLightCycle) + { + this.totalWorldTime = totalTimeIn; + this.worldTime = totalTimeIn; + + if (!doDayLightCycle) + { + this.worldTime = -this.worldTime; + + if (this.worldTime == 0L) + { + this.worldTime = -1L; + } + } + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.totalWorldTime = buf.readLong(); + this.worldTime = buf.readLong(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeLong(this.totalWorldTime); + buf.writeLong(this.worldTime); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleTimeUpdate(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S04PacketEntityEquipment.java b/proxy/src/main/java/net/minecraft/network/play/server/S04PacketEntityEquipment.java new file mode 100755 index 0000000..18d7b11 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S04PacketEntityEquipment.java @@ -0,0 +1,43 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ItemStack; + +public class S04PacketEntityEquipment implements Packet +{ + private int entityID; + private int equipmentSlot; + private ItemStack itemStack; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityID = buf.readVarIntFromBuffer(); + this.equipmentSlot = buf.readShort(); + this.itemStack = buf.readItemStackFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityID); + buf.writeShort(this.equipmentSlot); + buf.writeItemStackToBuffer(this.itemStack); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityEquipment(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S05PacketSpawnPosition.java b/proxy/src/main/java/net/minecraft/network/play/server/S05PacketSpawnPosition.java new file mode 100755 index 0000000..94bac60 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S05PacketSpawnPosition.java @@ -0,0 +1,37 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S05PacketSpawnPosition implements Packet +{ + private BlockPos spawnBlockPos; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.spawnBlockPos = buf.readBlockPos(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.spawnBlockPos); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnPosition(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S06PacketUpdateHealth.java b/proxy/src/main/java/net/minecraft/network/play/server/S06PacketUpdateHealth.java new file mode 100755 index 0000000..54ea08f --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S06PacketUpdateHealth.java @@ -0,0 +1,42 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S06PacketUpdateHealth implements Packet +{ + private float health; + private int foodLevel; + private float saturationLevel; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.health = buf.readFloat(); + this.foodLevel = buf.readVarIntFromBuffer(); + this.saturationLevel = buf.readFloat(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeFloat(this.health); + buf.writeVarIntToBuffer(this.foodLevel); + buf.writeFloat(this.saturationLevel); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleUpdateHealth(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S07PacketRespawn.java b/proxy/src/main/java/net/minecraft/network/play/server/S07PacketRespawn.java new file mode 100755 index 0000000..00ff950 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S07PacketRespawn.java @@ -0,0 +1,57 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S07PacketRespawn implements Packet +{ + private int dimensionID; + private byte difficulty; + private byte gameType; + private String worldType; + + public S07PacketRespawn() + { + } + + public S07PacketRespawn(S01PacketJoinGame pkt) + { + this.dimensionID = pkt.getDimension(); + this.difficulty = pkt.getDifficulty(); + this.gameType = pkt.getGameType(); + this.worldType = pkt.getWorldType(); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleRespawn(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.dimensionID = buf.readInt(); + this.difficulty = (byte)buf.readUnsignedByte(); + this.gameType = (byte)buf.readUnsignedByte(); + this.worldType = buf.readStringFromBuffer(16); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.dimensionID); + buf.writeByte(this.difficulty); + buf.writeByte(this.gameType); + buf.writeString(this.worldType); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S08PacketPlayerPosLook.java b/proxy/src/main/java/net/minecraft/network/play/server/S08PacketPlayerPosLook.java new file mode 100755 index 0000000..2769d4c --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S08PacketPlayerPosLook.java @@ -0,0 +1,121 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S08PacketPlayerPosLook implements Packet +{ + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + private Set field_179835_f; + + public S08PacketPlayerPosLook() + { + } + + public S08PacketPlayerPosLook(double xIn, double yIn, double zIn, float yawIn, float pitchIn) + { + this.x = xIn; + this.y = yIn; + this.z = zIn; + this.yaw = yawIn; + this.pitch = pitchIn; + this.field_179835_f = Collections.emptySet(); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + this.yaw = buf.readFloat(); + this.pitch = buf.readFloat(); + this.field_179835_f = S08PacketPlayerPosLook.EnumFlags.func_180053_a(buf.readUnsignedByte()); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeDouble(this.x); + buf.writeDouble(this.y); + buf.writeDouble(this.z); + buf.writeFloat(this.yaw); + buf.writeFloat(this.pitch); + buf.writeByte(S08PacketPlayerPosLook.EnumFlags.func_180056_a(this.field_179835_f)); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handlePlayerPosLook(this); + } + + public static enum EnumFlags + { + X(0), + Y(1), + Z(2), + Y_ROT(3), + X_ROT(4); + + private int field_180058_f; + + private EnumFlags(int p_i45992_3_) + { + this.field_180058_f = p_i45992_3_; + } + + private int func_180055_a() + { + return 1 << this.field_180058_f; + } + + private boolean func_180054_b(int p_180054_1_) + { + return (p_180054_1_ & this.func_180055_a()) == this.func_180055_a(); + } + + public static Set func_180053_a(int p_180053_0_) + { + Set set = EnumSet.noneOf(S08PacketPlayerPosLook.EnumFlags.class); + + for (S08PacketPlayerPosLook.EnumFlags s08packetplayerposlook$enumflags : values()) + { + if (s08packetplayerposlook$enumflags.func_180054_b(p_180053_0_)) + { + set.add(s08packetplayerposlook$enumflags); + } + } + + return set; + } + + public static int func_180056_a(Set p_180056_0_) + { + int i = 0; + + for (S08PacketPlayerPosLook.EnumFlags s08packetplayerposlook$enumflags : p_180056_0_) + { + i |= s08packetplayerposlook$enumflags.func_180055_a(); + } + + return i; + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S09PacketHeldItemChange.java b/proxy/src/main/java/net/minecraft/network/play/server/S09PacketHeldItemChange.java new file mode 100755 index 0000000..6c4fd34 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S09PacketHeldItemChange.java @@ -0,0 +1,36 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S09PacketHeldItemChange implements Packet +{ + private int heldItemHotbarIndex; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.heldItemHotbarIndex = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.heldItemHotbarIndex); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleHeldItemChange(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S0APacketUseBed.java b/proxy/src/main/java/net/minecraft/network/play/server/S0APacketUseBed.java new file mode 100755 index 0000000..2e5ab49 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S0APacketUseBed.java @@ -0,0 +1,40 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S0APacketUseBed implements Packet +{ + private int playerID; + private BlockPos bedPos; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.playerID = buf.readVarIntFromBuffer(); + this.bedPos = buf.readBlockPos(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.playerID); + buf.writeBlockPos(this.bedPos); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleUseBed(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S0BPacketAnimation.java b/proxy/src/main/java/net/minecraft/network/play/server/S0BPacketAnimation.java new file mode 100755 index 0000000..28ae37a --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S0BPacketAnimation.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S0BPacketAnimation implements Packet +{ + private int entityId; + private int type; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.type = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.type); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleAnimation(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S0CPacketSpawnPlayer.java b/proxy/src/main/java/net/minecraft/network/play/server/S0CPacketSpawnPlayer.java new file mode 100755 index 0000000..a74a93e --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S0CPacketSpawnPlayer.java @@ -0,0 +1,80 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.List; +import java.util.UUID; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.DataWatcher; +import proxy.util.MathHelper; + +public class S0CPacketSpawnPlayer implements Packet +{ + private int entityId; + private UUID playerId; + private int x; + private int y; + private int z; + private byte yaw; + private byte pitch; + private int currentItem; + private List field_148958_j; + + public S0CPacketSpawnPlayer() + { + } + + public S0CPacketSpawnPlayer(int id, UUID uuid, double x, double y, double z, float yaw, float pitch) + { + this.entityId = id; + this.playerId = uuid; + this.x = MathHelper.floor_double(x * 32.0D); + this.y = MathHelper.floor_double(y * 32.0D); + this.z = MathHelper.floor_double(z * 32.0D); + this.yaw = (byte)((int)(yaw * 256.0F / 360.0F)); + this.pitch = (byte)((int)(pitch * 256.0F / 360.0F)); + this.currentItem = 0; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.playerId = buf.readUuid(); + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.currentItem = buf.readShort(); + this.field_148958_j = DataWatcher.readWatchedListFromPacketBuffer(buf); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeUuid(this.playerId); + buf.writeInt(this.x); + buf.writeInt(this.y); + buf.writeInt(this.z); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeShort(this.currentItem); + DataWatcher.writeWatchedListToPacketBuffer(this.field_148958_j, buf); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnPlayer(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S0DPacketCollectItem.java b/proxy/src/main/java/net/minecraft/network/play/server/S0DPacketCollectItem.java new file mode 100755 index 0000000..df2bbf7 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S0DPacketCollectItem.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S0DPacketCollectItem implements Packet +{ + private int collectedItemEntityId; + private int entityId; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.collectedItemEntityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.collectedItemEntityId); + buf.writeVarIntToBuffer(this.entityId); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleCollectItem(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S0EPacketSpawnObject.java b/proxy/src/main/java/net/minecraft/network/play/server/S0EPacketSpawnObject.java new file mode 100755 index 0000000..e151555 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S0EPacketSpawnObject.java @@ -0,0 +1,74 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S0EPacketSpawnObject implements Packet +{ + private int entityId; + private int x; + private int y; + private int z; + private int speedX; + private int speedY; + private int speedZ; + private int pitch; + private int yaw; + private int type; + private int field_149020_k; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.type = buf.readByte(); + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + this.pitch = buf.readByte(); + this.yaw = buf.readByte(); + this.field_149020_k = buf.readInt(); + + if (this.field_149020_k > 0) + { + this.speedX = buf.readShort(); + this.speedY = buf.readShort(); + this.speedZ = buf.readShort(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.type); + buf.writeInt(this.x); + buf.writeInt(this.y); + buf.writeInt(this.z); + buf.writeByte(this.pitch); + buf.writeByte(this.yaw); + buf.writeInt(this.field_149020_k); + + if (this.field_149020_k > 0) + { + buf.writeShort(this.speedX); + buf.writeShort(this.speedY); + buf.writeShort(this.speedZ); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnObject(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S0FPacketSpawnMob.java b/proxy/src/main/java/net/minecraft/network/play/server/S0FPacketSpawnMob.java new file mode 100755 index 0000000..4503615 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S0FPacketSpawnMob.java @@ -0,0 +1,71 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.List; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.DataWatcher; + +public class S0FPacketSpawnMob implements Packet +{ + private int entityId; + private int type; + private int x; + private int y; + private int z; + private int velocityX; + private int velocityY; + private int velocityZ; + private byte yaw; + private byte pitch; + private byte headPitch; + private List watcher; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.type = buf.readByte() & 255; + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.headPitch = buf.readByte(); + this.velocityX = buf.readShort(); + this.velocityY = buf.readShort(); + this.velocityZ = buf.readShort(); + this.watcher = DataWatcher.readWatchedListFromPacketBuffer(buf); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.type & 255); + buf.writeInt(this.x); + buf.writeInt(this.y); + buf.writeInt(this.z); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeByte(this.headPitch); + buf.writeShort(this.velocityX); + buf.writeShort(this.velocityY); + buf.writeShort(this.velocityZ); + DataWatcher.writeWatchedListToPacketBuffer(this.watcher, buf); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnMob(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S10PacketSpawnPainting.java b/proxy/src/main/java/net/minecraft/network/play/server/S10PacketSpawnPainting.java new file mode 100755 index 0000000..0514760 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S10PacketSpawnPainting.java @@ -0,0 +1,46 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S10PacketSpawnPainting implements Packet +{ + private int entityID; + private BlockPos position; + private byte facing; + private String title; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityID = buf.readVarIntFromBuffer(); + this.title = buf.readStringFromBuffer(13); + this.position = buf.readBlockPos(); + this.facing = (byte)buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityID); + buf.writeString(this.title); + buf.writeBlockPos(this.position); + buf.writeByte(this.facing); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnPainting(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S11PacketSpawnExperienceOrb.java b/proxy/src/main/java/net/minecraft/network/play/server/S11PacketSpawnExperienceOrb.java new file mode 100755 index 0000000..c399568 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S11PacketSpawnExperienceOrb.java @@ -0,0 +1,48 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S11PacketSpawnExperienceOrb implements Packet +{ + private int entityID; + private int posX; + private int posY; + private int posZ; + private int xpValue; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityID = buf.readVarIntFromBuffer(); + this.posX = buf.readInt(); + this.posY = buf.readInt(); + this.posZ = buf.readInt(); + this.xpValue = buf.readShort(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityID); + buf.writeInt(this.posX); + buf.writeInt(this.posY); + buf.writeInt(this.posZ); + buf.writeShort(this.xpValue); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnExperienceOrb(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S12PacketEntityVelocity.java b/proxy/src/main/java/net/minecraft/network/play/server/S12PacketEntityVelocity.java new file mode 100755 index 0000000..5951d78 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S12PacketEntityVelocity.java @@ -0,0 +1,45 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S12PacketEntityVelocity implements Packet +{ + private int entityID; + private int motionX; + private int motionY; + private int motionZ; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityID = buf.readVarIntFromBuffer(); + this.motionX = buf.readShort(); + this.motionY = buf.readShort(); + this.motionZ = buf.readShort(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityID); + buf.writeShort(this.motionX); + buf.writeShort(this.motionY); + buf.writeShort(this.motionZ); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityVelocity(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S13PacketDestroyEntities.java b/proxy/src/main/java/net/minecraft/network/play/server/S13PacketDestroyEntities.java new file mode 100755 index 0000000..d115b9f --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S13PacketDestroyEntities.java @@ -0,0 +1,46 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S13PacketDestroyEntities implements Packet +{ + private int[] entityIDs; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityIDs = new int[buf.readVarIntFromBuffer()]; + + for (int i = 0; i < this.entityIDs.length; ++i) + { + this.entityIDs[i] = buf.readVarIntFromBuffer(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityIDs.length); + + for (int i = 0; i < this.entityIDs.length; ++i) + { + buf.writeVarIntToBuffer(this.entityIDs[i]); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleDestroyEntities(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S14PacketEntity.java b/proxy/src/main/java/net/minecraft/network/play/server/S14PacketEntity.java new file mode 100755 index 0000000..09203b8 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S14PacketEntity.java @@ -0,0 +1,118 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S14PacketEntity implements Packet +{ + protected int entityId; + protected byte posX; + protected byte posY; + protected byte posZ; + protected byte yaw; + protected byte pitch; + protected boolean onGround; + protected boolean field_149069_g; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityMovement(this); + } + + public static class S15PacketEntityRelMove extends S14PacketEntity + { + public void readPacketData(PacketBuffer buf) throws IOException + { + super.readPacketData(buf); + this.posX = buf.readByte(); + this.posY = buf.readByte(); + this.posZ = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + super.writePacketData(buf); + buf.writeByte(this.posX); + buf.writeByte(this.posY); + buf.writeByte(this.posZ); + buf.writeBoolean(this.onGround); + } + } + + public static class S16PacketEntityLook extends S14PacketEntity + { + public S16PacketEntityLook() + { + this.field_149069_g = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + super.readPacketData(buf); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + super.writePacketData(buf); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeBoolean(this.onGround); + } + } + + public static class S17PacketEntityLookMove extends S14PacketEntity + { + public S17PacketEntityLookMove() + { + this.field_149069_g = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + super.readPacketData(buf); + this.posX = buf.readByte(); + this.posY = buf.readByte(); + this.posZ = buf.readByte(); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + super.writePacketData(buf); + buf.writeByte(this.posX); + buf.writeByte(this.posY); + buf.writeByte(this.posZ); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeBoolean(this.onGround); + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S18PacketEntityTeleport.java b/proxy/src/main/java/net/minecraft/network/play/server/S18PacketEntityTeleport.java new file mode 100755 index 0000000..301f06e --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S18PacketEntityTeleport.java @@ -0,0 +1,54 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S18PacketEntityTeleport implements Packet +{ + private int entityId; + private int posX; + private int posY; + private int posZ; + private byte yaw; + private byte pitch; + private boolean onGround; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.posX = buf.readInt(); + this.posY = buf.readInt(); + this.posZ = buf.readInt(); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeInt(this.posX); + buf.writeInt(this.posY); + buf.writeInt(this.posZ); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeBoolean(this.onGround); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityTeleport(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S19PacketEntityHeadLook.java b/proxy/src/main/java/net/minecraft/network/play/server/S19PacketEntityHeadLook.java new file mode 100755 index 0000000..77bdd70 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S19PacketEntityHeadLook.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S19PacketEntityHeadLook implements Packet +{ + private int entityId; + private byte yaw; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.yaw = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.yaw); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityHeadLook(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S19PacketEntityStatus.java b/proxy/src/main/java/net/minecraft/network/play/server/S19PacketEntityStatus.java new file mode 100755 index 0000000..19028e6 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S19PacketEntityStatus.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S19PacketEntityStatus implements Packet +{ + private int entityId; + private byte logicOpcode; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readInt(); + this.logicOpcode = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.entityId); + buf.writeByte(this.logicOpcode); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityStatus(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S1BPacketEntityAttach.java b/proxy/src/main/java/net/minecraft/network/play/server/S1BPacketEntityAttach.java new file mode 100755 index 0000000..c549c82 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S1BPacketEntityAttach.java @@ -0,0 +1,42 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S1BPacketEntityAttach implements Packet +{ + private int leash; + private int entityId; + private int vehicleEntityId; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readInt(); + this.vehicleEntityId = buf.readInt(); + this.leash = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.entityId); + buf.writeInt(this.vehicleEntityId); + buf.writeByte(this.leash); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityAttach(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S1CPacketEntityMetadata.java b/proxy/src/main/java/net/minecraft/network/play/server/S1CPacketEntityMetadata.java new file mode 100755 index 0000000..5672fcb --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S1CPacketEntityMetadata.java @@ -0,0 +1,41 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.List; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.DataWatcher; + +public class S1CPacketEntityMetadata implements Packet +{ + private int entityId; + private List field_149378_b; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.field_149378_b = DataWatcher.readWatchedListFromPacketBuffer(buf); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + DataWatcher.writeWatchedListToPacketBuffer(this.field_149378_b, buf); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityMetadata(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S1DPacketEntityEffect.java b/proxy/src/main/java/net/minecraft/network/play/server/S1DPacketEntityEffect.java new file mode 100755 index 0000000..9a9b61d --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S1DPacketEntityEffect.java @@ -0,0 +1,48 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S1DPacketEntityEffect implements Packet +{ + private int entityId; + private byte effectId; + private byte amplifier; + private int duration; + private byte hideParticles; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.effectId = buf.readByte(); + this.amplifier = buf.readByte(); + this.duration = buf.readVarIntFromBuffer(); + this.hideParticles = buf.readByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.effectId); + buf.writeByte(this.amplifier); + buf.writeVarIntToBuffer(this.duration); + buf.writeByte(this.hideParticles); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityEffect(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S1EPacketRemoveEntityEffect.java b/proxy/src/main/java/net/minecraft/network/play/server/S1EPacketRemoveEntityEffect.java new file mode 100755 index 0000000..7667af2 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S1EPacketRemoveEntityEffect.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S1EPacketRemoveEntityEffect implements Packet +{ + private int entityId; + private int effectId; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.effectId = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.effectId); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleRemoveEntityEffect(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S1FPacketSetExperience.java b/proxy/src/main/java/net/minecraft/network/play/server/S1FPacketSetExperience.java new file mode 100755 index 0000000..31f3c5a --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S1FPacketSetExperience.java @@ -0,0 +1,42 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S1FPacketSetExperience implements Packet +{ + private float field_149401_a; + private int totalExperience; + private int level; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.field_149401_a = buf.readFloat(); + this.level = buf.readVarIntFromBuffer(); + this.totalExperience = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeFloat(this.field_149401_a); + buf.writeVarIntToBuffer(this.level); + buf.writeVarIntToBuffer(this.totalExperience); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSetExperience(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S20PacketEntityProperties.java b/proxy/src/main/java/net/minecraft/network/play/server/S20PacketEntityProperties.java new file mode 100755 index 0000000..e8a43be --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S20PacketEntityProperties.java @@ -0,0 +1,127 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +import com.google.common.collect.Lists; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S20PacketEntityProperties implements Packet +{ + private int entityId; + private final List field_149444_b = Lists.newArrayList(); + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + int i = buf.readInt(); + + for (int j = 0; j < i; ++j) + { + String s = buf.readStringFromBuffer(64); + double d0 = buf.readDouble(); + List list = Lists.newArrayList(); + int k = buf.readVarIntFromBuffer(); + + for (int l = 0; l < k; ++l) + { + UUID uuid = buf.readUuid(); + list.add(new AttributeModifier(uuid, buf.readDouble(), buf.readByte())); + } + + this.field_149444_b.add(new S20PacketEntityProperties.Snapshot(s, d0, list)); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeInt(this.field_149444_b.size()); + + for (S20PacketEntityProperties.Snapshot s20packetentityproperties$snapshot : this.field_149444_b) + { + buf.writeString(s20packetentityproperties$snapshot.func_151409_a()); + buf.writeDouble(s20packetentityproperties$snapshot.func_151410_b()); + buf.writeVarIntToBuffer(s20packetentityproperties$snapshot.func_151408_c().size()); + + for (AttributeModifier attributemodifier : s20packetentityproperties$snapshot.func_151408_c()) + { + buf.writeUuid(attributemodifier.getID()); + buf.writeDouble(attributemodifier.getAmount()); + buf.writeByte(attributemodifier.getOperation()); + } + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityProperties(this); + } + + private class AttributeModifier { + private final UUID id; + private final double amount; + private final byte operation; + + public AttributeModifier(UUID id, double amount, byte operation) { + this.id = id; + this.amount = amount; + this.operation = operation; + } + + public UUID getID() { + return this.id; + } + + public double getAmount() { + return this.amount; + } + + public byte getOperation() { + return this.operation; + } + } + + public class Snapshot + { + private final String field_151412_b; + private final double field_151413_c; + private final Collection field_151411_d; + + public Snapshot(String p_i45235_2_, double p_i45235_3_, Collection p_i45235_5_) + { + this.field_151412_b = p_i45235_2_; + this.field_151413_c = p_i45235_3_; + this.field_151411_d = p_i45235_5_; + } + + public String func_151409_a() + { + return this.field_151412_b; + } + + public double func_151410_b() + { + return this.field_151413_c; + } + + public Collection func_151408_c() + { + return this.field_151411_d; + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S21PacketChunkData.java b/proxy/src/main/java/net/minecraft/network/play/server/S21PacketChunkData.java new file mode 100755 index 0000000..fc1586f --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S21PacketChunkData.java @@ -0,0 +1,54 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S21PacketChunkData implements Packet +{ + private int chunkX; + private int chunkZ; + private S21PacketChunkData.Extracted extractedData; + private boolean field_149279_g; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.chunkX = buf.readInt(); + this.chunkZ = buf.readInt(); + this.field_149279_g = buf.readBoolean(); + this.extractedData = new S21PacketChunkData.Extracted(); + this.extractedData.dataSize = buf.readShort(); + this.extractedData.data = buf.readByteArray(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.chunkX); + buf.writeInt(this.chunkZ); + buf.writeBoolean(this.field_149279_g); + buf.writeShort((short)(this.extractedData.dataSize & 65535)); + buf.writeByteArray(this.extractedData.data); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleChunkData(this); + } + + public static class Extracted + { + public byte[] data; + public int dataSize; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S22PacketMultiBlockChange.java b/proxy/src/main/java/net/minecraft/network/play/server/S22PacketMultiBlockChange.java new file mode 100755 index 0000000..0f649c4 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S22PacketMultiBlockChange.java @@ -0,0 +1,75 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S22PacketMultiBlockChange implements Packet +{ + private int chunkPosCoordX; + private int chunkPosCoordZ; + private S22PacketMultiBlockChange.BlockUpdateData[] changedBlocks; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.chunkPosCoordX = buf.readInt(); + this.chunkPosCoordZ = buf.readInt(); + this.changedBlocks = new S22PacketMultiBlockChange.BlockUpdateData[buf.readVarIntFromBuffer()]; + + for (int i = 0; i < this.changedBlocks.length; ++i) + { + this.changedBlocks[i] = new S22PacketMultiBlockChange.BlockUpdateData(buf.readShort(), buf.readVarIntFromBuffer()); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.chunkPosCoordX); + buf.writeInt(this.chunkPosCoordZ); + buf.writeVarIntToBuffer(this.changedBlocks.length); + + for (S22PacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : this.changedBlocks) + { + buf.writeShort(s22packetmultiblockchange$blockupdatedata.func_180089_b()); + buf.writeVarIntToBuffer(s22packetmultiblockchange$blockupdatedata.getBlockState()); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleMultiBlockChange(this); + } + + public class BlockUpdateData + { + private final short chunkPosCrammed; + private final int blockState; + + public BlockUpdateData(short p_i45984_2_, int state) + { + this.chunkPosCrammed = p_i45984_2_; + this.blockState = state; + } + + public short func_180089_b() + { + return this.chunkPosCrammed; + } + + public int getBlockState() + { + return this.blockState; + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S23PacketBlockChange.java b/proxy/src/main/java/net/minecraft/network/play/server/S23PacketBlockChange.java new file mode 100755 index 0000000..eb6d5a3 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S23PacketBlockChange.java @@ -0,0 +1,40 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S23PacketBlockChange implements Packet +{ + private BlockPos blockPosition; + private int blockState; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.blockPosition = buf.readBlockPos(); + this.blockState = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.blockPosition); + buf.writeVarIntToBuffer(this.blockState); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleBlockChange(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S24PacketBlockAction.java b/proxy/src/main/java/net/minecraft/network/play/server/S24PacketBlockAction.java new file mode 100755 index 0000000..11083a6 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S24PacketBlockAction.java @@ -0,0 +1,46 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S24PacketBlockAction implements Packet +{ + private BlockPos blockPosition; + private int instrument; + private int pitch; + private int block; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.blockPosition = buf.readBlockPos(); + this.instrument = buf.readUnsignedByte(); + this.pitch = buf.readUnsignedByte(); + this.block = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.blockPosition); + buf.writeByte(this.instrument); + buf.writeByte(this.pitch); + buf.writeVarIntToBuffer(this.block); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleBlockAction(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S25PacketBlockBreakAnim.java b/proxy/src/main/java/net/minecraft/network/play/server/S25PacketBlockBreakAnim.java new file mode 100755 index 0000000..1b80bef --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S25PacketBlockBreakAnim.java @@ -0,0 +1,43 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S25PacketBlockBreakAnim implements Packet +{ + private int breakerId; + private BlockPos position; + private int progress; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.breakerId = buf.readVarIntFromBuffer(); + this.position = buf.readBlockPos(); + this.progress = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.breakerId); + buf.writeBlockPos(this.position); + buf.writeByte(this.progress); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleBlockBreakAnim(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S26PacketMapChunkBulk.java b/proxy/src/main/java/net/minecraft/network/play/server/S26PacketMapChunkBulk.java new file mode 100755 index 0000000..eeffa66 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S26PacketMapChunkBulk.java @@ -0,0 +1,131 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.Arrays; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S26PacketMapChunkBulk implements Packet +{ + private int[] xPositions; + private int[] zPositions; + private S21PacketChunkData.Extracted[] chunksData; + private boolean isOverworld; + + public S26PacketMapChunkBulk() + { + } + + public S26PacketMapChunkBulk(int x, int y, int z) + { + this.xPositions = new int[1]; + this.zPositions = new int[1]; + this.chunksData = new S21PacketChunkData.Extracted[1]; + this.isOverworld = true; + this.xPositions[0] = x >> 4; + this.zPositions[0] = z >> 4; + this.chunksData[0] = getExtractedData(x, y, z); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.isOverworld = buf.readBoolean(); + int i = buf.readVarIntFromBuffer(); + this.xPositions = new int[i]; + this.zPositions = new int[i]; + this.chunksData = new S21PacketChunkData.Extracted[i]; + + for (int j = 0; j < i; ++j) + { + this.xPositions[j] = buf.readInt(); + this.zPositions[j] = buf.readInt(); + this.chunksData[j] = new S21PacketChunkData.Extracted(); + this.chunksData[j].dataSize = buf.readShort() & 65535; + this.chunksData[j].data = new byte[func_180737_a(Integer.bitCount(this.chunksData[j].dataSize), this.isOverworld, true)]; + } + + for (int k = 0; k < i; ++k) + { + buf.readBytes(this.chunksData[k].data); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBoolean(this.isOverworld); + buf.writeVarIntToBuffer(this.chunksData.length); + + for (int i = 0; i < this.xPositions.length; ++i) + { + buf.writeInt(this.xPositions[i]); + buf.writeInt(this.zPositions[i]); + buf.writeShort((short)(this.chunksData[i].dataSize & 65535)); + } + + for (int j = 0; j < this.xPositions.length; ++j) + { + buf.writeBytes(this.chunksData[j].data); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleMapChunkBulk(this); + } + + protected static int func_180737_a(int p_180737_0_, boolean p_180737_1_, boolean p_180737_2_) + { + int i = p_180737_0_ * 2 * 16 * 16 * 16; + int j = p_180737_0_ * 16 * 16 * 16 / 2; + int k = p_180737_1_ ? p_180737_0_ * 16 * 16 * 16 / 2 : 0; + int l = p_180737_2_ ? 256 : 0; + return i + j + k + l; + } + + public static S21PacketChunkData.Extracted getExtractedData(int x, int y, int z) + { + S21PacketChunkData.Extracted seg = new S21PacketChunkData.Extracted(); + seg.dataSize = 1 << (y >> 4); + seg.data = new byte[func_180737_a(1, true, true)]; + int id1 = (x & 15) | (y & 15) << 8 | (z & 15) << 4; + int id2 = (x & 15) | ((y + 2) & 15) << 8 | ((z + 1) & 15) << 4; + int id3 = (x & 15) | ((y + 2) & 15) << 8 | ((z + 2) & 15) << 4; + int j = 0; + + char[] achar = new char[4096]; + + for (int n = 0; n < achar.length; n++) + { + char c0 = (char)(n == id1 ? 2 << 4 : (n == id2 ? (68 << 4) | 2 : (n == id3 ? 166 << 4 : 0))); + seg.data[j++] = (byte)(c0 & 255); + seg.data[j++] = (byte)(c0 >> 8 & 255); + } + + byte[] adata = new byte[2048]; + j = func_179757_a(adata, seg.data, j); + Arrays.fill(adata, (byte)255); + j = func_179757_a(adata, seg.data, j); + adata = new byte[256]; + Arrays.fill(adata, (byte)1); + func_179757_a(adata, seg.data, j); + + return seg; + } + + private static int func_179757_a(byte[] p_179757_0_, byte[] p_179757_1_, int p_179757_2_) + { + System.arraycopy(p_179757_0_, 0, p_179757_1_, p_179757_2_, p_179757_0_.length); + return p_179757_2_ + p_179757_0_.length; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S27PacketExplosion.java b/proxy/src/main/java/net/minecraft/network/play/server/S27PacketExplosion.java new file mode 100755 index 0000000..08bdc59 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S27PacketExplosion.java @@ -0,0 +1,88 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.List; + +import com.google.common.collect.Lists; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S27PacketExplosion implements Packet +{ + private double posX; + private double posY; + private double posZ; + private float strength; + private List affectedBlockPositions; + private float field_149152_f; + private float field_149153_g; + private float field_149159_h; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.posX = (double)buf.readFloat(); + this.posY = (double)buf.readFloat(); + this.posZ = (double)buf.readFloat(); + this.strength = buf.readFloat(); + int i = buf.readInt(); + this.affectedBlockPositions = Lists.newArrayListWithCapacity(i); + int j = (int)this.posX; + int k = (int)this.posY; + int l = (int)this.posZ; + + for (int i1 = 0; i1 < i; ++i1) + { + int j1 = buf.readByte() + j; + int k1 = buf.readByte() + k; + int l1 = buf.readByte() + l; + this.affectedBlockPositions.add(new BlockPos(j1, k1, l1)); + } + + this.field_149152_f = buf.readFloat(); + this.field_149153_g = buf.readFloat(); + this.field_149159_h = buf.readFloat(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeFloat((float)this.posX); + buf.writeFloat((float)this.posY); + buf.writeFloat((float)this.posZ); + buf.writeFloat(this.strength); + buf.writeInt(this.affectedBlockPositions.size()); + int i = (int)this.posX; + int j = (int)this.posY; + int k = (int)this.posZ; + + for (BlockPos blockpos : this.affectedBlockPositions) + { + int l = blockpos.getX() - i; + int i1 = blockpos.getY() - j; + int j1 = blockpos.getZ() - k; + buf.writeByte(l); + buf.writeByte(i1); + buf.writeByte(j1); + } + + buf.writeFloat(this.field_149152_f); + buf.writeFloat(this.field_149153_g); + buf.writeFloat(this.field_149159_h); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleExplosion(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S28PacketEffect.java b/proxy/src/main/java/net/minecraft/network/play/server/S28PacketEffect.java new file mode 100755 index 0000000..c7791c5 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S28PacketEffect.java @@ -0,0 +1,46 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S28PacketEffect implements Packet +{ + private int soundType; + private BlockPos soundPos; + private int soundData; + private boolean serverWide; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.soundType = buf.readInt(); + this.soundPos = buf.readBlockPos(); + this.soundData = buf.readInt(); + this.serverWide = buf.readBoolean(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.soundType); + buf.writeBlockPos(this.soundPos); + buf.writeInt(this.soundData); + buf.writeBoolean(this.serverWide); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEffect(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S29PacketSoundEffect.java b/proxy/src/main/java/net/minecraft/network/play/server/S29PacketSoundEffect.java new file mode 100755 index 0000000..021aee4 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S29PacketSoundEffect.java @@ -0,0 +1,51 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S29PacketSoundEffect implements Packet +{ + private String soundName; + private int posX; + private int posY = Integer.MAX_VALUE; + private int posZ; + private float soundVolume; + private int soundPitch; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.soundName = buf.readStringFromBuffer(256); + this.posX = buf.readInt(); + this.posY = buf.readInt(); + this.posZ = buf.readInt(); + this.soundVolume = buf.readFloat(); + this.soundPitch = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.soundName); + buf.writeInt(this.posX); + buf.writeInt(this.posY); + buf.writeInt(this.posZ); + buf.writeFloat(this.soundVolume); + buf.writeByte(this.soundPitch); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSoundEffect(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S2APacketParticles.java b/proxy/src/main/java/net/minecraft/network/play/server/S2APacketParticles.java new file mode 100755 index 0000000..acc4864 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S2APacketParticles.java @@ -0,0 +1,77 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S2APacketParticles implements Packet +{ + private int particleType; + private float xCoord; + private float yCoord; + private float zCoord; + private float xOffset; + private float yOffset; + private float zOffset; + private float particleSpeed; + private int particleCount; + private boolean longDistance; + private int[] particleArguments; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.particleType = buf.readInt(); + this.longDistance = buf.readBoolean(); + this.xCoord = buf.readFloat(); + this.yCoord = buf.readFloat(); + this.zCoord = buf.readFloat(); + this.xOffset = buf.readFloat(); + this.yOffset = buf.readFloat(); + this.zOffset = buf.readFloat(); + this.particleSpeed = buf.readFloat(); + this.particleCount = buf.readInt(); + int i = this.particleType == 36 ? 2 : (this.particleType == 37 || this.particleType == 38 ? 1 : 0); + this.particleArguments = new int[i]; + + for (int j = 0; j < i; ++j) + { + this.particleArguments[j] = buf.readVarIntFromBuffer(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeInt(this.particleType); + buf.writeBoolean(this.longDistance); + buf.writeFloat(this.xCoord); + buf.writeFloat(this.yCoord); + buf.writeFloat(this.zCoord); + buf.writeFloat(this.xOffset); + buf.writeFloat(this.yOffset); + buf.writeFloat(this.zOffset); + buf.writeFloat(this.particleSpeed); + buf.writeInt(this.particleCount); + int i = this.particleType == 36 ? 2 : (this.particleType == 37 || this.particleType == 38 ? 1 : 0); + + for (int j = 0; j < i; ++j) + { + buf.writeVarIntToBuffer(this.particleArguments[j]); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleParticles(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S2BPacketChangeGameState.java b/proxy/src/main/java/net/minecraft/network/play/server/S2BPacketChangeGameState.java new file mode 100755 index 0000000..3d9516e --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S2BPacketChangeGameState.java @@ -0,0 +1,49 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S2BPacketChangeGameState implements Packet +{ + private int state; + private float field_149141_c; + + public S2BPacketChangeGameState() + { + } + + public S2BPacketChangeGameState(int stateIn, float p_i45194_2_) + { + this.state = stateIn; + this.field_149141_c = p_i45194_2_; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.state = buf.readUnsignedByte(); + this.field_149141_c = buf.readFloat(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.state); + buf.writeFloat(this.field_149141_c); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleChangeGameState(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S2CPacketSpawnGlobalEntity.java b/proxy/src/main/java/net/minecraft/network/play/server/S2CPacketSpawnGlobalEntity.java new file mode 100755 index 0000000..5f279ee --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S2CPacketSpawnGlobalEntity.java @@ -0,0 +1,48 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S2CPacketSpawnGlobalEntity implements Packet +{ + private int entityId; + private int x; + private int y; + private int z; + private int type; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.type = buf.readByte(); + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeByte(this.type); + buf.writeInt(this.x); + buf.writeInt(this.y); + buf.writeInt(this.z); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSpawnGlobalEntity(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S2DPacketOpenWindow.java b/proxy/src/main/java/net/minecraft/network/play/server/S2DPacketOpenWindow.java new file mode 100755 index 0000000..4be8a99 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S2DPacketOpenWindow.java @@ -0,0 +1,57 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; + +public class S2DPacketOpenWindow implements Packet +{ + private int windowId; + private String inventoryType; + private ChatComponent windowTitle; + private int slotCount; + private int entityId; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleOpenWindow(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readUnsignedByte(); + this.inventoryType = buf.readStringFromBuffer(32); + this.windowTitle = buf.readChatComponent(); + this.slotCount = buf.readUnsignedByte(); + + if (this.inventoryType.equals("EntityHorse")) + { + this.entityId = buf.readInt(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeString(this.inventoryType); + buf.writeChatComponent(this.windowTitle); + buf.writeByte(this.slotCount); + + if (this.inventoryType.equals("EntityHorse")) + { + buf.writeInt(this.entityId); + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S2EPacketCloseWindow.java b/proxy/src/main/java/net/minecraft/network/play/server/S2EPacketCloseWindow.java new file mode 100755 index 0000000..bb5537e --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S2EPacketCloseWindow.java @@ -0,0 +1,36 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S2EPacketCloseWindow implements Packet +{ + private int windowId; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleCloseWindow(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S2FPacketSetSlot.java b/proxy/src/main/java/net/minecraft/network/play/server/S2FPacketSetSlot.java new file mode 100755 index 0000000..f632f4b --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S2FPacketSetSlot.java @@ -0,0 +1,43 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ItemStack; + +public class S2FPacketSetSlot implements Packet +{ + private int windowId; + private int slot; + private ItemStack item; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSetSlot(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readByte(); + this.slot = buf.readShort(); + this.item = buf.readItemStackFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeShort(this.slot); + buf.writeItemStackToBuffer(this.item); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S30PacketWindowItems.java b/proxy/src/main/java/net/minecraft/network/play/server/S30PacketWindowItems.java new file mode 100755 index 0000000..14e5725 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S30PacketWindowItems.java @@ -0,0 +1,51 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ItemStack; + +public class S30PacketWindowItems implements Packet +{ + private int windowId; + private ItemStack[] itemStacks; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readUnsignedByte(); + int i = buf.readShort(); + this.itemStacks = new ItemStack[i]; + + for (int j = 0; j < i; ++j) + { + this.itemStacks[j] = buf.readItemStackFromBuffer(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeShort(this.itemStacks.length); + + for (ItemStack itemstack : this.itemStacks) + { + buf.writeItemStackToBuffer(itemstack); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleWindowItems(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S31PacketWindowProperty.java b/proxy/src/main/java/net/minecraft/network/play/server/S31PacketWindowProperty.java new file mode 100755 index 0000000..5ff5538 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S31PacketWindowProperty.java @@ -0,0 +1,42 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S31PacketWindowProperty implements Packet +{ + private int windowId; + private int varIndex; + private int varValue; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleWindowProperty(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readUnsignedByte(); + this.varIndex = buf.readShort(); + this.varValue = buf.readShort(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeShort(this.varIndex); + buf.writeShort(this.varValue); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S32PacketConfirmTransaction.java b/proxy/src/main/java/net/minecraft/network/play/server/S32PacketConfirmTransaction.java new file mode 100755 index 0000000..09539ee --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S32PacketConfirmTransaction.java @@ -0,0 +1,42 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S32PacketConfirmTransaction implements Packet +{ + private int windowId; + private short actionNumber; + private boolean field_148893_c; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleConfirmTransaction(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.windowId = buf.readUnsignedByte(); + this.actionNumber = buf.readShort(); + this.field_148893_c = buf.readBoolean(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.windowId); + buf.writeShort(this.actionNumber); + buf.writeBoolean(this.field_148893_c); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S33PacketUpdateSign.java b/proxy/src/main/java/net/minecraft/network/play/server/S33PacketUpdateSign.java new file mode 100755 index 0000000..11e25d1 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S33PacketUpdateSign.java @@ -0,0 +1,60 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; + +public class S33PacketUpdateSign implements Packet +{ + private BlockPos blockPos; + private ChatComponent[] lines; + + public S33PacketUpdateSign() { + + } + + public S33PacketUpdateSign(int x, int y, int z, String line1, String line2, String line3, String line4) { + this.blockPos = new BlockPos(x, y, z); + this.lines = new ChatComponent[] {new ChatComponentText(line1), new ChatComponentText(line2), new ChatComponentText(line3), new ChatComponentText(line4)}; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.blockPos = buf.readBlockPos(); + this.lines = new ChatComponent[4]; + + for (int i = 0; i < 4; ++i) + { + this.lines[i] = buf.readChatComponent(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.blockPos); + + for (int i = 0; i < 4; ++i) + { + buf.writeChatComponent(this.lines[i]); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleUpdateSign(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S34PacketMaps.java b/proxy/src/main/java/net/minecraft/network/play/server/S34PacketMaps.java new file mode 100755 index 0000000..42b023a --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S34PacketMaps.java @@ -0,0 +1,116 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S34PacketMaps implements Packet +{ + private static class Vec4b + { + private byte field_176117_a; + private byte field_176115_b; + private byte field_176116_c; + private byte field_176114_d; + + public Vec4b(byte p_i45555_1_, byte p_i45555_2_, byte p_i45555_3_, byte p_i45555_4_) + { + this.field_176117_a = p_i45555_1_; + this.field_176115_b = p_i45555_2_; + this.field_176116_c = p_i45555_3_; + this.field_176114_d = p_i45555_4_; + } + + public byte func_176110_a() + { + return this.field_176117_a; + } + + public byte func_176112_b() + { + return this.field_176115_b; + } + + public byte func_176113_c() + { + return this.field_176116_c; + } + + public byte func_176111_d() + { + return this.field_176114_d; + } + } + + private int mapId; + private byte mapScale; + private Vec4b[] mapVisiblePlayersVec4b; + private int mapMinX; + private int mapMinY; + private int mapMaxX; + private int mapMaxY; + private byte[] mapDataBytes; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.mapId = buf.readVarIntFromBuffer(); + this.mapScale = buf.readByte(); + this.mapVisiblePlayersVec4b = new Vec4b[buf.readVarIntFromBuffer()]; + + for (int i = 0; i < this.mapVisiblePlayersVec4b.length; ++i) + { + short short1 = (short)buf.readByte(); + this.mapVisiblePlayersVec4b[i] = new Vec4b((byte)(short1 >> 4 & 15), buf.readByte(), buf.readByte(), (byte)(short1 & 15)); + } + + this.mapMaxX = buf.readUnsignedByte(); + + if (this.mapMaxX > 0) + { + this.mapMaxY = buf.readUnsignedByte(); + this.mapMinX = buf.readUnsignedByte(); + this.mapMinY = buf.readUnsignedByte(); + this.mapDataBytes = buf.readByteArray(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.mapId); + buf.writeByte(this.mapScale); + buf.writeVarIntToBuffer(this.mapVisiblePlayersVec4b.length); + + for (Vec4b vec4b : this.mapVisiblePlayersVec4b) + { + buf.writeByte((vec4b.func_176110_a() & 15) << 4 | vec4b.func_176111_d() & 15); + buf.writeByte(vec4b.func_176112_b()); + buf.writeByte(vec4b.func_176113_c()); + } + + buf.writeByte(this.mapMaxX); + + if (this.mapMaxX > 0) + { + buf.writeByte(this.mapMaxY); + buf.writeByte(this.mapMinX); + buf.writeByte(this.mapMinY); + buf.writeByteArray(this.mapDataBytes); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleMaps(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S35PacketUpdateTileEntity.java b/proxy/src/main/java/net/minecraft/network/play/server/S35PacketUpdateTileEntity.java new file mode 100755 index 0000000..9158727 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S35PacketUpdateTileEntity.java @@ -0,0 +1,44 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.nbt.NBTTagCompound; +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S35PacketUpdateTileEntity implements Packet +{ + private BlockPos blockPos; + private int metadata; + private NBTTagCompound nbt; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.blockPos = buf.readBlockPos(); + this.metadata = buf.readUnsignedByte(); + this.nbt = buf.readNBTTagCompoundFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.blockPos); + buf.writeByte((byte)this.metadata); + buf.writeNBTTagCompoundToBuffer(this.nbt); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleUpdateTileEntity(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S36PacketSignEditorOpen.java b/proxy/src/main/java/net/minecraft/network/play/server/S36PacketSignEditorOpen.java new file mode 100755 index 0000000..79b4dca --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S36PacketSignEditorOpen.java @@ -0,0 +1,45 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.BlockPos; + +public class S36PacketSignEditorOpen implements Packet +{ + private BlockPos signPosition; + + public S36PacketSignEditorOpen() { + + } + + public S36PacketSignEditorOpen(int x, int y, int z) { + this.signPosition = new BlockPos(x, y, z); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSignEditorOpen(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.signPosition = buf.readBlockPos(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeBlockPos(this.signPosition); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S37PacketStatistics.java b/proxy/src/main/java/net/minecraft/network/play/server/S37PacketStatistics.java new file mode 100755 index 0000000..87be016 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S37PacketStatistics.java @@ -0,0 +1,58 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.collect.Maps; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S37PacketStatistics implements Packet +{ + private Map field_148976_a; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleStatistics(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + int i = buf.readVarIntFromBuffer(); + this.field_148976_a = Maps.newHashMap(); + + for (int j = 0; j < i; ++j) + { + String statbase = buf.readStringFromBuffer(32767); + int k = buf.readVarIntFromBuffer(); + + if (statbase != null) + { + this.field_148976_a.put(statbase, Integer.valueOf(k)); + } + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.field_148976_a.size()); + + for (Entry entry : this.field_148976_a.entrySet()) + { + buf.writeString(entry.getKey()); + buf.writeVarIntToBuffer(((Integer)entry.getValue()).intValue()); + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S38PacketPlayerListItem.java b/proxy/src/main/java/net/minecraft/network/play/server/S38PacketPlayerListItem.java new file mode 100755 index 0000000..25be085 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S38PacketPlayerListItem.java @@ -0,0 +1,253 @@ +package net.minecraft.network.play.server; + +import com.google.common.base.Objects; +import com.google.common.collect.Lists; + +import java.io.IOException; +import java.util.List; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; +import proxy.util.GameProfile; +import proxy.util.Property; + +public class S38PacketPlayerListItem implements Packet +{ + private S38PacketPlayerListItem.Action action; + private final List players = Lists.newArrayList(); + + public S38PacketPlayerListItem() + { + } + + public S38PacketPlayerListItem(S38PacketPlayerListItem.Action actionIn, GameProfile profile, int ping, int mode, ChatComponent display) + { + this.action = actionIn; + + this.players.add(new S38PacketPlayerListItem.AddPlayerData(profile, ping, mode, display)); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.action = (S38PacketPlayerListItem.Action)buf.readEnumValue(S38PacketPlayerListItem.Action.class); + int i = buf.readVarIntFromBuffer(); + + for (int j = 0; j < i; ++j) + { + GameProfile gameprofile = null; + int k = 0; + int worldsettings$gametype = 0; + ChatComponent ichatcomponent = null; + + switch (this.action) + { + case ADD_PLAYER: + gameprofile = new GameProfile(buf.readUuid(), buf.readStringFromBuffer(16)); + int l = buf.readVarIntFromBuffer(); + int i1 = 0; + + for (; i1 < l; ++i1) + { + String s = buf.readStringFromBuffer(32767); + String s1 = buf.readStringFromBuffer(32767); + + if (buf.readBoolean()) + { + gameprofile.getProperties().put(s, new Property(s, s1, buf.readStringFromBuffer(32767))); + } + else + { + gameprofile.getProperties().put(s, new Property(s, s1)); + } + } + + worldsettings$gametype = buf.readVarIntFromBuffer(); + k = buf.readVarIntFromBuffer(); + + if (buf.readBoolean()) + { + ichatcomponent = buf.readChatComponent(); + } + + break; + + case UPDATE_GAME_MODE: + gameprofile = new GameProfile(buf.readUuid(), (String)null); + worldsettings$gametype = buf.readVarIntFromBuffer(); + break; + + case UPDATE_LATENCY: + gameprofile = new GameProfile(buf.readUuid(), (String)null); + k = buf.readVarIntFromBuffer(); + break; + + case UPDATE_DISPLAY_NAME: + gameprofile = new GameProfile(buf.readUuid(), (String)null); + + if (buf.readBoolean()) + { + ichatcomponent = buf.readChatComponent(); + } + + break; + + case REMOVE_PLAYER: + gameprofile = new GameProfile(buf.readUuid(), (String)null); + } + + this.players.add(new S38PacketPlayerListItem.AddPlayerData(gameprofile, k, worldsettings$gametype, ichatcomponent)); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.action); + buf.writeVarIntToBuffer(this.players.size()); + + for (S38PacketPlayerListItem.AddPlayerData s38packetplayerlistitem$addplayerdata : this.players) + { + switch (this.action) + { + case ADD_PLAYER: + buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId()); + buf.writeString(s38packetplayerlistitem$addplayerdata.getProfile().getName()); + buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getProfile().getProperties().size()); + + for (Property property : s38packetplayerlistitem$addplayerdata.getProfile().getProperties().values()) + { + buf.writeString(property.getName()); + buf.writeString(property.getValue()); + + if (property.hasSignature()) + { + buf.writeBoolean(true); + buf.writeString(property.getSignature()); + } + else + { + buf.writeBoolean(false); + } + } + + buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getGameMode()); + buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getPing()); + + if (s38packetplayerlistitem$addplayerdata.getDisplayName() == null) + { + buf.writeBoolean(false); + } + else + { + buf.writeBoolean(true); + buf.writeChatComponent(s38packetplayerlistitem$addplayerdata.getDisplayName()); + } + + break; + + case UPDATE_GAME_MODE: + buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId()); + buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getGameMode()); + break; + + case UPDATE_LATENCY: + buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId()); + buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getPing()); + break; + + case UPDATE_DISPLAY_NAME: + buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId()); + + if (s38packetplayerlistitem$addplayerdata.getDisplayName() == null) + { + buf.writeBoolean(false); + } + else + { + buf.writeBoolean(true); + buf.writeChatComponent(s38packetplayerlistitem$addplayerdata.getDisplayName()); + } + + break; + + case REMOVE_PLAYER: + buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId()); + } + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handlePlayerListItem(this); + } + + public List getEntries() + { + return this.players; + } + + public S38PacketPlayerListItem.Action getAction() + { + return this.action; + } + + public String toString() + { + return Objects.toStringHelper(this).add("action", this.action).add("entries", this.players).toString(); + } + + public static enum Action + { + ADD_PLAYER, + UPDATE_GAME_MODE, + UPDATE_LATENCY, + UPDATE_DISPLAY_NAME, + REMOVE_PLAYER; + } + + public class AddPlayerData + { + private final int ping; + private final int gamemode; + private final GameProfile profile; + private final ChatComponent displayName; + + public AddPlayerData(GameProfile profile, int pingIn, int gamemodeIn, ChatComponent displayNameIn) + { + this.profile = profile; + this.ping = pingIn; + this.gamemode = gamemodeIn; + this.displayName = displayNameIn; + } + + public GameProfile getProfile() + { + return this.profile; + } + + public int getPing() + { + return this.ping; + } + + public int getGameMode() + { + return this.gamemode; + } + + public ChatComponent getDisplayName() + { + return this.displayName; + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S39PacketPlayerAbilities.java b/proxy/src/main/java/net/minecraft/network/play/server/S39PacketPlayerAbilities.java new file mode 100755 index 0000000..528cd04 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S39PacketPlayerAbilities.java @@ -0,0 +1,145 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S39PacketPlayerAbilities implements Packet +{ + private boolean invulnerable; + private boolean flying; + private boolean allowFlying; + private boolean creativeMode; + private float flySpeed; + private float walkSpeed; + + public S39PacketPlayerAbilities() + { + } + + public S39PacketPlayerAbilities(boolean spectator) + { + this.setInvulnerable(spectator); + this.setFlying(spectator); + this.setAllowFlying(spectator); + this.setCreativeMode(false); + this.setFlySpeed(0.05f); + this.setWalkSpeed(0.1f); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + byte b0 = buf.readByte(); + this.setInvulnerable((b0 & 1) > 0); + this.setFlying((b0 & 2) > 0); + this.setAllowFlying((b0 & 4) > 0); + this.setCreativeMode((b0 & 8) > 0); + this.setFlySpeed(buf.readFloat()); + this.setWalkSpeed(buf.readFloat()); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + byte b0 = 0; + + if (this.isInvulnerable()) + { + b0 = (byte)(b0 | 1); + } + + if (this.isFlying()) + { + b0 = (byte)(b0 | 2); + } + + if (this.isAllowFlying()) + { + b0 = (byte)(b0 | 4); + } + + if (this.isCreativeMode()) + { + b0 = (byte)(b0 | 8); + } + + buf.writeByte(b0); + buf.writeFloat(this.flySpeed); + buf.writeFloat(this.walkSpeed); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handlePlayerAbilities(this); + } + + public boolean isInvulnerable() + { + return this.invulnerable; + } + + public void setInvulnerable(boolean isInvulnerable) + { + this.invulnerable = isInvulnerable; + } + + public boolean isFlying() + { + return this.flying; + } + + public void setFlying(boolean isFlying) + { + this.flying = isFlying; + } + + public boolean isAllowFlying() + { + return this.allowFlying; + } + + public void setAllowFlying(boolean isAllowFlying) + { + this.allowFlying = isAllowFlying; + } + + public boolean isCreativeMode() + { + return this.creativeMode; + } + + public void setCreativeMode(boolean isCreativeMode) + { + this.creativeMode = isCreativeMode; + } + + public float getFlySpeed() + { + return this.flySpeed; + } + + public void setFlySpeed(float flySpeedIn) + { + this.flySpeed = flySpeedIn; + } + + public float getWalkSpeed() + { + return this.walkSpeed; + } + + public void setWalkSpeed(float walkSpeedIn) + { + this.walkSpeed = walkSpeedIn; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S3APacketTabComplete.java b/proxy/src/main/java/net/minecraft/network/play/server/S3APacketTabComplete.java new file mode 100755 index 0000000..41f85c6 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S3APacketTabComplete.java @@ -0,0 +1,60 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S3APacketTabComplete implements Packet +{ + private String[] matches; + + public S3APacketTabComplete() + { + } + + public S3APacketTabComplete(String[] matchesIn) + { + this.matches = matchesIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.matches = new String[buf.readVarIntFromBuffer()]; + + for (int i = 0; i < this.matches.length; ++i) + { + this.matches[i] = buf.readStringFromBuffer(32767); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.matches.length); + + for (String s : this.matches) + { + buf.writeString(s); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleTabComplete(this); + } + + public String[] func_149630_c() + { + return this.matches; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S3BPacketScoreboardObjective.java b/proxy/src/main/java/net/minecraft/network/play/server/S3BPacketScoreboardObjective.java new file mode 100755 index 0000000..d903acf --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S3BPacketScoreboardObjective.java @@ -0,0 +1,53 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S3BPacketScoreboardObjective implements Packet +{ + private String objectiveName; + private String objectiveValue; + private String type; + private int field_149342_c; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.objectiveName = buf.readStringFromBuffer(16); + this.field_149342_c = buf.readByte(); + + if (this.field_149342_c == 0 || this.field_149342_c == 2) + { + this.objectiveValue = buf.readStringFromBuffer(32); + this.type = buf.readStringFromBuffer(16); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.objectiveName); + buf.writeByte(this.field_149342_c); + + if (this.field_149342_c == 0 || this.field_149342_c == 2) + { + buf.writeString(this.objectiveValue); + buf.writeString(this.type); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleScoreboardObjective(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S3CPacketUpdateScore.java b/proxy/src/main/java/net/minecraft/network/play/server/S3CPacketUpdateScore.java new file mode 100755 index 0000000..032c72e --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S3CPacketUpdateScore.java @@ -0,0 +1,59 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S3CPacketUpdateScore implements Packet +{ + private String name = ""; + private String objective = ""; + private int value; + private S3CPacketUpdateScore.Action action; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.name = buf.readStringFromBuffer(40); + this.action = (S3CPacketUpdateScore.Action)buf.readEnumValue(S3CPacketUpdateScore.Action.class); + this.objective = buf.readStringFromBuffer(16); + + if (this.action != S3CPacketUpdateScore.Action.REMOVE) + { + this.value = buf.readVarIntFromBuffer(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.name); + buf.writeEnumValue(this.action); + buf.writeString(this.objective); + + if (this.action != S3CPacketUpdateScore.Action.REMOVE) + { + buf.writeVarIntToBuffer(this.value); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleUpdateScore(this); + } + + public static enum Action + { + CHANGE, + REMOVE; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S3DPacketDisplayScoreboard.java b/proxy/src/main/java/net/minecraft/network/play/server/S3DPacketDisplayScoreboard.java new file mode 100755 index 0000000..2874aa1 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S3DPacketDisplayScoreboard.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S3DPacketDisplayScoreboard implements Packet +{ + private int position; + private String scoreName; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.position = buf.readByte(); + this.scoreName = buf.readStringFromBuffer(16); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.position); + buf.writeString(this.scoreName); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleDisplayScoreboard(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S3EPacketTeams.java b/proxy/src/main/java/net/minecraft/network/play/server/S3EPacketTeams.java new file mode 100755 index 0000000..64ed943 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S3EPacketTeams.java @@ -0,0 +1,96 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; +import java.util.Collection; + +import com.google.common.collect.Lists; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S3EPacketTeams implements Packet +{ + private String name = ""; + private String displayName = ""; + private String prefix = ""; + private String suffix = ""; + private String nameTagVisibility; + private int color; + private Collection players; + private int action; + private int friendlyFlags; + + public S3EPacketTeams() + { + this.nameTagVisibility = "always"; + this.color = -1; + this.players = Lists.newArrayList(); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.name = buf.readStringFromBuffer(16); + this.action = buf.readByte(); + + if (this.action == 0 || this.action == 2) + { + this.displayName = buf.readStringFromBuffer(32); + this.prefix = buf.readStringFromBuffer(16); + this.suffix = buf.readStringFromBuffer(16); + this.friendlyFlags = buf.readByte(); + this.nameTagVisibility = buf.readStringFromBuffer(32); + this.color = buf.readByte(); + } + + if (this.action == 0 || this.action == 3 || this.action == 4) + { + int i = buf.readVarIntFromBuffer(); + + for (int j = 0; j < i; ++j) + { + this.players.add(buf.readStringFromBuffer(40)); + } + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.name); + buf.writeByte(this.action); + + if (this.action == 0 || this.action == 2) + { + buf.writeString(this.displayName); + buf.writeString(this.prefix); + buf.writeString(this.suffix); + buf.writeByte(this.friendlyFlags); + buf.writeString(this.nameTagVisibility); + buf.writeByte(this.color); + } + + if (this.action == 0 || this.action == 3 || this.action == 4) + { + buf.writeVarIntToBuffer(this.players.size()); + + for (String s : this.players) + { + buf.writeString(s); + } + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleTeams(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S3FPacketCustomPayload.java b/proxy/src/main/java/net/minecraft/network/play/server/S3FPacketCustomPayload.java new file mode 100755 index 0000000..7aea740 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S3FPacketCustomPayload.java @@ -0,0 +1,74 @@ +package net.minecraft.network.play.server; + +import io.netty.buffer.ByteBuf; +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S3FPacketCustomPayload implements Packet +{ + private String channel; + private PacketBuffer data; + + public S3FPacketCustomPayload() + { + } + + public S3FPacketCustomPayload(String channelName, PacketBuffer dataIn) + { + this.channel = channelName; + this.data = dataIn; + + if (dataIn.writerIndex() > 1048576) + { + throw new IllegalArgumentException("Payload may not be larger than 1048576 bytes"); + } + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.channel = buf.readStringFromBuffer(20); + int i = buf.readableBytes(); + + if (i >= 0 && i <= 1048576) + { + this.data = new PacketBuffer(buf.readBytes(i)); + } + else + { + throw new IOException("Payload may not be larger than 1048576 bytes"); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.channel); + buf.writeBytes((ByteBuf)this.data); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleCustomPayload(this); + } + + public String getChannelName() + { + return this.channel; + } + + public PacketBuffer getBufferData() + { + return this.data; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S40PacketDisconnect.java b/proxy/src/main/java/net/minecraft/network/play/server/S40PacketDisconnect.java new file mode 100755 index 0000000..0ccabbd --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S40PacketDisconnect.java @@ -0,0 +1,51 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; + +public class S40PacketDisconnect implements Packet +{ + private ChatComponent reason; + + public S40PacketDisconnect() + { + } + + public S40PacketDisconnect(ChatComponent reasonIn) + { + this.reason = reasonIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.reason = buf.readChatComponent(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeChatComponent(this.reason); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleDisconnect(this); + } + + public ChatComponent getReason() + { + return this.reason; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S41PacketServerDifficulty.java b/proxy/src/main/java/net/minecraft/network/play/server/S41PacketServerDifficulty.java new file mode 100755 index 0000000..abff2b4 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S41PacketServerDifficulty.java @@ -0,0 +1,36 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S41PacketServerDifficulty implements Packet +{ + private byte difficulty; + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleServerDifficulty(this); + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.difficulty = (byte)buf.readUnsignedByte(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeByte(this.difficulty); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S42PacketCombatEvent.java b/proxy/src/main/java/net/minecraft/network/play/server/S42PacketCombatEvent.java new file mode 100755 index 0000000..24fc261 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S42PacketCombatEvent.java @@ -0,0 +1,71 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S42PacketCombatEvent implements Packet +{ + public S42PacketCombatEvent.Event eventType; + public int field_179774_b; + public int field_179775_c; + public int field_179772_d; + public String deathMessage; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.eventType = (S42PacketCombatEvent.Event)buf.readEnumValue(S42PacketCombatEvent.Event.class); + + if (this.eventType == S42PacketCombatEvent.Event.END_COMBAT) + { + this.field_179772_d = buf.readVarIntFromBuffer(); + this.field_179775_c = buf.readInt(); + } + else if (this.eventType == S42PacketCombatEvent.Event.ENTITY_DIED) + { + this.field_179774_b = buf.readVarIntFromBuffer(); + this.field_179775_c = buf.readInt(); + this.deathMessage = buf.readStringFromBuffer(32767); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.eventType); + + if (this.eventType == S42PacketCombatEvent.Event.END_COMBAT) + { + buf.writeVarIntToBuffer(this.field_179772_d); + buf.writeInt(this.field_179775_c); + } + else if (this.eventType == S42PacketCombatEvent.Event.ENTITY_DIED) + { + buf.writeVarIntToBuffer(this.field_179774_b); + buf.writeInt(this.field_179775_c); + buf.writeString(this.deathMessage); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleCombatEvent(this); + } + + public static enum Event + { + ENTER_COMBAT, + END_COMBAT, + ENTITY_DIED; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S43PacketCamera.java b/proxy/src/main/java/net/minecraft/network/play/server/S43PacketCamera.java new file mode 100755 index 0000000..43294c9 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S43PacketCamera.java @@ -0,0 +1,36 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S43PacketCamera implements Packet +{ + private int entityId; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleCamera(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S44PacketWorldBorder.java b/proxy/src/main/java/net/minecraft/network/play/server/S44PacketWorldBorder.java new file mode 100755 index 0000000..b433ddc --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S44PacketWorldBorder.java @@ -0,0 +1,126 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S44PacketWorldBorder implements Packet +{ + private S44PacketWorldBorder.Action action; + private int size; + private double centerX; + private double centerZ; + private double targetSize; + private double diameter; + private long timeUntilTarget; + private int warningTime; + private int warningDistance; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.action = (S44PacketWorldBorder.Action)buf.readEnumValue(S44PacketWorldBorder.Action.class); + + switch (this.action) + { + case SET_SIZE: + this.targetSize = buf.readDouble(); + break; + + case LERP_SIZE: + this.diameter = buf.readDouble(); + this.targetSize = buf.readDouble(); + this.timeUntilTarget = buf.readVarLong(); + break; + + case SET_CENTER: + this.centerX = buf.readDouble(); + this.centerZ = buf.readDouble(); + break; + + case SET_WARNING_BLOCKS: + this.warningDistance = buf.readVarIntFromBuffer(); + break; + + case SET_WARNING_TIME: + this.warningTime = buf.readVarIntFromBuffer(); + break; + + case INITIALIZE: + this.centerX = buf.readDouble(); + this.centerZ = buf.readDouble(); + this.diameter = buf.readDouble(); + this.targetSize = buf.readDouble(); + this.timeUntilTarget = buf.readVarLong(); + this.size = buf.readVarIntFromBuffer(); + this.warningDistance = buf.readVarIntFromBuffer(); + this.warningTime = buf.readVarIntFromBuffer(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.action); + + switch (this.action) + { + case SET_SIZE: + buf.writeDouble(this.targetSize); + break; + + case LERP_SIZE: + buf.writeDouble(this.diameter); + buf.writeDouble(this.targetSize); + buf.writeVarLong(this.timeUntilTarget); + break; + + case SET_CENTER: + buf.writeDouble(this.centerX); + buf.writeDouble(this.centerZ); + break; + + case SET_WARNING_BLOCKS: + buf.writeVarIntToBuffer(this.warningDistance); + break; + + case SET_WARNING_TIME: + buf.writeVarIntToBuffer(this.warningTime); + break; + + case INITIALIZE: + buf.writeDouble(this.centerX); + buf.writeDouble(this.centerZ); + buf.writeDouble(this.diameter); + buf.writeDouble(this.targetSize); + buf.writeVarLong(this.timeUntilTarget); + buf.writeVarIntToBuffer(this.size); + buf.writeVarIntToBuffer(this.warningDistance); + buf.writeVarIntToBuffer(this.warningTime); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleWorldBorder(this); + } + + public static enum Action + { + SET_SIZE, + LERP_SIZE, + SET_CENTER, + INITIALIZE, + SET_WARNING_TIME, + SET_WARNING_BLOCKS; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S45PacketTitle.java b/proxy/src/main/java/net/minecraft/network/play/server/S45PacketTitle.java new file mode 100755 index 0000000..2656183 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S45PacketTitle.java @@ -0,0 +1,123 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; + +public class S45PacketTitle implements Packet +{ + private S45PacketTitle.Type type; + private ChatComponent message; + private int fadeInTime; + private int displayTime; + private int fadeOutTime; + + public S45PacketTitle() + { + } + + public S45PacketTitle(S45PacketTitle.Type type, ChatComponent message) + { + this(type, message, -1, -1, -1); + } + + public S45PacketTitle(int fadeInTime, int displayTime, int fadeOutTime) + { + this(S45PacketTitle.Type.TIMES, (ChatComponent)null, fadeInTime, displayTime, fadeOutTime); + } + + public S45PacketTitle(S45PacketTitle.Type type, ChatComponent message, int fadeInTime, int displayTime, int fadeOutTime) + { + this.type = type; + this.message = message; + this.fadeInTime = fadeInTime; + this.displayTime = displayTime; + this.fadeOutTime = fadeOutTime; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.type = (S45PacketTitle.Type)buf.readEnumValue(S45PacketTitle.Type.class); + + if (this.type == S45PacketTitle.Type.TITLE || this.type == S45PacketTitle.Type.SUBTITLE) + { + this.message = buf.readChatComponent(); + } + + if (this.type == S45PacketTitle.Type.TIMES) + { + this.fadeInTime = buf.readInt(); + this.displayTime = buf.readInt(); + this.fadeOutTime = buf.readInt(); + } + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.type); + + if (this.type == S45PacketTitle.Type.TITLE || this.type == S45PacketTitle.Type.SUBTITLE) + { + buf.writeChatComponent(this.message); + } + + if (this.type == S45PacketTitle.Type.TIMES) + { + buf.writeInt(this.fadeInTime); + buf.writeInt(this.displayTime); + buf.writeInt(this.fadeOutTime); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleTitle(this); + } + + public static enum Type + { + TITLE, + SUBTITLE, + TIMES, + CLEAR, + RESET; + + public static S45PacketTitle.Type byName(String name) + { + for (S45PacketTitle.Type s45packettitle$type : values()) + { + if (s45packettitle$type.name().equalsIgnoreCase(name)) + { + return s45packettitle$type; + } + } + + return TITLE; + } + + public static String[] getNames() + { + String[] astring = new String[values().length]; + int i = 0; + + for (S45PacketTitle.Type s45packettitle$type : values()) + { + astring[i++] = s45packettitle$type.name().toLowerCase(); + } + + return astring; + } + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S46PacketSetCompressionLevel.java b/proxy/src/main/java/net/minecraft/network/play/server/S46PacketSetCompressionLevel.java new file mode 100755 index 0000000..adc4352 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S46PacketSetCompressionLevel.java @@ -0,0 +1,41 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S46PacketSetCompressionLevel implements Packet +{ + private int threshold; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.threshold = buf.readVarIntFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.threshold); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleSetCompressionLevel(this); + } + + public int getThreshold() + { + return this.threshold; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S47PacketPlayerListHeaderFooter.java b/proxy/src/main/java/net/minecraft/network/play/server/S47PacketPlayerListHeaderFooter.java new file mode 100755 index 0000000..93270c7 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S47PacketPlayerListHeaderFooter.java @@ -0,0 +1,50 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.util.ChatComponent; + +public class S47PacketPlayerListHeaderFooter implements Packet +{ + private ChatComponent header; + private ChatComponent footer; + + public S47PacketPlayerListHeaderFooter() + { + } + + public S47PacketPlayerListHeaderFooter(ChatComponent headerIn, ChatComponent footerIn) + { + this.header = headerIn; + this.footer = footerIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.header = buf.readChatComponent(); + this.footer = buf.readChatComponent(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeChatComponent(this.header); + buf.writeChatComponent(this.footer); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handlePlayerListHeaderFooter(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S48PacketResourcePackSend.java b/proxy/src/main/java/net/minecraft/network/play/server/S48PacketResourcePackSend.java new file mode 100755 index 0000000..b782886 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S48PacketResourcePackSend.java @@ -0,0 +1,39 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S48PacketResourcePackSend implements Packet +{ + private String url; + private String hash; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.url = buf.readStringFromBuffer(32767); + this.hash = buf.readStringFromBuffer(40); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(this.url); + buf.writeString(this.hash); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleResourcePack(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/play/server/S49PacketUpdateEntityNBT.java b/proxy/src/main/java/net/minecraft/network/play/server/S49PacketUpdateEntityNBT.java new file mode 100755 index 0000000..555a6ac --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/play/server/S49PacketUpdateEntityNBT.java @@ -0,0 +1,40 @@ +package net.minecraft.network.play.server; + +import java.io.IOException; + +import proxy.nbt.NBTTagCompound; +import proxy.network.INetHandlerPlayClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S49PacketUpdateEntityNBT implements Packet +{ + private int entityId; + private NBTTagCompound tagCompound; + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarIntFromBuffer(); + this.tagCompound = buf.readNBTTagCompoundFromBuffer(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarIntToBuffer(this.entityId); + buf.writeNBTTagCompoundToBuffer(this.tagCompound); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(INetHandlerPlayClient handler) + { + handler.handleEntityNBT(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/status/client/C00PacketServerQuery.java b/proxy/src/main/java/net/minecraft/network/status/client/C00PacketServerQuery.java new file mode 100755 index 0000000..54af54a --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/status/client/C00PacketServerQuery.java @@ -0,0 +1,32 @@ +package net.minecraft.network.status.client; + +import java.io.IOException; + +import proxy.network.NetHandlerStatusServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C00PacketServerQuery implements Packet +{ + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerStatusServer handler) + { + handler.processServerQuery(this); + } +} diff --git a/proxy/src/main/java/net/minecraft/network/status/client/C01PacketPing.java b/proxy/src/main/java/net/minecraft/network/status/client/C01PacketPing.java new file mode 100755 index 0000000..ec864d3 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/status/client/C01PacketPing.java @@ -0,0 +1,50 @@ +package net.minecraft.network.status.client; + +import java.io.IOException; + +import proxy.network.NetHandlerStatusServer; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class C01PacketPing implements Packet +{ + private long clientTime; + + public C01PacketPing() + { + } + + public C01PacketPing(long ping) + { + this.clientTime = ping; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.clientTime = buf.readLong(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeLong(this.clientTime); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerStatusServer handler) + { + handler.processPing(this); + } + + public long getClientTime() + { + return this.clientTime; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/status/server/S00PacketServerInfo.java b/proxy/src/main/java/net/minecraft/network/status/server/S00PacketServerInfo.java new file mode 100755 index 0000000..071a562 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/status/server/S00PacketServerInfo.java @@ -0,0 +1,58 @@ +package net.minecraft.network.status.server; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.IOException; + +import proxy.network.NetHandlerStatusClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; +import proxy.network.ServerStatusResponse; +import proxy.util.ChatComponent; +import proxy.util.ChatStyle; +import proxy.util.EnumTypeAdapterFactory; + +public class S00PacketServerInfo implements Packet +{ + private static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(ServerStatusResponse.MinecraftProtocolVersionIdentifier.class, new ServerStatusResponse.MinecraftProtocolVersionIdentifier.Serializer()).registerTypeAdapter(ServerStatusResponse.PlayerCountData.class, new ServerStatusResponse.PlayerCountData.Serializer()).registerTypeAdapter(ServerStatusResponse.class, new ServerStatusResponse.Serializer()).registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer()).registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()).registerTypeAdapterFactory(new EnumTypeAdapterFactory()).create(); + private ServerStatusResponse response; + + public S00PacketServerInfo() + { + } + + public S00PacketServerInfo(ServerStatusResponse responseIn) + { + this.response = responseIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.response = (ServerStatusResponse)GSON.fromJson(buf.readStringFromBuffer(32767), ServerStatusResponse.class); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeString(GSON.toJson((Object)this.response)); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerStatusClient handler) + { + handler.handleServerInfo(this); + } + + public ServerStatusResponse getResponse() + { + return this.response; + } +} diff --git a/proxy/src/main/java/net/minecraft/network/status/server/S01PacketPong.java b/proxy/src/main/java/net/minecraft/network/status/server/S01PacketPong.java new file mode 100755 index 0000000..517f987 --- /dev/null +++ b/proxy/src/main/java/net/minecraft/network/status/server/S01PacketPong.java @@ -0,0 +1,45 @@ +package net.minecraft.network.status.server; + +import java.io.IOException; + +import proxy.network.NetHandlerStatusClient; +import proxy.network.Packet; +import proxy.network.PacketBuffer; + +public class S01PacketPong implements Packet +{ + private long clientTime; + + public S01PacketPong() + { + } + + public S01PacketPong(long time) + { + this.clientTime = time; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.clientTime = buf.readLong(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeLong(this.clientTime); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(NetHandlerStatusClient handler) + { + handler.handlePong(this); + } +} diff --git a/proxy/src/main/java/proxy/Proxy.java b/proxy/src/main/java/proxy/Proxy.java index 6266c01..e11824d 100755 --- a/proxy/src/main/java/proxy/Proxy.java +++ b/proxy/src/main/java/proxy/Proxy.java @@ -1,7 +1,366 @@ package proxy; -public final class Proxy { +import io.netty.bootstrap.ServerBootstrap; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufOutputStream; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelException; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.epoll.Epoll; +import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.epoll.EpollServerSocketChannel; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.ServerSocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.codec.base64.Base64; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.IDN; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Queue; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.FutureTask; + +import javax.imageio.ImageIO; + +import com.google.common.base.Charsets; +import com.google.common.collect.Maps; +import com.google.common.collect.Queues; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListenableFutureTask; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +import net.minecraft.network.play.server.S40PacketDisconnect; +import proxy.network.EnumPacketDirection; +import proxy.network.MessageDeserializer; +import proxy.network.MessageDeserializer2; +import proxy.network.MessageSerializer; +import proxy.network.MessageSerializer2; +import proxy.network.NetHandlerHandshake; +import proxy.network.NetHandlerPlayServer; +import proxy.network.NetworkManager; +import proxy.network.ServerStatusResponse; +import proxy.network.ThreadQuickExitException; +import proxy.util.ChatColor; +import proxy.util.ChatComponentText; +import proxy.util.GameProfile; +import proxy.util.User; +import proxy.util.LazyLoadBase; +import proxy.util.Log; + +public class Proxy { + public static final LazyLoadBase NIO_EVENT_LOOP = new LazyLoadBase() { + protected NioEventLoopGroup load() { + return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build()); + } + }; + public static final LazyLoadBase EPOLL_EVENT_LOOP = new LazyLoadBase() { + protected EpollEventLoopGroup load() { + return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).build()); + } + }; + + private volatile boolean isAlive; + private volatile boolean running = true; + + private final List endpoints = Collections.synchronizedList(new ArrayList()); + private final List networkManagers = Collections.synchronizedList(new ArrayList()); + private final Queue> futureTaskQueue = Queues.>newArrayDeque(); + private final Map users = Maps.newHashMap(); + private final Map players = Maps.newHashMap(); + private final Thread serverThread; + + private int compression = -1; + private boolean epoll = false; + private boolean register = true; + private boolean checkCase = true; + private String forwardHost = "lian.dd"; + private int forwardPort = 25565; + private String proxyHost = ""; + private int proxyPort = 25566; + private int minPassLength = 8; + private int maxAttempts = 5; + private ServerStatusResponse status = getStatus(new File("icon.png"), ChatColor.AQUA + "Server\n" + ChatColor.GREEN + "Test!!", 90, 10, "Test1", + "Test2 ...", "Test #3 !!"); + + private static void addFaviconToStatusResponse(ServerStatusResponse info, File file) { + if(file.isFile()) { + ByteBuf buf = Unpooled.buffer(); + try { + BufferedImage img = ImageIO.read(file); + if(img.getWidth() != 64 || img.getHeight() != 64) + throw new IllegalArgumentException("Icon must be 64x64 pixels"); + ImageIO.write(img, "PNG", new ByteBufOutputStream(buf)); + ByteBuf base64 = Base64.encode(buf); + info.setFavicon("data:image/png;base64," + base64.toString(Charsets.UTF_8)); + } + catch(Exception e) { + Log.error(e, "Couldn't load server icon"); + } + finally { + buf.release(); + } + } + } + + public static ServerStatusResponse getStatus(File icon, String motd, int max, int current, String... lines) { + ServerStatusResponse info = new ServerStatusResponse(); + info.setServerDescription(new ChatComponentText(motd)); + info.setProtocolVersionInfo(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.8.9", 47)); + addFaviconToStatusResponse(info, icon); + info.setPlayerCountData(new ServerStatusResponse.PlayerCountData(max, current)); + GameProfile[] profiles = new GameProfile[Math.min(lines.length, 12)]; + for(int z = 0; z < profiles.length; z++) { + profiles[z] = new GameProfile(Proxy.getOfflineUUID(lines[z]), lines[z]); + } + info.getPlayerCountData().setPlayers(profiles); + return info; + } + + public static UUID getOfflineUUID(String name) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); + } + public static void main(String[] args) { - System.out.println("init test"); + Thread.currentThread().setName("Proxy thread"); + Proxy proxy = new Proxy(); + proxy.run(); + } + + public Proxy() { + this.serverThread = Thread.currentThread(); + this.isAlive = true; + } + + public void run() { + Log.info("Starting login proxy on %s:%d", this.proxyHost.isEmpty() ? "0.0.0.0" : this.proxyHost, this.proxyPort); + try { + this.addLanEndpoint(this.proxyHost.isEmpty() ? null : InetAddress.getByName(IDN.toASCII(this.proxyHost)), this.proxyPort); + } + catch(IOException e) { + Log.error(e, "Could not bind to port"); + return; + } + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + public void run() { + Proxy.this.terminateEndpoints(); + } + }, "Proxy shutdown thread")); + while(this.running) { + synchronized (this.futureTaskQueue) + { + while (!this.futureTaskQueue.isEmpty()) + { + FutureTask task = this.futureTaskQueue.poll(); + try { + task.run(); + task.get(); + } + catch(ExecutionException e1) { + if(!(e1.getCause() instanceof ThreadQuickExitException)) + Log.error(e1, "Error executing task " + task); + } + catch(InterruptedException e2) { + Log.error(e2, "Error executing task " + task); + } + } + } + this.networkTick(); + try { + Thread.sleep(50L); + } + catch(InterruptedException e) { + } + } + this.terminateEndpoints(); + Log.info("Proxy stopped"); + } + + public void addLanEndpoint(InetAddress address, int port) throws IOException { + synchronized(this.endpoints) { + Class oclass; + LazyLoadBase lazyloadbase; + + if(Epoll.isAvailable() && this.epoll) { + oclass = EpollServerSocketChannel.class; + lazyloadbase = EPOLL_EVENT_LOOP; + Log.info("Using epoll channel type"); + } + else { + oclass = NioServerSocketChannel.class; + lazyloadbase = NIO_EVENT_LOOP; + Log.info("Using default channel type"); + } + + this.endpoints + .add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer() { + protected void initChannel(Channel p_initChannel_1_) throws Exception { + try { + p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); + } + catch(ChannelException var3) { + ; + } + + p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))) + .addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())) + .addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.SERVERBOUND))) + .addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())) + .addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.CLIENTBOUND))); + NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND); + Proxy.this.networkManagers.add(networkmanager); + p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager); + networkmanager.setNetHandler(new NetHandlerHandshake(Proxy.this, networkmanager)); + } + }).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly()); + } + } + + public void terminateEndpoints() { + this.isAlive = false; + + for(ChannelFuture channelfuture : this.endpoints) { + try { + channelfuture.channel().close().sync(); + } + catch(InterruptedException var4) { + Log.error("Interrupted whilst closing channel"); + } + } + } + + public void networkTick() { + synchronized(this.networkManagers) { + Iterator iterator = this.networkManagers.iterator(); + + while(iterator.hasNext()) { + final NetworkManager networkmanager = (NetworkManager)iterator.next(); + + if(!networkmanager.hasNoChannel()) { + if(!networkmanager.isChannelOpen()) { + iterator.remove(); + networkmanager.checkDisconnected(); + } + else { + try { + networkmanager.processReceivedPackets(); + } + catch(Exception exception) { + Log.error(exception, "Failed to handle packet for " + networkmanager.getRemoteAddress()); + final ChatComponentText chatcomponenttext = new ChatComponentText("Internal server error"); + networkmanager.sendPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener>() { + public void operationComplete(Future p_operationComplete_1_) throws Exception { + networkmanager.closeChannel(chatcomponenttext); + } + }); + networkmanager.disableAutoRead(); + } + } + } + } + } + } + + private ListenableFuture callFromMainThread(Callable callable) { + if(!this.isCallingFromMinecraftThread()) { + ListenableFutureTask task = ListenableFutureTask.create(callable); + + synchronized(this.futureTaskQueue) { + this.futureTaskQueue.add(task); + return task; + } + } + else { + try { + return Futures.immediateFuture(callable.call()); + } + catch(Exception e) { + return Futures.immediateFailedCheckedFuture(e); + } + } + } + + public void schedule(Runnable task) { + this.callFromMainThread(Executors.callable(task)); + } + + public boolean isCallingFromMinecraftThread() { + return Thread.currentThread() == this.serverThread; + } + + public int getCompression() { + return this.compression; + } + + public ServerStatusResponse getStatus() { + return this.status; + } + + public String getForwardHost() { + return this.forwardHost; + } + + public int getForwardPort() { + return this.forwardPort; + } + + public boolean isUsingEPoll() { + return this.epoll; + } + + public boolean canRegister() { + return this.register; + } + + public boolean isCheckingCase() { + return this.checkCase; + } + + public int getMinimumPasswordLength() { + return this.minPassLength; + } + + public int getMaximumPasswordAttempts() { + return this.maxAttempts; + } + + public User getUser(String user) { + return this.users.get(user.toLowerCase(Locale.US)); + } + + public void setUser(String user, User password) { + this.users.put(user.toLowerCase(Locale.US), password); + } + + public void setLoggedIn(String user, NetHandlerPlayServer handler) { + this.players.put(user.toLowerCase(Locale.US), handler); + } + + public void setLoggedOut(String user) { + this.players.remove(user.toLowerCase(Locale.US)); + } + + public boolean isLoggedIn(String user) { + return this.players.containsKey(user.toLowerCase(Locale.US)); } } diff --git a/proxy/src/main/java/proxy/nbt/NBTBase.java b/proxy/src/main/java/proxy/nbt/NBTBase.java new file mode 100755 index 0000000..613854d --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTBase.java @@ -0,0 +1,123 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public abstract class NBTBase +{ + public static final String[] NBT_TYPES = new String[] {"END", "BYTE", "SHORT", "INT", "LONG", "FLOAT", "DOUBLE", "BYTE[]", "STRING", "LIST", "COMPOUND", "INT[]"}; + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + abstract void write(DataOutput output) throws IOException; + + abstract void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException; + + public abstract String toString(); + + /** + * Gets the type byte for the tag. + */ + public abstract byte getId(); + + /** + * Creates a new NBTBase object that corresponds with the passed in id. + */ + protected static NBTBase createNewByType(byte id) + { + switch (id) + { + case 0: + return new NBTTagEnd(); + + case 1: + return new NBTTagByte(); + + case 2: + return new NBTTagShort(); + + case 3: + return new NBTTagInt(); + + case 4: + return new NBTTagLong(); + + case 5: + return new NBTTagFloat(); + + case 6: + return new NBTTagDouble(); + + case 7: + return new NBTTagByteArray(); + + case 8: + return new NBTTagString(); + + case 9: + return new NBTTagList(); + + case 10: + return new NBTTagCompound(); + + case 11: + return new NBTTagIntArray(); + + default: + return null; + } + } + + /** + * Creates a clone of the tag. + */ + public abstract NBTBase copy(); + + /** + * Return whether this compound has no tags. + */ + public boolean hasNoTags() + { + return false; + } + + public boolean equals(Object p_equals_1_) + { + if (!(p_equals_1_ instanceof NBTBase)) + { + return false; + } + else + { + NBTBase nbtbase = (NBTBase)p_equals_1_; + return this.getId() == nbtbase.getId(); + } + } + + public int hashCode() + { + return this.getId(); + } + + protected String getString() + { + return this.toString(); + } + + public abstract static class NBTPrimitive extends NBTBase + { + public abstract long getLong(); + + public abstract int getInt(); + + public abstract short getShort(); + + public abstract byte getByte(); + + public abstract double getDouble(); + + public abstract float getFloat(); + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTSizeTracker.java b/proxy/src/main/java/proxy/nbt/NBTSizeTracker.java new file mode 100755 index 0000000..1fd71f8 --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTSizeTracker.java @@ -0,0 +1,31 @@ +package proxy.nbt; + +public class NBTSizeTracker +{ + public static final NBTSizeTracker INFINITE = new NBTSizeTracker(0L) + { + public void read(long bits) + { + } + }; + private final long max; + private long read; + + public NBTSizeTracker(long max) + { + this.max = max; + } + + /** + * Tracks the reading of the given amount of bits(!) + */ + public void read(long bits) + { + this.read += bits / 8L; + + if (this.read > this.max) + { + throw new RuntimeException("Tried to read NBT tag that was too big; tried to allocate: " + this.read + "bytes where max allowed: " + this.max); + } + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagByte.java b/proxy/src/main/java/proxy/nbt/NBTTagByte.java new file mode 100755 index 0000000..c8bfade --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagByte.java @@ -0,0 +1,103 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class NBTTagByte extends NBTBase.NBTPrimitive +{ + /** The byte value for the tag. */ + private byte data; + + NBTTagByte() + { + } + + public NBTTagByte(byte data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeByte(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(72L); + this.data = input.readByte(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)1; + } + + public String toString() + { + return "" + this.data + "b"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagByte(this.data); + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagByte nbttagbyte = (NBTTagByte)p_equals_1_; + return this.data == nbttagbyte.data; + } + else + { + return false; + } + } + + public int hashCode() + { + return super.hashCode() ^ this.data; + } + + public long getLong() + { + return (long)this.data; + } + + public int getInt() + { + return this.data; + } + + public short getShort() + { + return (short)this.data; + } + + public byte getByte() + { + return this.data; + } + + public double getDouble() + { + return (double)this.data; + } + + public float getFloat() + { + return (float)this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagByteArray.java b/proxy/src/main/java/proxy/nbt/NBTTagByteArray.java new file mode 100755 index 0000000..07d43ae --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagByteArray.java @@ -0,0 +1,77 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Arrays; + +public class NBTTagByteArray extends NBTBase +{ + /** The byte array stored in the tag. */ + private byte[] data; + + NBTTagByteArray() + { + } + + public NBTTagByteArray(byte[] data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeInt(this.data.length); + output.write(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(192L); + int i = input.readInt(); + sizeTracker.read((long)(8 * i)); + this.data = new byte[i]; + input.readFully(this.data); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)7; + } + + public String toString() + { + return "[" + this.data.length + " bytes]"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + byte[] abyte = new byte[this.data.length]; + System.arraycopy(this.data, 0, abyte, 0, this.data.length); + return new NBTTagByteArray(abyte); + } + + public boolean equals(Object p_equals_1_) + { + return super.equals(p_equals_1_) ? Arrays.equals(this.data, ((NBTTagByteArray)p_equals_1_).data) : false; + } + + public int hashCode() + { + return super.hashCode() ^ Arrays.hashCode(this.data); + } + + public byte[] getByteArray() + { + return this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagCompound.java b/proxy/src/main/java/proxy/nbt/NBTTagCompound.java new file mode 100755 index 0000000..66810ab --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagCompound.java @@ -0,0 +1,511 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +public class NBTTagCompound extends NBTBase +{ + private Map tagMap = new HashMap(); + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + public void write(DataOutput output) throws IOException + { + for (String s : this.tagMap.keySet()) + { + NBTBase nbtbase = (NBTBase)this.tagMap.get(s); + writeEntry(s, nbtbase, output); + } + + output.writeByte(0); + } + + public void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(384L); + + if (depth > 512) + { + throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512"); + } + else + { + this.tagMap.clear(); + byte b0; + + while ((b0 = readType(input, sizeTracker)) != 0) + { + String s = readKey(input, sizeTracker); + sizeTracker.read((long)(224 + 16 * s.length())); + NBTBase nbtbase = readNBT(b0, s, input, depth + 1, sizeTracker); + + if (this.tagMap.put(s, nbtbase) != null) + { + sizeTracker.read(288L); + } + } + } + } + + public Set getKeySet() + { + return this.tagMap.keySet(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)10; + } + + /** + * Stores the given tag into the map with the given string key. This is mostly used to store tag lists. + */ + public void setTag(String key, NBTBase value) + { + this.tagMap.put(key, value); + } + + /** + * Stores a new NBTTagByte with the given byte value into the map with the given string key. + */ + public void setByte(String key, byte value) + { + this.tagMap.put(key, new NBTTagByte(value)); + } + + /** + * Stores a new NBTTagShort with the given short value into the map with the given string key. + */ + public void setShort(String key, short value) + { + this.tagMap.put(key, new NBTTagShort(value)); + } + + /** + * Stores a new NBTTagInt with the given integer value into the map with the given string key. + */ + public void setInteger(String key, int value) + { + this.tagMap.put(key, new NBTTagInt(value)); + } + + /** + * Stores a new NBTTagLong with the given long value into the map with the given string key. + */ + public void setLong(String key, long value) + { + this.tagMap.put(key, new NBTTagLong(value)); + } + + /** + * Stores a new NBTTagFloat with the given float value into the map with the given string key. + */ + public void setFloat(String key, float value) + { + this.tagMap.put(key, new NBTTagFloat(value)); + } + + /** + * Stores a new NBTTagDouble with the given double value into the map with the given string key. + */ + public void setDouble(String key, double value) + { + this.tagMap.put(key, new NBTTagDouble(value)); + } + + /** + * Stores a new NBTTagString with the given string value into the map with the given string key. + */ + public void setString(String key, String value) + { + this.tagMap.put(key, new NBTTagString(value)); + } + + /** + * Stores a new NBTTagByteArray with the given array as data into the map with the given string key. + */ + public void setByteArray(String key, byte[] value) + { + this.tagMap.put(key, new NBTTagByteArray(value)); + } + + /** + * Stores a new NBTTagIntArray with the given array as data into the map with the given string key. + */ + public void setIntArray(String key, int[] value) + { + this.tagMap.put(key, new NBTTagIntArray(value)); + } + + /** + * Stores the given boolean value as a NBTTagByte, storing 1 for true and 0 for false, using the given string key. + */ + public void setBoolean(String key, boolean value) + { + this.setByte(key, (byte)(value ? 1 : 0)); + } + + /** + * gets a generic tag with the specified name + */ + public NBTBase getTag(String key) + { + return (NBTBase)this.tagMap.get(key); + } + + /** + * Gets the ID byte for the given tag key + */ + public byte getTagId(String key) + { + NBTBase nbtbase = (NBTBase)this.tagMap.get(key); + return nbtbase != null ? nbtbase.getId() : 0; + } + + /** + * Returns whether the given string has been previously stored as a key in the map. + */ + public boolean hasKey(String key) + { + return this.tagMap.containsKey(key); + } + + public boolean hasKey(String key, int type) + { + int i = this.getTagId(key); + + if (i == type) + { + return true; + } + else if (type != 99) + { + if (i > 0) + { + ; + } + + return false; + } + else + { + return i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6; + } + } + + /** + * Retrieves a byte value using the specified key, or 0 if no such key was stored. + */ + public byte getByte(String key) + { + try + { + return !this.hasKey(key, 99) ? 0 : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getByte(); + } + catch (ClassCastException var3) + { + return (byte)0; + } + } + + /** + * Retrieves a short value using the specified key, or 0 if no such key was stored. + */ + public short getShort(String key) + { + try + { + return !this.hasKey(key, 99) ? 0 : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getShort(); + } + catch (ClassCastException var3) + { + return (short)0; + } + } + + /** + * Retrieves an integer value using the specified key, or 0 if no such key was stored. + */ + public int getInteger(String key) + { + try + { + return !this.hasKey(key, 99) ? 0 : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getInt(); + } + catch (ClassCastException var3) + { + return 0; + } + } + + /** + * Retrieves a long value using the specified key, or 0 if no such key was stored. + */ + public long getLong(String key) + { + try + { + return !this.hasKey(key, 99) ? 0L : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getLong(); + } + catch (ClassCastException var3) + { + return 0L; + } + } + + /** + * Retrieves a float value using the specified key, or 0 if no such key was stored. + */ + public float getFloat(String key) + { + try + { + return !this.hasKey(key, 99) ? 0.0F : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getFloat(); + } + catch (ClassCastException var3) + { + return 0.0F; + } + } + + /** + * Retrieves a double value using the specified key, or 0 if no such key was stored. + */ + public double getDouble(String key) + { + try + { + return !this.hasKey(key, 99) ? 0.0D : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getDouble(); + } + catch (ClassCastException var3) + { + return 0.0D; + } + } + + /** + * Retrieves a string value using the specified key, or an empty string if no such key was stored. + */ + public String getString(String key) + { + try + { + return !this.hasKey(key, 8) ? "" : ((NBTBase)this.tagMap.get(key)).getString(); + } + catch (ClassCastException var3) + { + return ""; + } + } + + /** + * Retrieves a byte array using the specified key, or a zero-length array if no such key was stored. + */ + public byte[] getByteArray(String key) + { + try + { + return !this.hasKey(key, 7) ? new byte[0] : ((NBTTagByteArray)this.tagMap.get(key)).getByteArray(); + } + catch (ClassCastException classcastexception) + { + throw new RuntimeException(classcastexception); + } + } + + /** + * Retrieves an int array using the specified key, or a zero-length array if no such key was stored. + */ + public int[] getIntArray(String key) + { + try + { + return !this.hasKey(key, 11) ? new int[0] : ((NBTTagIntArray)this.tagMap.get(key)).getIntArray(); + } + catch (ClassCastException classcastexception) + { + throw new RuntimeException(classcastexception); + } + } + + /** + * Retrieves a NBTTagCompound subtag matching the specified key, or a new empty NBTTagCompound if no such key was + * stored. + */ + public NBTTagCompound getCompoundTag(String key) + { + try + { + return !this.hasKey(key, 10) ? new NBTTagCompound() : (NBTTagCompound)this.tagMap.get(key); + } + catch (ClassCastException classcastexception) + { + throw new RuntimeException(classcastexception); + } + } + + /** + * Gets the NBTTagList object with the given name. Args: name, NBTBase type + */ + public NBTTagList getTagList(String key, int type) + { + try + { + if (this.getTagId(key) != 9) + { + return new NBTTagList(); + } + else + { + NBTTagList nbttaglist = (NBTTagList)this.tagMap.get(key); + return nbttaglist.tagCount() > 0 && nbttaglist.getTagType() != type ? new NBTTagList() : nbttaglist; + } + } + catch (ClassCastException classcastexception) + { + throw new RuntimeException(classcastexception); + } + } + + /** + * Retrieves a boolean value using the specified key, or false if no such key was stored. This uses the getByte + * method. + */ + public boolean getBoolean(String key) + { + return this.getByte(key) != 0; + } + + /** + * Remove the specified tag. + */ + public void removeTag(String key) + { + this.tagMap.remove(key); + } + + public String toString() + { + StringBuilder stringbuilder = new StringBuilder("{"); + + for (Entry entry : this.tagMap.entrySet()) + { + if (stringbuilder.length() != 1) + { + stringbuilder.append(','); + } + + stringbuilder.append((String)entry.getKey()).append(':').append(entry.getValue()); + } + + return stringbuilder.append('}').toString(); + } + + /** + * Return whether this compound has no tags. + */ + public boolean hasNoTags() + { + return this.tagMap.isEmpty(); + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + + for (String s : this.tagMap.keySet()) + { + nbttagcompound.setTag(s, ((NBTBase)this.tagMap.get(s)).copy()); + } + + return nbttagcompound; + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagCompound nbttagcompound = (NBTTagCompound)p_equals_1_; + return this.tagMap.entrySet().equals(nbttagcompound.tagMap.entrySet()); + } + else + { + return false; + } + } + + public int hashCode() + { + return super.hashCode() ^ this.tagMap.hashCode(); + } + + private static void writeEntry(String name, NBTBase data, DataOutput output) throws IOException + { + output.writeByte(data.getId()); + + if (data.getId() != 0) + { + output.writeUTF(name); + data.write(output); + } + } + + private static byte readType(DataInput input, NBTSizeTracker sizeTracker) throws IOException + { + return input.readByte(); + } + + private static String readKey(DataInput input, NBTSizeTracker sizeTracker) throws IOException + { + return input.readUTF(); + } + + static NBTBase readNBT(byte id, String key, DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + NBTBase nbtbase = NBTBase.createNewByType(id); + + nbtbase.read(input, depth, sizeTracker); + return nbtbase; + } + + /** + * Merges this NBTTagCompound with the given compound. Any sub-compounds are merged using the same methods, other + * types of tags are overwritten from the given compound. + */ + public void merge(NBTTagCompound other) + { + for (String s : other.tagMap.keySet()) + { + NBTBase nbtbase = (NBTBase)other.tagMap.get(s); + + if (nbtbase.getId() == 10) + { + if (this.hasKey(s, 10)) + { + NBTTagCompound nbttagcompound = this.getCompoundTag(s); + nbttagcompound.merge((NBTTagCompound)nbtbase); + } + else + { + this.setTag(s, nbtbase.copy()); + } + } + else + { + this.setTag(s, nbtbase.copy()); + } + } + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagDouble.java b/proxy/src/main/java/proxy/nbt/NBTTagDouble.java new file mode 100755 index 0000000..9db369b --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagDouble.java @@ -0,0 +1,106 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import proxy.util.MathHelper; + +public class NBTTagDouble extends NBTBase.NBTPrimitive +{ + /** The double value for the tag. */ + private double data; + + NBTTagDouble() + { + } + + public NBTTagDouble(double data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeDouble(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(128L); + this.data = input.readDouble(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)6; + } + + public String toString() + { + return "" + this.data + "d"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagDouble(this.data); + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagDouble nbttagdouble = (NBTTagDouble)p_equals_1_; + return this.data == nbttagdouble.data; + } + else + { + return false; + } + } + + public int hashCode() + { + long i = Double.doubleToLongBits(this.data); + return super.hashCode() ^ (int)(i ^ i >>> 32); + } + + public long getLong() + { + return (long)Math.floor(this.data); + } + + public int getInt() + { + return MathHelper.floor_double(this.data); + } + + public short getShort() + { + return (short)(MathHelper.floor_double(this.data) & 65535); + } + + public byte getByte() + { + return (byte)(MathHelper.floor_double(this.data) & 255); + } + + public double getDouble() + { + return this.data; + } + + public float getFloat() + { + return (float)this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagEnd.java b/proxy/src/main/java/proxy/nbt/NBTTagEnd.java new file mode 100755 index 0000000..a0edc95 --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagEnd.java @@ -0,0 +1,41 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class NBTTagEnd extends NBTBase +{ + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(64L); + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)0; + } + + public String toString() + { + return "END"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagEnd(); + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagFloat.java b/proxy/src/main/java/proxy/nbt/NBTTagFloat.java new file mode 100755 index 0000000..2473b16 --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagFloat.java @@ -0,0 +1,105 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import proxy.util.MathHelper; + +public class NBTTagFloat extends NBTBase.NBTPrimitive +{ + /** The float value for the tag. */ + private float data; + + NBTTagFloat() + { + } + + public NBTTagFloat(float data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeFloat(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(96L); + this.data = input.readFloat(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)5; + } + + public String toString() + { + return "" + this.data + "f"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagFloat(this.data); + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagFloat nbttagfloat = (NBTTagFloat)p_equals_1_; + return this.data == nbttagfloat.data; + } + else + { + return false; + } + } + + public int hashCode() + { + return super.hashCode() ^ Float.floatToIntBits(this.data); + } + + public long getLong() + { + return (long)this.data; + } + + public int getInt() + { + return MathHelper.floor_float(this.data); + } + + public short getShort() + { + return (short)(MathHelper.floor_float(this.data) & 65535); + } + + public byte getByte() + { + return (byte)(MathHelper.floor_float(this.data) & 255); + } + + public double getDouble() + { + return (double)this.data; + } + + public float getFloat() + { + return this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagInt.java b/proxy/src/main/java/proxy/nbt/NBTTagInt.java new file mode 100755 index 0000000..90c9ff4 --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagInt.java @@ -0,0 +1,103 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class NBTTagInt extends NBTBase.NBTPrimitive +{ + /** The integer value for the tag. */ + private int data; + + NBTTagInt() + { + } + + public NBTTagInt(int data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeInt(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(96L); + this.data = input.readInt(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)3; + } + + public String toString() + { + return "" + this.data; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagInt(this.data); + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagInt nbttagint = (NBTTagInt)p_equals_1_; + return this.data == nbttagint.data; + } + else + { + return false; + } + } + + public int hashCode() + { + return super.hashCode() ^ this.data; + } + + public long getLong() + { + return (long)this.data; + } + + public int getInt() + { + return this.data; + } + + public short getShort() + { + return (short)(this.data & 65535); + } + + public byte getByte() + { + return (byte)(this.data & 255); + } + + public double getDouble() + { + return (double)this.data; + } + + public float getFloat() + { + return (float)this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagIntArray.java b/proxy/src/main/java/proxy/nbt/NBTTagIntArray.java new file mode 100755 index 0000000..30eeddf --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagIntArray.java @@ -0,0 +1,92 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Arrays; + +public class NBTTagIntArray extends NBTBase +{ + /** The array of saved integers */ + private int[] intArray; + + NBTTagIntArray() + { + } + + public NBTTagIntArray(int[] p_i45132_1_) + { + this.intArray = p_i45132_1_; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeInt(this.intArray.length); + + for (int i = 0; i < this.intArray.length; ++i) + { + output.writeInt(this.intArray[i]); + } + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(192L); + int i = input.readInt(); + sizeTracker.read((long)(32 * i)); + this.intArray = new int[i]; + + for (int j = 0; j < i; ++j) + { + this.intArray[j] = input.readInt(); + } + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)11; + } + + public String toString() + { + String s = "["; + + for (int i : this.intArray) + { + s = s + i + ","; + } + + return s + "]"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + int[] aint = new int[this.intArray.length]; + System.arraycopy(this.intArray, 0, aint, 0, this.intArray.length); + return new NBTTagIntArray(aint); + } + + public boolean equals(Object p_equals_1_) + { + return super.equals(p_equals_1_) ? Arrays.equals(this.intArray, ((NBTTagIntArray)p_equals_1_).intArray) : false; + } + + public int hashCode() + { + return super.hashCode() ^ Arrays.hashCode(this.intArray); + } + + public int[] getIntArray() + { + return this.intArray; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagList.java b/proxy/src/main/java/proxy/nbt/NBTTagList.java new file mode 100755 index 0000000..c7741ba --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagList.java @@ -0,0 +1,299 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import proxy.util.Log; + +public class NBTTagList extends NBTBase +{ + private List tagList = new ArrayList(); + + /** + * The type byte for the tags in the list - they must all be of the same type. + */ + private byte tagType = 0; + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + if (!this.tagList.isEmpty()) + { + this.tagType = ((NBTBase)this.tagList.get(0)).getId(); + } + else + { + this.tagType = 0; + } + + output.writeByte(this.tagType); + output.writeInt(this.tagList.size()); + + for (int i = 0; i < this.tagList.size(); ++i) + { + ((NBTBase)this.tagList.get(i)).write(output); + } + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(296L); + + if (depth > 512) + { + throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512"); + } + else + { + this.tagType = input.readByte(); + int i = input.readInt(); + + if (this.tagType == 0 && i > 0) + { + throw new RuntimeException("Missing type on ListTag"); + } + else + { + sizeTracker.read(32L * (long)i); + this.tagList = new ArrayList(i); + + for (int j = 0; j < i; ++j) + { + NBTBase nbtbase = NBTBase.createNewByType(this.tagType); + nbtbase.read(input, depth + 1, sizeTracker); + this.tagList.add(nbtbase); + } + } + } + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)9; + } + + public String toString() + { + StringBuilder stringbuilder = new StringBuilder("["); + + for (int i = 0; i < this.tagList.size(); ++i) + { + if (i != 0) + { + stringbuilder.append(','); + } + + stringbuilder.append(i).append(':').append(this.tagList.get(i)); + } + + return stringbuilder.append(']').toString(); + } + + /** + * Adds the provided tag to the end of the list. There is no check to verify this tag is of the same type as any + * previous tag. + */ + public void appendTag(NBTBase nbt) + { + if (nbt.getId() == 0) + { + Log.warn("Invalid TagEnd added to ListTag"); + } + else + { + if (this.tagType == 0) + { + this.tagType = nbt.getId(); + } + else if (this.tagType != nbt.getId()) + { + Log.warn("Adding mismatching tag types to tag list"); + return; + } + + this.tagList.add(nbt); + } + } + + /** + * Set the given index to the given tag + */ + public void set(int idx, NBTBase nbt) + { + if (nbt.getId() == 0) + { + Log.warn("Invalid TagEnd added to ListTag"); + } + else if (idx >= 0 && idx < this.tagList.size()) + { + if (this.tagType == 0) + { + this.tagType = nbt.getId(); + } + else if (this.tagType != nbt.getId()) + { + Log.warn("Adding mismatching tag types to tag list"); + return; + } + + this.tagList.set(idx, nbt); + } + else + { + Log.warn("index out of bounds to set tag in tag list"); + } + } + + /** + * Removes a tag at the given index. + */ + public NBTBase removeTag(int i) + { + return (NBTBase)this.tagList.remove(i); + } + + /** + * Return whether this compound has no tags. + */ + public boolean hasNoTags() + { + return this.tagList.isEmpty(); + } + + /** + * Retrieves the NBTTagCompound at the specified index in the list + */ + public NBTTagCompound getCompoundTagAt(int i) + { + if (i >= 0 && i < this.tagList.size()) + { + NBTBase nbtbase = (NBTBase)this.tagList.get(i); + return nbtbase.getId() == 10 ? (NBTTagCompound)nbtbase : new NBTTagCompound(); + } + else + { + return new NBTTagCompound(); + } + } + + public int[] getIntArrayAt(int i) + { + if (i >= 0 && i < this.tagList.size()) + { + NBTBase nbtbase = (NBTBase)this.tagList.get(i); + return nbtbase.getId() == 11 ? ((NBTTagIntArray)nbtbase).getIntArray() : new int[0]; + } + else + { + return new int[0]; + } + } + + public double getDoubleAt(int i) + { + if (i >= 0 && i < this.tagList.size()) + { + NBTBase nbtbase = (NBTBase)this.tagList.get(i); + return nbtbase.getId() == 6 ? ((NBTTagDouble)nbtbase).getDouble() : 0.0D; + } + else + { + return 0.0D; + } + } + + public float getFloatAt(int i) + { + if (i >= 0 && i < this.tagList.size()) + { + NBTBase nbtbase = (NBTBase)this.tagList.get(i); + return nbtbase.getId() == 5 ? ((NBTTagFloat)nbtbase).getFloat() : 0.0F; + } + else + { + return 0.0F; + } + } + + /** + * Retrieves the tag String value at the specified index in the list + */ + public String getStringTagAt(int i) + { + if (i >= 0 && i < this.tagList.size()) + { + NBTBase nbtbase = (NBTBase)this.tagList.get(i); + return nbtbase.getId() == 8 ? nbtbase.getString() : nbtbase.toString(); + } + else + { + return ""; + } + } + + /** + * Get the tag at the given position + */ + public NBTBase get(int idx) + { + return (NBTBase)(idx >= 0 && idx < this.tagList.size() ? (NBTBase)this.tagList.get(idx) : new NBTTagEnd()); + } + + /** + * Returns the number of tags in the list. + */ + public int tagCount() + { + return this.tagList.size(); + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + NBTTagList nbttaglist = new NBTTagList(); + nbttaglist.tagType = this.tagType; + + for (NBTBase nbtbase : this.tagList) + { + NBTBase nbtbase1 = nbtbase.copy(); + nbttaglist.tagList.add(nbtbase1); + } + + return nbttaglist; + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagList nbttaglist = (NBTTagList)p_equals_1_; + + if (this.tagType == nbttaglist.tagType) + { + return this.tagList.equals(nbttaglist.tagList); + } + } + + return false; + } + + public int hashCode() + { + return super.hashCode() ^ this.tagList.hashCode(); + } + + public int getTagType() + { + return this.tagType; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagLong.java b/proxy/src/main/java/proxy/nbt/NBTTagLong.java new file mode 100755 index 0000000..9f2d04e --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagLong.java @@ -0,0 +1,103 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class NBTTagLong extends NBTBase.NBTPrimitive +{ + /** The long value for the tag. */ + private long data; + + NBTTagLong() + { + } + + public NBTTagLong(long data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeLong(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(128L); + this.data = input.readLong(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)4; + } + + public String toString() + { + return "" + this.data + "L"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagLong(this.data); + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagLong nbttaglong = (NBTTagLong)p_equals_1_; + return this.data == nbttaglong.data; + } + else + { + return false; + } + } + + public int hashCode() + { + return super.hashCode() ^ (int)(this.data ^ this.data >>> 32); + } + + public long getLong() + { + return this.data; + } + + public int getInt() + { + return (int)(this.data & -1L); + } + + public short getShort() + { + return (short)((int)(this.data & 65535L)); + } + + public byte getByte() + { + return (byte)((int)(this.data & 255L)); + } + + public double getDouble() + { + return (double)this.data; + } + + public float getFloat() + { + return (float)this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagShort.java b/proxy/src/main/java/proxy/nbt/NBTTagShort.java new file mode 100755 index 0000000..d5413d3 --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagShort.java @@ -0,0 +1,103 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class NBTTagShort extends NBTBase.NBTPrimitive +{ + /** The short value for the tag. */ + private short data; + + public NBTTagShort() + { + } + + public NBTTagShort(short data) + { + this.data = data; + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeShort(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(80L); + this.data = input.readShort(); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)2; + } + + public String toString() + { + return "" + this.data + "s"; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagShort(this.data); + } + + public boolean equals(Object p_equals_1_) + { + if (super.equals(p_equals_1_)) + { + NBTTagShort nbttagshort = (NBTTagShort)p_equals_1_; + return this.data == nbttagshort.data; + } + else + { + return false; + } + } + + public int hashCode() + { + return super.hashCode() ^ this.data; + } + + public long getLong() + { + return (long)this.data; + } + + public int getInt() + { + return this.data; + } + + public short getShort() + { + return this.data; + } + + public byte getByte() + { + return (byte)(this.data & 255); + } + + public double getDouble() + { + return (double)this.data; + } + + public float getFloat() + { + return (float)this.data; + } +} diff --git a/proxy/src/main/java/proxy/nbt/NBTTagString.java b/proxy/src/main/java/proxy/nbt/NBTTagString.java new file mode 100755 index 0000000..9ed386d --- /dev/null +++ b/proxy/src/main/java/proxy/nbt/NBTTagString.java @@ -0,0 +1,93 @@ +package proxy.nbt; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class NBTTagString extends NBTBase +{ + /** The string value for the tag (cannot be empty). */ + private String data; + + public NBTTagString() + { + this.data = ""; + } + + public NBTTagString(String data) + { + this.data = data; + + if (data == null) + { + throw new IllegalArgumentException("Empty string not allowed"); + } + } + + /** + * Write the actual data contents of the tag, implemented in NBT extension classes + */ + void write(DataOutput output) throws IOException + { + output.writeUTF(this.data); + } + + void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException + { + sizeTracker.read(288L); + this.data = input.readUTF(); + sizeTracker.read((long)(16 * this.data.length())); + } + + /** + * Gets the type byte for the tag. + */ + public byte getId() + { + return (byte)8; + } + + public String toString() + { + return "\"" + this.data.replace("\"", "\\\"") + "\""; + } + + /** + * Creates a clone of the tag. + */ + public NBTBase copy() + { + return new NBTTagString(this.data); + } + + /** + * Return whether this compound has no tags. + */ + public boolean hasNoTags() + { + return this.data.isEmpty(); + } + + public boolean equals(Object p_equals_1_) + { + if (!super.equals(p_equals_1_)) + { + return false; + } + else + { + NBTTagString nbttagstring = (NBTTagString)p_equals_1_; + return this.data == null && nbttagstring.data == null || this.data != null && this.data.equals(nbttagstring.data); + } + } + + public int hashCode() + { + return super.hashCode() ^ this.data.hashCode(); + } + + public String getString() + { + return this.data; + } +} diff --git a/proxy/src/main/java/proxy/network/EnumConnectionState.java b/proxy/src/main/java/proxy/network/EnumConnectionState.java new file mode 100755 index 0000000..0e81f5f --- /dev/null +++ b/proxy/src/main/java/proxy/network/EnumConnectionState.java @@ -0,0 +1,347 @@ +package proxy.network; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.Maps; + +import net.minecraft.network.handshake.client.C00Handshake; +import net.minecraft.network.login.client.C00PacketLoginStart; +import net.minecraft.network.login.client.C01PacketEncryptionResponse; +import net.minecraft.network.login.server.S00PacketDisconnect; +import net.minecraft.network.login.server.S01PacketEncryptionRequest; +import net.minecraft.network.login.server.S02PacketLoginSuccess; +import net.minecraft.network.login.server.S03PacketEnableCompression; +import net.minecraft.network.play.client.C00PacketKeepAlive; +import net.minecraft.network.play.client.C01PacketChatMessage; +import net.minecraft.network.play.client.C02PacketUseEntity; +import net.minecraft.network.play.client.C03PacketPlayer; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; +import net.minecraft.network.play.client.C09PacketHeldItemChange; +import net.minecraft.network.play.client.C0APacketAnimation; +import net.minecraft.network.play.client.C0BPacketEntityAction; +import net.minecraft.network.play.client.C0CPacketInput; +import net.minecraft.network.play.client.C0DPacketCloseWindow; +import net.minecraft.network.play.client.C0EPacketClickWindow; +import net.minecraft.network.play.client.C0FPacketConfirmTransaction; +import net.minecraft.network.play.client.C10PacketCreativeInventoryAction; +import net.minecraft.network.play.client.C11PacketEnchantItem; +import net.minecraft.network.play.client.C12PacketUpdateSign; +import net.minecraft.network.play.client.C13PacketPlayerAbilities; +import net.minecraft.network.play.client.C14PacketTabComplete; +import net.minecraft.network.play.client.C15PacketClientSettings; +import net.minecraft.network.play.client.C16PacketClientStatus; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.client.C18PacketSpectate; +import net.minecraft.network.play.client.C19PacketResourcePackStatus; +import net.minecraft.network.play.server.S00PacketKeepAlive; +import net.minecraft.network.play.server.S01PacketJoinGame; +import net.minecraft.network.play.server.S02PacketChat; +import net.minecraft.network.play.server.S03PacketTimeUpdate; +import net.minecraft.network.play.server.S04PacketEntityEquipment; +import net.minecraft.network.play.server.S05PacketSpawnPosition; +import net.minecraft.network.play.server.S06PacketUpdateHealth; +import net.minecraft.network.play.server.S07PacketRespawn; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import net.minecraft.network.play.server.S09PacketHeldItemChange; +import net.minecraft.network.play.server.S0APacketUseBed; +import net.minecraft.network.play.server.S0BPacketAnimation; +import net.minecraft.network.play.server.S0CPacketSpawnPlayer; +import net.minecraft.network.play.server.S0DPacketCollectItem; +import net.minecraft.network.play.server.S0EPacketSpawnObject; +import net.minecraft.network.play.server.S0FPacketSpawnMob; +import net.minecraft.network.play.server.S10PacketSpawnPainting; +import net.minecraft.network.play.server.S11PacketSpawnExperienceOrb; +import net.minecraft.network.play.server.S12PacketEntityVelocity; +import net.minecraft.network.play.server.S13PacketDestroyEntities; +import net.minecraft.network.play.server.S14PacketEntity; +import net.minecraft.network.play.server.S18PacketEntityTeleport; +import net.minecraft.network.play.server.S19PacketEntityHeadLook; +import net.minecraft.network.play.server.S19PacketEntityStatus; +import net.minecraft.network.play.server.S1BPacketEntityAttach; +import net.minecraft.network.play.server.S1CPacketEntityMetadata; +import net.minecraft.network.play.server.S1DPacketEntityEffect; +import net.minecraft.network.play.server.S1EPacketRemoveEntityEffect; +import net.minecraft.network.play.server.S1FPacketSetExperience; +import net.minecraft.network.play.server.S20PacketEntityProperties; +import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.network.play.server.S22PacketMultiBlockChange; +import net.minecraft.network.play.server.S23PacketBlockChange; +import net.minecraft.network.play.server.S24PacketBlockAction; +import net.minecraft.network.play.server.S25PacketBlockBreakAnim; +import net.minecraft.network.play.server.S26PacketMapChunkBulk; +import net.minecraft.network.play.server.S27PacketExplosion; +import net.minecraft.network.play.server.S28PacketEffect; +import net.minecraft.network.play.server.S29PacketSoundEffect; +import net.minecraft.network.play.server.S2APacketParticles; +import net.minecraft.network.play.server.S2BPacketChangeGameState; +import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity; +import net.minecraft.network.play.server.S2DPacketOpenWindow; +import net.minecraft.network.play.server.S2EPacketCloseWindow; +import net.minecraft.network.play.server.S2FPacketSetSlot; +import net.minecraft.network.play.server.S30PacketWindowItems; +import net.minecraft.network.play.server.S31PacketWindowProperty; +import net.minecraft.network.play.server.S32PacketConfirmTransaction; +import net.minecraft.network.play.server.S33PacketUpdateSign; +import net.minecraft.network.play.server.S34PacketMaps; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.network.play.server.S36PacketSignEditorOpen; +import net.minecraft.network.play.server.S37PacketStatistics; +import net.minecraft.network.play.server.S38PacketPlayerListItem; +import net.minecraft.network.play.server.S39PacketPlayerAbilities; +import net.minecraft.network.play.server.S3APacketTabComplete; +import net.minecraft.network.play.server.S3BPacketScoreboardObjective; +import net.minecraft.network.play.server.S3CPacketUpdateScore; +import net.minecraft.network.play.server.S3DPacketDisplayScoreboard; +import net.minecraft.network.play.server.S3EPacketTeams; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.network.play.server.S40PacketDisconnect; +import net.minecraft.network.play.server.S41PacketServerDifficulty; +import net.minecraft.network.play.server.S42PacketCombatEvent; +import net.minecraft.network.play.server.S43PacketCamera; +import net.minecraft.network.play.server.S44PacketWorldBorder; +import net.minecraft.network.play.server.S45PacketTitle; +import net.minecraft.network.play.server.S46PacketSetCompressionLevel; +import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter; +import net.minecraft.network.play.server.S48PacketResourcePackSend; +import net.minecraft.network.play.server.S49PacketUpdateEntityNBT; +import net.minecraft.network.status.client.C00PacketServerQuery; +import net.minecraft.network.status.client.C01PacketPing; +import net.minecraft.network.status.server.S00PacketServerInfo; +import net.minecraft.network.status.server.S01PacketPong; +import proxy.util.Log; + +public enum EnumConnectionState +{ + HANDSHAKING(-1) + { + { + this.registerPacket(EnumPacketDirection.SERVERBOUND, C00Handshake.class); + } + }, + PLAY(0) + { + { + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S00PacketKeepAlive.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S01PacketJoinGame.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S02PacketChat.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S03PacketTimeUpdate.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S04PacketEntityEquipment.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S05PacketSpawnPosition.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S06PacketUpdateHealth.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S07PacketRespawn.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S08PacketPlayerPosLook.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S09PacketHeldItemChange.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S0APacketUseBed.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S0BPacketAnimation.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S0CPacketSpawnPlayer.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S0DPacketCollectItem.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S0EPacketSpawnObject.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S0FPacketSpawnMob.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S10PacketSpawnPainting.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S11PacketSpawnExperienceOrb.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S12PacketEntityVelocity.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S13PacketDestroyEntities.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S14PacketEntity.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S14PacketEntity.S15PacketEntityRelMove.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S14PacketEntity.S16PacketEntityLook.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S14PacketEntity.S17PacketEntityLookMove.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S18PacketEntityTeleport.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S19PacketEntityHeadLook.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S19PacketEntityStatus.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S1BPacketEntityAttach.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S1CPacketEntityMetadata.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S1DPacketEntityEffect.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S1EPacketRemoveEntityEffect.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S1FPacketSetExperience.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S20PacketEntityProperties.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S21PacketChunkData.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S22PacketMultiBlockChange.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S23PacketBlockChange.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S24PacketBlockAction.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S25PacketBlockBreakAnim.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S26PacketMapChunkBulk.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S27PacketExplosion.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S28PacketEffect.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S29PacketSoundEffect.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S2APacketParticles.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S2BPacketChangeGameState.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S2CPacketSpawnGlobalEntity.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S2DPacketOpenWindow.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S2EPacketCloseWindow.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S2FPacketSetSlot.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S30PacketWindowItems.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S31PacketWindowProperty.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S32PacketConfirmTransaction.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S33PacketUpdateSign.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S34PacketMaps.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S35PacketUpdateTileEntity.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S36PacketSignEditorOpen.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S37PacketStatistics.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S38PacketPlayerListItem.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S39PacketPlayerAbilities.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S3APacketTabComplete.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S3BPacketScoreboardObjective.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S3CPacketUpdateScore.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S3DPacketDisplayScoreboard.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S3EPacketTeams.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S3FPacketCustomPayload.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S40PacketDisconnect.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S41PacketServerDifficulty.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S42PacketCombatEvent.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S43PacketCamera.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S44PacketWorldBorder.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S45PacketTitle.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S46PacketSetCompressionLevel.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S47PacketPlayerListHeaderFooter.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S48PacketResourcePackSend.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S49PacketUpdateEntityNBT.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C00PacketKeepAlive.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C01PacketChatMessage.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C02PacketUseEntity.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C03PacketPlayer.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C03PacketPlayer.C04PacketPlayerPosition.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C03PacketPlayer.C05PacketPlayerLook.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C03PacketPlayer.C06PacketPlayerPosLook.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C07PacketPlayerDigging.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C08PacketPlayerBlockPlacement.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C09PacketHeldItemChange.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C0APacketAnimation.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C0BPacketEntityAction.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C0CPacketInput.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C0DPacketCloseWindow.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C0EPacketClickWindow.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C0FPacketConfirmTransaction.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C10PacketCreativeInventoryAction.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C11PacketEnchantItem.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C12PacketUpdateSign.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C13PacketPlayerAbilities.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C14PacketTabComplete.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C15PacketClientSettings.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C16PacketClientStatus.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C17PacketCustomPayload.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C18PacketSpectate.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C19PacketResourcePackStatus.class); + } + }, + STATUS(1) + { + { + this.registerPacket(EnumPacketDirection.SERVERBOUND, C00PacketServerQuery.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S00PacketServerInfo.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C01PacketPing.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S01PacketPong.class); + } + }, + LOGIN(2) + { + { + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S00PacketDisconnect.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S01PacketEncryptionRequest.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S02PacketLoginSuccess.class); + this.registerPacket(EnumPacketDirection.CLIENTBOUND, S03PacketEnableCompression.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C00PacketLoginStart.class); + this.registerPacket(EnumPacketDirection.SERVERBOUND, C01PacketEncryptionResponse.class); + } + }; + + private static int field_181136_e = -1; + private static int field_181137_f = 2; + private static final EnumConnectionState[] STATES_BY_ID = new EnumConnectionState[field_181137_f - field_181136_e + 1]; + private static final Map < Class , EnumConnectionState > STATES_BY_CLASS = Maps. < Class , EnumConnectionState > newHashMap(); + private final int id; + private final Map < EnumPacketDirection, BiMap < Integer, Class >> directionMaps; + + private EnumConnectionState(int protocolId) + { + this.directionMaps = Maps.newEnumMap(EnumPacketDirection.class); + this.id = protocolId; + } + + protected EnumConnectionState registerPacket(EnumPacketDirection direction, Class packetClass) + { + BiMap < Integer, Class > bimap = (BiMap)this.directionMaps.get(direction); + + if (bimap == null) + { + bimap = HashBiMap. < Integer, Class > create(); + this.directionMaps.put(direction, bimap); + } + + if (bimap.containsValue(packetClass)) + { + String s = direction + " packet " + packetClass + " is already known to ID " + bimap.inverse().get(packetClass); + Log.error(s); + throw new IllegalArgumentException(s); + } + else + { + bimap.put(Integer.valueOf(bimap.size()), packetClass); + return this; + } + } + + public Integer getPacketId(EnumPacketDirection direction, Packet packetIn) + { + return (Integer)((BiMap)this.directionMaps.get(direction)).inverse().get(packetIn.getClass()); + } + + public Packet getPacket(EnumPacketDirection direction, int packetId) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + Class oclass = (Class)((BiMap)this.directionMaps.get(direction)).get(Integer.valueOf(packetId)); + return oclass == null ? null : (Packet)oclass.getConstructor().newInstance(); + } + + public int getId() + { + return this.id; + } + + public static EnumConnectionState getById(int stateId) + { + return stateId >= field_181136_e && stateId <= field_181137_f ? STATES_BY_ID[stateId - field_181136_e] : null; + } + + public static EnumConnectionState getFromPacket(Packet packetIn) + { + return (EnumConnectionState)STATES_BY_CLASS.get(packetIn.getClass()); + } + + static { + for (EnumConnectionState enumconnectionstate : values()) + { + int i = enumconnectionstate.getId(); + + if (i < field_181136_e || i > field_181137_f) + { + throw new Error("Invalid protocol ID " + Integer.toString(i)); + } + + STATES_BY_ID[i - field_181136_e] = enumconnectionstate; + + for (EnumPacketDirection enumpacketdirection : enumconnectionstate.directionMaps.keySet()) + { + for (Class oclass : (enumconnectionstate.directionMaps.get(enumpacketdirection)).values()) + { + if (STATES_BY_CLASS.containsKey(oclass) && STATES_BY_CLASS.get(oclass) != enumconnectionstate) + { + throw new Error("Packet " + oclass + " is already assigned to protocol " + STATES_BY_CLASS.get(oclass) + " - can\'t reassign to " + enumconnectionstate); + } + + try + { + oclass.getConstructor().newInstance(); + } + catch (Throwable var10) + { + throw new Error("Packet " + oclass + " fails instantiation checks! " + oclass); + } + + STATES_BY_CLASS.put(oclass, enumconnectionstate); + } + } + } + } +} diff --git a/proxy/src/main/java/proxy/network/EnumPacketDirection.java b/proxy/src/main/java/proxy/network/EnumPacketDirection.java new file mode 100755 index 0000000..b4a0a0f --- /dev/null +++ b/proxy/src/main/java/proxy/network/EnumPacketDirection.java @@ -0,0 +1,5 @@ +package proxy.network; + +public enum EnumPacketDirection { + SERVERBOUND, CLIENTBOUND; +} diff --git a/proxy/src/main/java/proxy/network/INetHandler.java b/proxy/src/main/java/proxy/network/INetHandler.java new file mode 100755 index 0000000..5d82aeb --- /dev/null +++ b/proxy/src/main/java/proxy/network/INetHandler.java @@ -0,0 +1,7 @@ +package proxy.network; + +import proxy.util.ChatComponent; + +public interface INetHandler { + void onDisconnect(NetworkManager connection, ChatComponent reason); +} diff --git a/proxy/src/main/java/proxy/network/INetHandlerPlayClient.java b/proxy/src/main/java/proxy/network/INetHandlerPlayClient.java new file mode 100755 index 0000000..40e3ff7 --- /dev/null +++ b/proxy/src/main/java/proxy/network/INetHandlerPlayClient.java @@ -0,0 +1,384 @@ +package proxy.network; + +import net.minecraft.network.play.server.S00PacketKeepAlive; +import net.minecraft.network.play.server.S01PacketJoinGame; +import net.minecraft.network.play.server.S02PacketChat; +import net.minecraft.network.play.server.S03PacketTimeUpdate; +import net.minecraft.network.play.server.S04PacketEntityEquipment; +import net.minecraft.network.play.server.S05PacketSpawnPosition; +import net.minecraft.network.play.server.S06PacketUpdateHealth; +import net.minecraft.network.play.server.S07PacketRespawn; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import net.minecraft.network.play.server.S09PacketHeldItemChange; +import net.minecraft.network.play.server.S0APacketUseBed; +import net.minecraft.network.play.server.S0BPacketAnimation; +import net.minecraft.network.play.server.S0CPacketSpawnPlayer; +import net.minecraft.network.play.server.S0DPacketCollectItem; +import net.minecraft.network.play.server.S0EPacketSpawnObject; +import net.minecraft.network.play.server.S0FPacketSpawnMob; +import net.minecraft.network.play.server.S10PacketSpawnPainting; +import net.minecraft.network.play.server.S11PacketSpawnExperienceOrb; +import net.minecraft.network.play.server.S12PacketEntityVelocity; +import net.minecraft.network.play.server.S13PacketDestroyEntities; +import net.minecraft.network.play.server.S14PacketEntity; +import net.minecraft.network.play.server.S18PacketEntityTeleport; +import net.minecraft.network.play.server.S19PacketEntityHeadLook; +import net.minecraft.network.play.server.S19PacketEntityStatus; +import net.minecraft.network.play.server.S1BPacketEntityAttach; +import net.minecraft.network.play.server.S1CPacketEntityMetadata; +import net.minecraft.network.play.server.S1DPacketEntityEffect; +import net.minecraft.network.play.server.S1EPacketRemoveEntityEffect; +import net.minecraft.network.play.server.S1FPacketSetExperience; +import net.minecraft.network.play.server.S20PacketEntityProperties; +import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.network.play.server.S22PacketMultiBlockChange; +import net.minecraft.network.play.server.S23PacketBlockChange; +import net.minecraft.network.play.server.S24PacketBlockAction; +import net.minecraft.network.play.server.S25PacketBlockBreakAnim; +import net.minecraft.network.play.server.S26PacketMapChunkBulk; +import net.minecraft.network.play.server.S27PacketExplosion; +import net.minecraft.network.play.server.S28PacketEffect; +import net.minecraft.network.play.server.S29PacketSoundEffect; +import net.minecraft.network.play.server.S2APacketParticles; +import net.minecraft.network.play.server.S2BPacketChangeGameState; +import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity; +import net.minecraft.network.play.server.S2DPacketOpenWindow; +import net.minecraft.network.play.server.S2EPacketCloseWindow; +import net.minecraft.network.play.server.S2FPacketSetSlot; +import net.minecraft.network.play.server.S30PacketWindowItems; +import net.minecraft.network.play.server.S31PacketWindowProperty; +import net.minecraft.network.play.server.S32PacketConfirmTransaction; +import net.minecraft.network.play.server.S33PacketUpdateSign; +import net.minecraft.network.play.server.S34PacketMaps; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.network.play.server.S36PacketSignEditorOpen; +import net.minecraft.network.play.server.S37PacketStatistics; +import net.minecraft.network.play.server.S38PacketPlayerListItem; +import net.minecraft.network.play.server.S39PacketPlayerAbilities; +import net.minecraft.network.play.server.S3APacketTabComplete; +import net.minecraft.network.play.server.S3BPacketScoreboardObjective; +import net.minecraft.network.play.server.S3CPacketUpdateScore; +import net.minecraft.network.play.server.S3DPacketDisplayScoreboard; +import net.minecraft.network.play.server.S3EPacketTeams; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.network.play.server.S40PacketDisconnect; +import net.minecraft.network.play.server.S41PacketServerDifficulty; +import net.minecraft.network.play.server.S42PacketCombatEvent; +import net.minecraft.network.play.server.S43PacketCamera; +import net.minecraft.network.play.server.S44PacketWorldBorder; +import net.minecraft.network.play.server.S45PacketTitle; +import net.minecraft.network.play.server.S46PacketSetCompressionLevel; +import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter; +import net.minecraft.network.play.server.S48PacketResourcePackSend; +import net.minecraft.network.play.server.S49PacketUpdateEntityNBT; + +public interface INetHandlerPlayClient extends INetHandler +{ + /** + * Spawns an instance of the objecttype indicated by the packet and sets its position and momentum + */ + void handleSpawnObject(S0EPacketSpawnObject packetIn); + + /** + * Spawns an experience orb and sets its value (amount of XP) + */ + void handleSpawnExperienceOrb(S11PacketSpawnExperienceOrb packetIn); + + /** + * Handles globally visible entities. Used in vanilla for lightning bolts + */ + void handleSpawnGlobalEntity(S2CPacketSpawnGlobalEntity packetIn); + + /** + * Spawns the mob entity at the specified location, with the specified rotation, momentum and type. Updates the + * entities Datawatchers with the entity metadata specified in the packet + */ + void handleSpawnMob(S0FPacketSpawnMob packetIn); + + /** + * May create a scoreboard objective, remove an objective from the scoreboard or update an objectives' displayname + */ + void handleScoreboardObjective(S3BPacketScoreboardObjective packetIn); + + /** + * Handles the spawning of a painting object + */ + void handleSpawnPainting(S10PacketSpawnPainting packetIn); + + /** + * Handles the creation of a nearby player entity, sets the position and held item + */ + void handleSpawnPlayer(S0CPacketSpawnPlayer packetIn); + + /** + * Renders a specified animation: Waking up a player, a living entity swinging its currently held item, being hurt + * or receiving a critical hit by normal or magical means + */ + void handleAnimation(S0BPacketAnimation packetIn); + + /** + * Updates the players statistics or achievements + */ + void handleStatistics(S37PacketStatistics packetIn); + + /** + * Updates all registered IWorldAccess instances with destroyBlockInWorldPartially + */ + void handleBlockBreakAnim(S25PacketBlockBreakAnim packetIn); + + /** + * Creates a sign in the specified location if it didn't exist and opens the GUI to edit its text + */ + void handleSignEditorOpen(S36PacketSignEditorOpen packetIn); + + /** + * Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks, + * beacons, skulls, flowerpot + */ + void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn); + + /** + * Triggers Block.onBlockEventReceived, which is implemented in BlockPistonBase for extension/retraction, BlockNote + * for setting the instrument (including audiovisual feedback) and in BlockContainer to set the number of players + * accessing a (Ender)Chest + */ + void handleBlockAction(S24PacketBlockAction packetIn); + + /** + * Updates the block and metadata and generates a blockupdate (and notify the clients) + */ + void handleBlockChange(S23PacketBlockChange packetIn); + + /** + * Prints a chatmessage in the chat GUI + */ + void handleChat(S02PacketChat packetIn); + + /** + * Displays the available command-completion options the server knows of + */ + void handleTabComplete(S3APacketTabComplete packetIn); + + /** + * Received from the servers PlayerManager if between 1 and 64 blocks in a chunk are changed. If only one block + * requires an update, the server sends S23PacketBlockChange and if 64 or more blocks are changed, the server sends + * S21PacketChunkData + */ + void handleMultiBlockChange(S22PacketMultiBlockChange packetIn); + + /** + * Updates the worlds MapStorage with the specified MapData for the specified map-identifier and invokes a + * MapItemRenderer for it + */ + void handleMaps(S34PacketMaps packetIn); + + /** + * Verifies that the server and client are synchronized with respect to the inventory/container opened by the player + * and confirms if it is the case. + */ + void handleConfirmTransaction(S32PacketConfirmTransaction packetIn); + + /** + * Resets the ItemStack held in hand and closes the window that is opened + */ + void handleCloseWindow(S2EPacketCloseWindow packetIn); + + /** + * Handles the placement of a specified ItemStack in a specified container/inventory slot + */ + void handleWindowItems(S30PacketWindowItems packetIn); + + /** + * Displays a GUI by ID. In order starting from id 0: Chest, Workbench, Furnace, Dispenser, Enchanting table, + * Brewing stand, Villager merchant, Beacon, Anvil, Hopper, Dropper, Horse + */ + void handleOpenWindow(S2DPacketOpenWindow packetIn); + + /** + * Sets the progressbar of the opened window to the specified value + */ + void handleWindowProperty(S31PacketWindowProperty packetIn); + + /** + * Handles pickin up an ItemStack or dropping one in your inventory or an open (non-creative) container + */ + void handleSetSlot(S2FPacketSetSlot packetIn); + + /** + * Handles packets that have room for a channel specification. Vanilla implemented channels are "MC|TrList" to + * acquire a MerchantRecipeList trades for a villager merchant, "MC|Brand" which sets the server brand? on the + * player instance and finally "MC|RPack" which the server uses to communicate the identifier of the default server + * resourcepack for the client to load. + */ + void handleCustomPayload(S3FPacketCustomPayload packetIn); + + /** + * Closes the network channel + */ + void handleDisconnect(S40PacketDisconnect packetIn); + + /** + * Retrieves the player identified by the packet, puts him to sleep if possible (and flags whether all players are + * asleep) + */ + void handleUseBed(S0APacketUseBed packetIn); + + /** + * Invokes the entities' handleUpdateHealth method which is implemented in LivingBase (hurt/death), + * MinecartMobSpawner (spawn delay), FireworkRocket & MinecartTNT (explosion), IronGolem (throwing,...), Witch + * (spawn particles), Zombie (villager transformation), Animal (breeding mode particles), Horse (breeding/smoke + * particles), Sheep (...), Tameable (...), Villager (particles for breeding mode, angry and happy), Wolf (...) + */ + void handleEntityStatus(S19PacketEntityStatus packetIn); + + void handleEntityAttach(S1BPacketEntityAttach packetIn); + + /** + * Initiates a new explosion (sound, particles, drop spawn) for the affected blocks indicated by the packet. + */ + void handleExplosion(S27PacketExplosion packetIn); + + void handleChangeGameState(S2BPacketChangeGameState packetIn); + + void handleKeepAlive(S00PacketKeepAlive packetIn); + + /** + * Updates the specified chunk with the supplied data, marks it for re-rendering and lighting recalculation + */ + void handleChunkData(S21PacketChunkData packetIn); + + void handleMapChunkBulk(S26PacketMapChunkBulk packetIn); + + void handleEffect(S28PacketEffect packetIn); + + /** + * Registers some server properties (gametype,hardcore-mode,terraintype,difficulty,player limit), creates a new + * WorldClient and sets the player initial dimension + */ + void handleJoinGame(S01PacketJoinGame packetIn); + + /** + * Updates the specified entity's position by the specified relative moment and absolute rotation. Note that + * subclassing of the packet allows for the specification of a subset of this data (e.g. only rel. position, abs. + * rotation or both). + */ + void handleEntityMovement(S14PacketEntity packetIn); + + /** + * Handles changes in player positioning and rotation such as when travelling to a new dimension, (re)spawning, + * mounting horses etc. Seems to immediately reply to the server with the clients post-processing perspective on the + * player positioning + */ + void handlePlayerPosLook(S08PacketPlayerPosLook packetIn); + + /** + * Spawns a specified number of particles at the specified location with a randomized displacement according to + * specified bounds + */ + void handleParticles(S2APacketParticles packetIn); + + void handlePlayerAbilities(S39PacketPlayerAbilities packetIn); + + void handlePlayerListItem(S38PacketPlayerListItem packetIn); + + /** + * Locally eliminates the entities. Invoked by the server when the items are in fact destroyed, or the player is no + * longer registered as required to monitor them. The latter happens when distance between the player and item + * increases beyond a certain treshold (typically the viewing distance) + */ + void handleDestroyEntities(S13PacketDestroyEntities packetIn); + + void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn); + + void handleRespawn(S07PacketRespawn packetIn); + + /** + * Updates the direction in which the specified entity is looking, normally this head rotation is independent of the + * rotation of the entity itself + */ + void handleEntityHeadLook(S19PacketEntityHeadLook packetIn); + + /** + * Updates which hotbar slot of the player is currently selected + */ + void handleHeldItemChange(S09PacketHeldItemChange packetIn); + + /** + * Removes or sets the ScoreObjective to be displayed at a particular scoreboard position (list, sidebar, below + * name) + */ + void handleDisplayScoreboard(S3DPacketDisplayScoreboard packetIn); + + /** + * Invoked when the server registers new proximate objects in your watchlist or when objects in your watchlist have + * changed -> Registers any changes locally + */ + void handleEntityMetadata(S1CPacketEntityMetadata packetIn); + + /** + * Sets the velocity of the specified entity to the specified value + */ + void handleEntityVelocity(S12PacketEntityVelocity packetIn); + + void handleEntityEquipment(S04PacketEntityEquipment packetIn); + + void handleSetExperience(S1FPacketSetExperience packetIn); + + void handleUpdateHealth(S06PacketUpdateHealth packetIn); + + /** + * Updates a team managed by the scoreboard: Create/Remove the team registration, Register/Remove the player-team- + * memberships, Set team displayname/prefix/suffix and/or whether friendly fire is enabled + */ + void handleTeams(S3EPacketTeams packetIn); + + /** + * Either updates the score with a specified value or removes the score for an objective + */ + void handleUpdateScore(S3CPacketUpdateScore packetIn); + + void handleSpawnPosition(S05PacketSpawnPosition packetIn); + + void handleTimeUpdate(S03PacketTimeUpdate packetIn); + + /** + * Updates a specified sign with the specified text lines + */ + void handleUpdateSign(S33PacketUpdateSign packetIn); + + void handleSoundEffect(S29PacketSoundEffect packetIn); + + void handleCollectItem(S0DPacketCollectItem packetIn); + + /** + * Updates an entity's position and rotation as specified by the packet + */ + void handleEntityTeleport(S18PacketEntityTeleport packetIn); + + /** + * Updates en entity's attributes and their respective modifiers, which are used for speed bonusses (player + * sprinting, animals fleeing, baby speed), weapon/tool attackDamage, hostiles followRange randomization, zombie + * maxHealth and knockback resistance as well as reinforcement spawning chance. + */ + void handleEntityProperties(S20PacketEntityProperties packetIn); + + void handleEntityEffect(S1DPacketEntityEffect packetIn); + + void handleCombatEvent(S42PacketCombatEvent packetIn); + + void handleServerDifficulty(S41PacketServerDifficulty packetIn); + + void handleCamera(S43PacketCamera packetIn); + + void handleWorldBorder(S44PacketWorldBorder packetIn); + + void handleTitle(S45PacketTitle packetIn); + + void handleSetCompressionLevel(S46PacketSetCompressionLevel packetIn); + + void handlePlayerListHeaderFooter(S47PacketPlayerListHeaderFooter packetIn); + + void handleResourcePack(S48PacketResourcePackSend packetIn); + + void handleEntityNBT(S49PacketUpdateEntityNBT packetIn); +} diff --git a/proxy/src/main/java/proxy/network/INetHandlerPlayServer.java b/proxy/src/main/java/proxy/network/INetHandlerPlayServer.java new file mode 100755 index 0000000..7a4a0d7 --- /dev/null +++ b/proxy/src/main/java/proxy/network/INetHandlerPlayServer.java @@ -0,0 +1,143 @@ +package proxy.network; + +import net.minecraft.network.play.client.C00PacketKeepAlive; +import net.minecraft.network.play.client.C01PacketChatMessage; +import net.minecraft.network.play.client.C02PacketUseEntity; +import net.minecraft.network.play.client.C03PacketPlayer; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; +import net.minecraft.network.play.client.C09PacketHeldItemChange; +import net.minecraft.network.play.client.C0APacketAnimation; +import net.minecraft.network.play.client.C0BPacketEntityAction; +import net.minecraft.network.play.client.C0CPacketInput; +import net.minecraft.network.play.client.C0DPacketCloseWindow; +import net.minecraft.network.play.client.C0EPacketClickWindow; +import net.minecraft.network.play.client.C0FPacketConfirmTransaction; +import net.minecraft.network.play.client.C10PacketCreativeInventoryAction; +import net.minecraft.network.play.client.C11PacketEnchantItem; +import net.minecraft.network.play.client.C12PacketUpdateSign; +import net.minecraft.network.play.client.C13PacketPlayerAbilities; +import net.minecraft.network.play.client.C14PacketTabComplete; +import net.minecraft.network.play.client.C15PacketClientSettings; +import net.minecraft.network.play.client.C16PacketClientStatus; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.client.C18PacketSpectate; +import net.minecraft.network.play.client.C19PacketResourcePackStatus; + +public interface INetHandlerPlayServer extends INetHandler +{ + void handleAnimation(C0APacketAnimation packetIn); + + /** + * Process chat messages (broadcast back to clients) and commands (executes) + */ + void processChatMessage(C01PacketChatMessage packetIn); + + /** + * Retrieves possible tab completions for the requested command string and sends them to the client + */ + void processTabComplete(C14PacketTabComplete packetIn); + + /** + * Processes the client status updates: respawn attempt from player, opening statistics or achievements, or + * acquiring 'open inventory' achievement + */ + void processClientStatus(C16PacketClientStatus packetIn); + + /** + * Updates serverside copy of client settings: language, render distance, chat visibility, chat colours, difficulty, + * and whether to show the cape + */ + void processClientSettings(C15PacketClientSettings packetIn); + + /** + * Received in response to the server requesting to confirm that the client-side open container matches the servers' + * after a mismatched container-slot manipulation. It will unlock the player's ability to manipulate the container + * contents + */ + void processConfirmTransaction(C0FPacketConfirmTransaction packetIn); + + /** + * Enchants the item identified by the packet given some convoluted conditions (matching window, which + * should/shouldn't be in use?) + */ + void processEnchantItem(C11PacketEnchantItem packetIn); + + /** + * Executes a container/inventory slot manipulation as indicated by the packet. Sends the serverside result if they + * didn't match the indicated result and prevents further manipulation by the player until he confirms that it has + * the same open container/inventory + */ + void processClickWindow(C0EPacketClickWindow packetIn); + + /** + * Processes the client closing windows (container) + */ + void processCloseWindow(C0DPacketCloseWindow packetIn); + + /** + * Synchronizes serverside and clientside book contents and signing + */ + void processVanilla250Packet(C17PacketCustomPayload packetIn); + + /** + * Processes interactions ((un)leashing, opening command block GUI) and attacks on an entity with players currently + * equipped item + */ + void processUseEntity(C02PacketUseEntity packetIn); + + /** + * Updates a players' ping statistics + */ + void processKeepAlive(C00PacketKeepAlive packetIn); + + /** + * Processes clients perspective on player positioning and/or orientation + */ + void processPlayer(C03PacketPlayer packetIn); + + /** + * Processes a player starting/stopping flying + */ + void processPlayerAbilities(C13PacketPlayerAbilities packetIn); + + /** + * Processes the player initiating/stopping digging on a particular spot, as well as a player dropping items?. (0: + * initiated, 1: reinitiated, 2? , 3-4 drop item (respectively without or with player control), 5: stopped; x,y,z, + * side clicked on;) + */ + void processPlayerDigging(C07PacketPlayerDigging packetIn); + + /** + * Processes a range of action-types: sneaking, sprinting, waking from sleep, opening the inventory or setting jump + * height of the horse the player is riding + */ + void processEntityAction(C0BPacketEntityAction packetIn); + + /** + * Processes player movement input. Includes walking, strafing, jumping, sneaking; excludes riding and toggling + * flying/sprinting + */ + void processInput(C0CPacketInput packetIn); + + /** + * Updates which quickbar slot is selected + */ + void processHeldItemChange(C09PacketHeldItemChange packetIn); + + /** + * Update the server with an ItemStack in a slot. + */ + void processCreativeInventoryAction(C10PacketCreativeInventoryAction packetIn); + + void processUpdateSign(C12PacketUpdateSign packetIn); + + /** + * Processes block placement and block activation (anvil, furnace, etc.) + */ + void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn); + + void handleSpectate(C18PacketSpectate packetIn); + + void handleResourcePackStatus(C19PacketResourcePackStatus packetIn); +} diff --git a/proxy/src/main/java/proxy/network/MessageDeserializer.java b/proxy/src/main/java/proxy/network/MessageDeserializer.java new file mode 100755 index 0000000..b4910e8 --- /dev/null +++ b/proxy/src/main/java/proxy/network/MessageDeserializer.java @@ -0,0 +1,45 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import java.io.IOException; +import java.util.List; + +public class MessageDeserializer extends ByteToMessageDecoder +{ + private final EnumPacketDirection direction; + + public MessageDeserializer(EnumPacketDirection direction) + { + this.direction = direction; + } + + protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws IOException, InstantiationException, IllegalAccessException, Exception + { + if (p_decode_2_.readableBytes() != 0) + { + PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_); + int i = packetbuffer.readVarIntFromBuffer(); + Packet packet = ((EnumConnectionState)p_decode_1_.channel().attr(NetworkManager.STATE).get()).getPacket(this.direction, i); + + if (packet == null) + { + throw new IOException("Bad packet id " + i); + } + else + { + packet.readPacketData(packetbuffer); + + if (packetbuffer.readableBytes() > 0) + { + throw new IOException("Packet " + ((EnumConnectionState)p_decode_1_.channel().attr(NetworkManager.STATE).get()).getId() + "/" + i + " (" + packet.getClass().getSimpleName() + ") was larger than I expected, found " + packetbuffer.readableBytes() + " bytes extra whilst reading packet " + i); + } + else + { + p_decode_3_.add(packet); + } + } + } + } +} diff --git a/proxy/src/main/java/proxy/network/MessageDeserializer2.java b/proxy/src/main/java/proxy/network/MessageDeserializer2.java new file mode 100755 index 0000000..ec7fa0b --- /dev/null +++ b/proxy/src/main/java/proxy/network/MessageDeserializer2.java @@ -0,0 +1,54 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.CorruptedFrameException; +import java.util.List; + +public class MessageDeserializer2 extends ByteToMessageDecoder +{ + protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws Exception + { + p_decode_2_.markReaderIndex(); + byte[] abyte = new byte[3]; + + for (int i = 0; i < abyte.length; ++i) + { + if (!p_decode_2_.isReadable()) + { + p_decode_2_.resetReaderIndex(); + return; + } + + abyte[i] = p_decode_2_.readByte(); + + if (abyte[i] >= 0) + { + PacketBuffer packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(abyte)); + + try + { + int j = packetbuffer.readVarIntFromBuffer(); + + if (p_decode_2_.readableBytes() >= j) + { + p_decode_3_.add(p_decode_2_.readBytes(j)); + return; + } + + p_decode_2_.resetReaderIndex(); + } + finally + { + packetbuffer.release(); + } + + return; + } + } + + throw new CorruptedFrameException("length wider than 21-bit"); + } +} diff --git a/proxy/src/main/java/proxy/network/MessageSerializer.java b/proxy/src/main/java/proxy/network/MessageSerializer.java new file mode 100755 index 0000000..f5a09b5 --- /dev/null +++ b/proxy/src/main/java/proxy/network/MessageSerializer.java @@ -0,0 +1,42 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import proxy.util.Log; + +import java.io.IOException; + +public class MessageSerializer extends MessageToByteEncoder +{ + private final EnumPacketDirection direction; + + public MessageSerializer(EnumPacketDirection direction) + { + this.direction = direction; + } + + protected void encode(ChannelHandlerContext p_encode_1_, Packet p_encode_2_, ByteBuf p_encode_3_) throws IOException, Exception + { + Integer integer = ((EnumConnectionState)p_encode_1_.channel().attr(NetworkManager.STATE).get()).getPacketId(this.direction, p_encode_2_); + + if (integer == null) + { + throw new IOException("Can't serialize unregistered packet"); + } + else + { + PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_); + packetbuffer.writeVarIntToBuffer(integer.intValue()); + + try + { + p_encode_2_.writePacketData(packetbuffer); + } + catch (Throwable throwable) + { + Log.error(throwable, "Could not serialize packet"); + } + } + } +} diff --git a/proxy/src/main/java/proxy/network/MessageSerializer2.java b/proxy/src/main/java/proxy/network/MessageSerializer2.java new file mode 100755 index 0000000..4895b98 --- /dev/null +++ b/proxy/src/main/java/proxy/network/MessageSerializer2.java @@ -0,0 +1,26 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +public class MessageSerializer2 extends MessageToByteEncoder +{ + protected void encode(ChannelHandlerContext p_encode_1_, ByteBuf p_encode_2_, ByteBuf p_encode_3_) throws Exception + { + int i = p_encode_2_.readableBytes(); + int j = PacketBuffer.getVarIntSize(i); + + if (j > 3) + { + throw new IllegalArgumentException("unable to fit " + i + " into " + 3); + } + else + { + PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_); + packetbuffer.ensureWritable(j + i); + packetbuffer.writeVarIntToBuffer(i); + packetbuffer.writeBytes(p_encode_2_, p_encode_2_.readerIndex(), i); + } + } +} diff --git a/proxy/src/main/java/proxy/network/NetHandlerHandshake.java b/proxy/src/main/java/proxy/network/NetHandlerHandshake.java new file mode 100755 index 0000000..594a101 --- /dev/null +++ b/proxy/src/main/java/proxy/network/NetHandlerHandshake.java @@ -0,0 +1,51 @@ +package proxy.network; + +import net.minecraft.network.handshake.client.C00Handshake; +import net.minecraft.network.login.server.S00PacketDisconnect; +import proxy.Proxy; +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; + +public class NetHandlerHandshake implements INetHandler { + private final Proxy proxy; + private final NetworkManager connection; + + public NetHandlerHandshake(Proxy proxy, NetworkManager connection) { + this.proxy = proxy; + this.connection = connection; + } + + public void processHandshake(C00Handshake packet) { + switch(packet.getRequestedState()) { + case LOGIN: + this.connection.setConnectionState(EnumConnectionState.LOGIN); + + if(packet.getProtocolVersion() > 47) { + ChatComponentText text = new ChatComponentText("Outdated server! I\'m still on 1.8.9"); + this.connection.sendPacket(new S00PacketDisconnect(text)); + this.connection.closeChannel(text); + } + else if(packet.getProtocolVersion() < 47) { + ChatComponentText text = new ChatComponentText("Outdated client! Please use 1.8.9"); + this.connection.sendPacket(new S00PacketDisconnect(text)); + this.connection.closeChannel(text); + } + else { + this.connection.setNetHandler(new NetHandlerLoginServer(this.proxy, this.connection)); + } + + break; + + case STATUS: + this.connection.setConnectionState(EnumConnectionState.STATUS); + this.connection.setNetHandler(new NetHandlerStatusServer(this.proxy, this.connection)); + break; + + default: + throw new UnsupportedOperationException("Invalid intention " + packet.getRequestedState()); + } + } + + public void onDisconnect(NetworkManager connection, ChatComponent reason) { + } +} diff --git a/proxy/src/main/java/proxy/network/NetHandlerLoginServer.java b/proxy/src/main/java/proxy/network/NetHandlerLoginServer.java new file mode 100755 index 0000000..55a0c8e --- /dev/null +++ b/proxy/src/main/java/proxy/network/NetHandlerLoginServer.java @@ -0,0 +1,108 @@ +package proxy.network; + +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import net.minecraft.network.login.client.C00PacketLoginStart; +import net.minecraft.network.login.client.C01PacketEncryptionResponse; +import net.minecraft.network.login.server.S00PacketDisconnect; +import net.minecraft.network.login.server.S02PacketLoginSuccess; +import net.minecraft.network.login.server.S03PacketEnableCompression; +import proxy.Proxy; +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; +import proxy.util.ITickable; +import proxy.util.Log; + +public class NetHandlerLoginServer implements INetHandler, ITickable { + private static enum LoginState { + INIT, WAITING, DONE; + } + + private final Proxy proxy; + private final NetworkManager connection; + + private LoginState state = LoginState.INIT; + private int timer; + private String username; + + private static boolean isValidUser(String name) { + for(int z = 0; z < name.length(); z++) { + char ch = name.charAt(z); + if((ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && ch != '_') + return false; + } + return true; + } + + public NetHandlerLoginServer(Proxy proxy, NetworkManager connection) { + this.proxy = proxy; + this.connection = connection; + } + + public void update(NetworkManager connection) { + if(this.state == LoginState.WAITING) { + this.tryAcceptPlayer(); + } + + if(this.timer++ == 600) { + this.closeConnection("Took too long to log in"); + } + } + + public void closeConnection(String reason) { + try { + Log.info("Disconnecting " + this.getConnectionInfo() + ": " + reason); + ChatComponentText text = new ChatComponentText(reason); + this.connection.sendPacket(new S00PacketDisconnect(text)); + this.connection.closeChannel(text); + } + catch(Exception e) { + Log.error(e, "Error whilst disconnecting player"); + } + } + + public void tryAcceptPlayer() { + if(this.proxy.isLoggedIn(this.username)) { + this.closeConnection("That username is already taken"); + return; + } + this.state = LoginState.DONE; + + if(this.proxy.getCompression() >= 0) { + this.connection.sendPacket(new S03PacketEnableCompression(this.proxy.getCompression()), new ChannelFutureListener() { + public void operationComplete(ChannelFuture p_operationComplete_1_) throws Exception { + NetHandlerLoginServer.this.connection.setCompressionTreshold(NetHandlerLoginServer.this.proxy.getCompression()); + } + }); + } + + NetHandlerPlayServer handler = new NetHandlerPlayServer(this.proxy, this.connection, this.username); + this.connection.setNetHandler(handler); + this.connection.sendPacket(new S02PacketLoginSuccess(Proxy.getOfflineUUID(this.username), this.username)); + handler.setupPlayer(); + } + + public void onDisconnect(NetworkManager connection, ChatComponent reason) { + Log.info(this.getConnectionInfo() + " lost connection: " + reason); + } + + public String getConnectionInfo() { + return this.username != null ? this.username + " (" + this.connection.getRemoteAddress().toString() + ")" + : String.valueOf(this.connection.getRemoteAddress()); + } + + public void processLoginStart(C00PacketLoginStart packet) { + if(this.state != LoginState.INIT) + throw new IllegalStateException("Unexpected hello packet"); + this.username = packet.getProfile(); + if(this.username.length() < 3 || this.username.length() > 16 || !isValidUser(this.username)) { + this.closeConnection("Invalid username"); + return; + } + this.state = LoginState.WAITING; + } + + public void processEncryptionResponse(C01PacketEncryptionResponse packet) { + throw new IllegalStateException("Unexpected key packet"); + } +} diff --git a/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java b/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java new file mode 100755 index 0000000..839cfa8 --- /dev/null +++ b/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java @@ -0,0 +1,907 @@ +package proxy.network; + +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; + +import java.net.IDN; +import java.net.InetAddress; +import java.net.UnknownHostException; +import net.minecraft.network.handshake.client.C00Handshake; +import net.minecraft.network.login.client.C00PacketLoginStart; +import net.minecraft.network.login.server.S00PacketDisconnect; +import net.minecraft.network.login.server.S01PacketEncryptionRequest; +import net.minecraft.network.login.server.S02PacketLoginSuccess; +import net.minecraft.network.login.server.S03PacketEnableCompression; +import net.minecraft.network.play.client.C00PacketKeepAlive; +import net.minecraft.network.play.client.C01PacketChatMessage; +import net.minecraft.network.play.client.C02PacketUseEntity; +import net.minecraft.network.play.client.C03PacketPlayer; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; +import net.minecraft.network.play.client.C09PacketHeldItemChange; +import net.minecraft.network.play.client.C0APacketAnimation; +import net.minecraft.network.play.client.C0BPacketEntityAction; +import net.minecraft.network.play.client.C0CPacketInput; +import net.minecraft.network.play.client.C0DPacketCloseWindow; +import net.minecraft.network.play.client.C0EPacketClickWindow; +import net.minecraft.network.play.client.C0FPacketConfirmTransaction; +import net.minecraft.network.play.client.C10PacketCreativeInventoryAction; +import net.minecraft.network.play.client.C11PacketEnchantItem; +import net.minecraft.network.play.client.C12PacketUpdateSign; +import net.minecraft.network.play.client.C13PacketPlayerAbilities; +import net.minecraft.network.play.client.C14PacketTabComplete; +import net.minecraft.network.play.client.C15PacketClientSettings; +import net.minecraft.network.play.client.C16PacketClientStatus; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.client.C18PacketSpectate; +import net.minecraft.network.play.client.C19PacketResourcePackStatus; +import net.minecraft.network.play.server.S00PacketKeepAlive; +import net.minecraft.network.play.server.S01PacketJoinGame; +import net.minecraft.network.play.server.S02PacketChat; +import net.minecraft.network.play.server.S03PacketTimeUpdate; +import net.minecraft.network.play.server.S04PacketEntityEquipment; +import net.minecraft.network.play.server.S05PacketSpawnPosition; +import net.minecraft.network.play.server.S06PacketUpdateHealth; +import net.minecraft.network.play.server.S07PacketRespawn; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import net.minecraft.network.play.server.S09PacketHeldItemChange; +import net.minecraft.network.play.server.S0APacketUseBed; +import net.minecraft.network.play.server.S0BPacketAnimation; +import net.minecraft.network.play.server.S0CPacketSpawnPlayer; +import net.minecraft.network.play.server.S0DPacketCollectItem; +import net.minecraft.network.play.server.S0EPacketSpawnObject; +import net.minecraft.network.play.server.S0FPacketSpawnMob; +import net.minecraft.network.play.server.S10PacketSpawnPainting; +import net.minecraft.network.play.server.S11PacketSpawnExperienceOrb; +import net.minecraft.network.play.server.S12PacketEntityVelocity; +import net.minecraft.network.play.server.S13PacketDestroyEntities; +import net.minecraft.network.play.server.S14PacketEntity; +import net.minecraft.network.play.server.S18PacketEntityTeleport; +import net.minecraft.network.play.server.S19PacketEntityHeadLook; +import net.minecraft.network.play.server.S19PacketEntityStatus; +import net.minecraft.network.play.server.S1BPacketEntityAttach; +import net.minecraft.network.play.server.S1CPacketEntityMetadata; +import net.minecraft.network.play.server.S1DPacketEntityEffect; +import net.minecraft.network.play.server.S1EPacketRemoveEntityEffect; +import net.minecraft.network.play.server.S1FPacketSetExperience; +import net.minecraft.network.play.server.S20PacketEntityProperties; +import net.minecraft.network.play.server.S21PacketChunkData; +import net.minecraft.network.play.server.S22PacketMultiBlockChange; +import net.minecraft.network.play.server.S23PacketBlockChange; +import net.minecraft.network.play.server.S24PacketBlockAction; +import net.minecraft.network.play.server.S25PacketBlockBreakAnim; +import net.minecraft.network.play.server.S26PacketMapChunkBulk; +import net.minecraft.network.play.server.S27PacketExplosion; +import net.minecraft.network.play.server.S28PacketEffect; +import net.minecraft.network.play.server.S29PacketSoundEffect; +import net.minecraft.network.play.server.S2APacketParticles; +import net.minecraft.network.play.server.S2BPacketChangeGameState; +import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity; +import net.minecraft.network.play.server.S2DPacketOpenWindow; +import net.minecraft.network.play.server.S2EPacketCloseWindow; +import net.minecraft.network.play.server.S2FPacketSetSlot; +import net.minecraft.network.play.server.S30PacketWindowItems; +import net.minecraft.network.play.server.S31PacketWindowProperty; +import net.minecraft.network.play.server.S32PacketConfirmTransaction; +import net.minecraft.network.play.server.S33PacketUpdateSign; +import net.minecraft.network.play.server.S34PacketMaps; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.network.play.server.S36PacketSignEditorOpen; +import net.minecraft.network.play.server.S37PacketStatistics; +import net.minecraft.network.play.server.S38PacketPlayerListItem; +import net.minecraft.network.play.server.S39PacketPlayerAbilities; +import net.minecraft.network.play.server.S3APacketTabComplete; +import net.minecraft.network.play.server.S3BPacketScoreboardObjective; +import net.minecraft.network.play.server.S3CPacketUpdateScore; +import net.minecraft.network.play.server.S3DPacketDisplayScoreboard; +import net.minecraft.network.play.server.S3EPacketTeams; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.network.play.server.S40PacketDisconnect; +import net.minecraft.network.play.server.S41PacketServerDifficulty; +import net.minecraft.network.play.server.S42PacketCombatEvent; +import net.minecraft.network.play.server.S43PacketCamera; +import net.minecraft.network.play.server.S44PacketWorldBorder; +import net.minecraft.network.play.server.S45PacketTitle; +import net.minecraft.network.play.server.S46PacketSetCompressionLevel; +import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter; +import net.minecraft.network.play.server.S48PacketResourcePackSend; +import net.minecraft.network.play.server.S49PacketUpdateEntityNBT; +import proxy.Proxy; +import proxy.nbt.NBTTagList; +import proxy.util.ChatColor; +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; +import proxy.util.User; +import proxy.util.ITickable; +import proxy.util.ItemStack; +import proxy.util.Log; + +public class NetHandlerPlayServer implements INetHandlerPlayServer, INetHandlerPlayClient, ITickable { + public class ProxyLoginHandler implements INetHandler { + public void handleEncryptionRequest(S01PacketEncryptionRequest packetIn) { + NetHandlerPlayServer.this.server.closeChannel(new ChatComponentText("Online mode auth request received")); + NetHandlerPlayServer.this.kickPlayerFromServer("Server tried to authenticate, check if online-mode ist set to false"); + } + + public void handleLoginSuccess(S02PacketLoginSuccess packetIn) { + if(!NetHandlerPlayServer.this.username.equals(packetIn.getName()) || !Proxy.getOfflineUUID(NetHandlerPlayServer.this.username).equals(packetIn.getId())) { + NetHandlerPlayServer.this.server.closeChannel(new ChatComponentText("Different profile received")); + NetHandlerPlayServer.this.kickPlayerFromServer("Server returned a different profile, check if server or plugins tamper with profiles"); + } + NetHandlerPlayServer.this.server.setNetHandler(NetHandlerPlayServer.this); + NetHandlerPlayServer.this.server.setConnectionState(EnumConnectionState.PLAY); + NetHandlerPlayServer.this.connected = true; + NetHandlerPlayServer.this.connecting = false; + Log.info("Connected %s to forward host", NetHandlerPlayServer.this.username); + } + + public void handleDisconnect(S00PacketDisconnect packetIn) { + NetHandlerPlayServer.this.server.closeChannel(packetIn.func_149603_c()); + NetHandlerPlayServer.this.kickPlayerFromServer(packetIn.func_149603_c()); + } + + public void handleEnableCompression(S03PacketEnableCompression packetIn) { + NetHandlerPlayServer.this.server.setCompressionTreshold(packetIn.getCompressionTreshold()); + } + + public void onDisconnect(NetworkManager connection, ChatComponent reason) { + NetHandlerPlayServer.this.onDisconnect(connection, reason); + } + } + + private final Proxy proxy; + private final NetworkManager client; + private final String username; + + private NetworkManager server; + + private int networkTickCount; + private long lastPingTime; + private long lastSentPingPacket; + private volatile boolean connecting; + private volatile boolean connected; + private volatile boolean joined; + private int passwordAttempts; + private boolean wasClosed; + private volatile int signPreloaded; + + private static boolean isAllowedChar(char ch) { + return ch != 167 && ch >= 32 && ch != 127; + } + + private static String filterString(String str) { + StringBuilder sb = new StringBuilder(); + for(char ch : str.toCharArray()) { + if(isAllowedChar(ch)) { + sb.append(ch); + } + } + return sb.toString(); + } + + private static boolean isValidString(String str) { + for(int z = 0; z < str.length(); z++) { + if(!isAllowedChar(str.charAt(z))) { + return false; + } + } + return true; + } + + public NetHandlerPlayServer(Proxy proxy, NetworkManager client, String username) { + this.proxy = proxy; + this.client = client; + this.username = username; + } + + public void setupPlayer() { + this.sendToClient(new S01PacketJoinGame(0, true)); + this.sendToClient(new S03PacketTimeUpdate(3000L, false)); + this.sendToClient(new S26PacketMapChunkBulk(0, 64, 0)); + this.sendToClient(new S08PacketPlayerPosLook(0.5, 65.0, 0.5, 0.0f, 0.0f)); + this.sendMessage(ChatColor.DARK_PURPLE + "Welcome %s, please log in using the sign gui ...", this.username); + } + + public void sendMessage(String message) { + this.sendToClient(new S02PacketChat(message)); + } + + public void sendMessage(String fmt, Object ... args) { + this.sendToClient(new S02PacketChat(String.format(fmt, args))); + } + + public void update(NetworkManager connection) { + if(connection == this.server) + return; + if(!this.connected) { + ++this.networkTickCount; + if((long)this.networkTickCount - this.lastSentPingPacket > 40L) { + this.lastSentPingPacket = (long)this.networkTickCount; + this.lastPingTime = System.nanoTime() / 1000000L; + this.sendToClient(new S00PacketKeepAlive((int)this.lastPingTime)); + } + } + if(this.connecting || this.connected) { + if(this.server.isChannelOpen()) { + try { + this.server.processReceivedPackets(); + } + catch(Throwable e) { + this.kickPlayerFromServer("Forward server error"); + Log.error(e, "Error in connection for %s", this.username); + } + } + else { + this.server.checkDisconnected(); + } + } + } + + public void sendToClient(Packet packetIn) { + this.client.sendPacket(packetIn); + } + + public void sendToServer(Packet packetIn) { + this.server.sendPacket(packetIn); + } + + public void kickPlayerFromServer(String reason) { + this.kickPlayerFromServer(new ChatComponentText(reason)); + } + + public void kickPlayerFromServer(final ChatComponent comp) { + this.client.sendPacket(new S40PacketDisconnect(comp), new GenericFutureListener>() { + public void operationComplete(Future p_operationComplete_1_) throws Exception { + NetHandlerPlayServer.this.client.closeChannel(comp); + } + }); + this.client.disableAutoRead(); + this.proxy.schedule(new Runnable() { + public void run() { + NetHandlerPlayServer.this.client.checkDisconnected(); + } + }); + } + + private void connectToServer() { + this.proxy.setLoggedIn(this.username, this); + Log.info("Connecting %s to %s:%d", this.username, this.proxy.getForwardHost(), this.proxy.getForwardPort()); + final NetworkManager conn; + try { + conn = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(IDN.toASCII(this.proxy.getForwardHost())), this.proxy.getForwardPort(), this.proxy.isUsingEPoll()); + } + catch(UnknownHostException e) { + this.kickPlayerFromServer("Could not connect to server: unknown host, check if the hostname is correct"); + Log.error(e, "Could not connect to server"); + return; + } + catch(Exception e) { + this.kickPlayerFromServer("Could not connect to server: connection failed, check if the server is running and reachable on this port"); + Log.error(e, "Could not connect to server"); + return; + } + conn.setNetHandler(new ProxyLoginHandler()); + conn.sendPacket(new C00Handshake(47, this.proxy.getForwardHost(), this.proxy.getForwardPort(), EnumConnectionState.LOGIN), new GenericFutureListener>() { + public void operationComplete(Future future) throws Exception { + conn.sendPacket(new C00PacketLoginStart(NetHandlerPlayServer.this.username)); + } + }); + this.server = conn; + this.connecting = true; + Log.info("Connected %s to login phase", this.username); + } + + public void processInput(C0CPacketInput packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processPlayer(C03PacketPlayer packetIn) { + if(this.connected) { + this.sendToServer(packetIn); + } + else { + this.sendToClient(new S08PacketPlayerPosLook(0.5, 65.0, 0.5, 0.0f, 0.0f)); + if(this.signPreloaded == 1) { + this.signPreloaded = 2; + this.setSign(ChatColor.DARK_BLUE + "" + ChatColor.UNDERLINE + "Enter password", ChatColor.DARK_GRAY + "Use 1 or 2 lines"); + } + else if(this.signPreloaded == 0) { + this.signPreloaded = 1; + } + } + } + + public void onDisconnect(NetworkManager connection, ChatComponent reason) { + if(connection == this.server) { + this.kickPlayerFromServer(reason); + Log.info("Server disconnected, kicking player %s", this.username); + } + if(connection == this.client) { + if(this.connected) + this.server.closeChannel(reason); + Log.info("Client %s disconnected", this.username); + } + this.proxy.setLoggedOut(this.username); + Log.info("%s lost connection: " + reason, this.username); + } + + private void setSign(String message, String desc) { + this.sendToClient(new S33PacketUpdateSign(0, 66, 1, "", "", message, desc)); + this.sendToClient(new S36PacketSignEditorOpen(0, 66, 1)); + } + + private void handlePassword(String password) { + if(password.isEmpty()) { + if(this.wasClosed) { + this.kickPlayerFromServer("Login aborted"); + } + else { + this.wasClosed = true; + this.setSign(ChatColor.GOLD + "Press esc again", ChatColor.GOLD + "to disconnect ..."); + } + return; + } + this.wasClosed = false; + User stored = this.proxy.getUser(this.username); + if(stored == null) { + if(!this.proxy.canRegister()) { + this.kickPlayerFromServer("You are not whitelisted on this server"); + } + else if(password.isEmpty() || password.length() < this.proxy.getMinimumPasswordLength()) { + this.setSign(ChatColor.DARK_RED + "" + ChatColor.UNDERLINE + "Too short" + ChatColor.DARK_RED + ", use", ChatColor.DARK_RED + "" + this.proxy.getMinimumPasswordLength() + "-32 characters"); + } + else if(password.length() > 32) { + this.setSign(ChatColor.DARK_RED + "" + ChatColor.UNDERLINE + "Too long" + ChatColor.DARK_RED + ", use", ChatColor.DARK_RED + "" + this.proxy.getMinimumPasswordLength() + "-32 characters"); + } + else { + this.proxy.setUser(this.username, User.createUser(this.username, password)); + Log.info("%s registered with password", this.username); + this.connectToServer(); + } + } + else { + if(!stored.checkPassword(password)) { + if(++this.passwordAttempts >= this.proxy.getMaximumPasswordAttempts()) + this.kickPlayerFromServer("Too many password attempts"); + else + this.setSign(ChatColor.DARK_RED + "" + ChatColor.UNDERLINE + "Wrong password", ChatColor.DARK_RED + "Please try again"); + Log.info("%s failed password attempt %d/%d", this.username, this.passwordAttempts, this.proxy.getMaximumPasswordAttempts()); + } + else if(this.proxy.isCheckingCase() && !stored.getName().equals(this.username)) { + this.kickPlayerFromServer("You used the wrong username casing, please use '" + stored.getName() + "' exactly"); + Log.info("%s tried to use a different username casing", this.username); + } + else { + Log.info("%s logged in with password", this.username); + this.connectToServer(); + } + } + } + + public void processUpdateSign(C12PacketUpdateSign packetIn) { + if(!this.connected) { + PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.proxy); + if(!(packetIn.getLines()[0] instanceof ChatComponentText && packetIn.getLines()[1] instanceof ChatComponentText)) + return; + String line1 = ((ChatComponentText)packetIn.getLines()[0]).getText(); + String line2 = ((ChatComponentText)packetIn.getLines()[1]).getText(); + if(line1.length() > 50 || line2.length() > 50 || !isValidString(line1) || !isValidString(line2)) + return; + String password = line1 + line2; + this.handlePassword(password); + return; + } + ChatComponent[] lines = packetIn.getLines(); + for(ChatComponent line : lines) { + if(line != null && (!(line instanceof ChatComponentText) || ((ChatComponentText)line).getText().length() > 50 + || !isValidString(((ChatComponentText)line).getText()))) + return; + } + this.sendToServer(packetIn); + } + + public void processChatMessage(C01PacketChatMessage packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processTabComplete(C14PacketTabComplete packetIn) { +// PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.proxy); + if(this.connected) // { +// this.completion = packetIn.getMessage(); + this.sendToServer(packetIn); +// } +// else { +// List list = Lists.newArrayList(); +// // TODO: completions +// this.sendToClient(new S3APacketTabComplete(list.toArray(new String[list.size()]))); +// } + } + + public void processPlayerDigging(C07PacketPlayerDigging packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void handleSpectate(C18PacketSpectate packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void handleResourcePackStatus(C19PacketResourcePackStatus packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processHeldItemChange(C09PacketHeldItemChange packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processKeepAlive(C00PacketKeepAlive packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void handleAnimation(C0APacketAnimation packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processEntityAction(C0BPacketEntityAction packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processUseEntity(C02PacketUseEntity packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processClientStatus(C16PacketClientStatus packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processCloseWindow(C0DPacketCloseWindow packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processClickWindow(C0EPacketClickWindow packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processEnchantItem(C11PacketEnchantItem packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processConfirmTransaction(C0FPacketConfirmTransaction packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processPlayerAbilities(C13PacketPlayerAbilities packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processClientSettings(C15PacketClientSettings packetIn) { + if(this.connected) + this.sendToServer(packetIn); + } + + public void processCreativeInventoryAction(C10PacketCreativeInventoryAction packetIn) { + if(!this.connected) + return; + ItemStack stack = packetIn.getStack(); + // TODO: validate item + this.sendToServer(packetIn); + } + + public void processVanilla250Packet(C17PacketCustomPayload packetIn) { + if(!this.connected) { + if("MC|Brand".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + String brand = packetbuffer.readStringFromBuffer(32767); + Log.info("Client brand of %s: %s", this.username, + filterString(ChatColor.strip(brand.length() > 128 ? brand.substring(0, 128) + " ..." : brand))); + packetbuffer.release(); + } + return; + } + + if("MC|BEdit".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + try { + ItemStack itemstack1 = packetbuffer.readItemStackFromBuffer(); + + if(itemstack1 != null) { + NBTTagList pages = itemstack1.getTag().getTagList("pages", 8); + return; + } + } + catch(Exception exception3) { + return; + } + finally { + packetbuffer.release(); + } + + return; + } + else if("MC|BSign".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + try { + ItemStack itemstack = packetbuffer.readItemStackFromBuffer(); + + if(itemstack != null) { + String title = itemstack.getTag().getString("title"); + NBTTagList pages = itemstack.getTag().getTagList("pages", 8); + return; + } + } + catch(Exception exception4) { + return; + } + finally { + packetbuffer.release(); + } + + return; + } + else if("MC|TrSel".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + int i = packetbuffer.readInt(); + packetbuffer.release(); + } + else if("MC|AdvCdm".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + int j = packetbuffer.readByte(); + + if(j == 0) { + packetbuffer.readInt(); + packetbuffer.readInt(); + packetbuffer.readInt(); + } + else if(j == 1) { + packetbuffer.readInt(); + } + + String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes()); + boolean flag = packetbuffer.readBoolean(); + packetbuffer.release(); + } + else if("MC|Beacon".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + int id = packetbuffer.readInt(); + if(id != 1 /* moveSpeed */ && id != 3 /* digSpeed */ && id != 11 /* resistance */ && id != 8 /* jump */ && id != 5 /* damageBoost */) { + packetbuffer.release(); + return; + } + id = packetbuffer.readInt(); + if(id != 1 /* moveSpeed */ && id != 3 /* digSpeed */ && id != 11 /* resistance */ && id != 8 /* jump */ && id != 5 /* damageBoost */ + && id != 10 /* regeneration */) { + packetbuffer.release(); + return; + } + packetbuffer.release(); + } + else if("MC|ItemName".equals(packetIn.getChannelName())) { + PacketBuffer packetbuffer = packetIn.getBufferData(); + if(packetbuffer.readableBytes() >= 1 && filterString(packetbuffer.readStringFromBuffer(32767)).length() > 30) { + packetbuffer.release(); + return; + } + packetbuffer.release(); + } + else { + return; + } + + this.sendToServer(packetIn); + } + + public void handleDisconnect(S40PacketDisconnect packetIn) { + this.server.closeChannel(packetIn.getReason()); + this.kickPlayerFromServer(packetIn.getReason()); + } + + public void handleJoinGame(S01PacketJoinGame packetIn) { + this.sendToClient(packetIn); + if(!this.joined) { + this.joined = true; + this.sendToClient(new S07PacketRespawn(packetIn)); + this.sendToClient(new S2EPacketCloseWindow()); + } + } + + public void handleSetCompressionLevel(S46PacketSetCompressionLevel packetIn) { + this.server.setCompressionTreshold(packetIn.getThreshold()); + } + + public void handleTabComplete(S3APacketTabComplete packetIn) { +// PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.proxy); +// String[] comps = packetIn.func_149630_c(); +// if(this.completion != null) { +// // TODO: completion +// } + this.sendToClient(packetIn); + } + + public void handleKeepAlive(S00PacketKeepAlive packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnObject(S0EPacketSpawnObject packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnExperienceOrb(S11PacketSpawnExperienceOrb packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnGlobalEntity(S2CPacketSpawnGlobalEntity packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnPainting(S10PacketSpawnPainting packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityVelocity(S12PacketEntityVelocity packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityMetadata(S1CPacketEntityMetadata packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnPlayer(S0CPacketSpawnPlayer packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityTeleport(S18PacketEntityTeleport packetIn) { + this.sendToClient(packetIn); + } + + public void handleHeldItemChange(S09PacketHeldItemChange packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityMovement(S14PacketEntity packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityHeadLook(S19PacketEntityHeadLook packetIn) { + this.sendToClient(packetIn); + } + + public void handleDestroyEntities(S13PacketDestroyEntities packetIn) { + this.sendToClient(packetIn); + } + + public void handlePlayerPosLook(S08PacketPlayerPosLook packetIn) { + this.sendToClient(packetIn); + } + + public void handleMultiBlockChange(S22PacketMultiBlockChange packetIn) { + this.sendToClient(packetIn); + } + + public void handleChunkData(S21PacketChunkData packetIn) { + this.sendToClient(packetIn); + } + + public void handleBlockChange(S23PacketBlockChange packetIn) { + this.sendToClient(packetIn); + } + + public void handleCollectItem(S0DPacketCollectItem packetIn) { + this.sendToClient(packetIn); + } + + public void handleChat(S02PacketChat packetIn) { + this.sendToClient(packetIn); + } + + public void handleAnimation(S0BPacketAnimation packetIn) { + this.sendToClient(packetIn); + } + + public void handleUseBed(S0APacketUseBed packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnMob(S0FPacketSpawnMob packetIn) { + this.sendToClient(packetIn); + } + + public void handleTimeUpdate(S03PacketTimeUpdate packetIn) { + this.sendToClient(packetIn); + } + + public void handleSpawnPosition(S05PacketSpawnPosition packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityAttach(S1BPacketEntityAttach packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityStatus(S19PacketEntityStatus packetIn) { + this.sendToClient(packetIn); + } + + public void handleUpdateHealth(S06PacketUpdateHealth packetIn) { + this.sendToClient(packetIn); + } + + public void handleSetExperience(S1FPacketSetExperience packetIn) { + this.sendToClient(packetIn); + } + + public void handleRespawn(S07PacketRespawn packetIn) { + this.sendToClient(packetIn); + } + + public void handleExplosion(S27PacketExplosion packetIn) { + this.sendToClient(packetIn); + } + + public void handleOpenWindow(S2DPacketOpenWindow packetIn) { + this.sendToClient(packetIn); + } + + public void handleSetSlot(S2FPacketSetSlot packetIn) { + this.sendToClient(packetIn); + } + + public void handleConfirmTransaction(S32PacketConfirmTransaction packetIn) { + this.sendToClient(packetIn); + } + + public void handleWindowItems(S30PacketWindowItems packetIn) { + this.sendToClient(packetIn); + } + + public void handleSignEditorOpen(S36PacketSignEditorOpen packetIn) { + this.sendToClient(packetIn); + } + + public void handleUpdateSign(S33PacketUpdateSign packetIn) { + this.sendToClient(packetIn); + } + + public void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn) { + this.sendToClient(packetIn); + } + + public void handleWindowProperty(S31PacketWindowProperty packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityEquipment(S04PacketEntityEquipment packetIn) { + this.sendToClient(packetIn); + } + + public void handleCloseWindow(S2EPacketCloseWindow packetIn) { + this.sendToClient(packetIn); + } + + public void handleBlockAction(S24PacketBlockAction packetIn) { + this.sendToClient(packetIn); + } + + public void handleBlockBreakAnim(S25PacketBlockBreakAnim packetIn) { + this.sendToClient(packetIn); + } + + public void handleMapChunkBulk(S26PacketMapChunkBulk packetIn) { + this.sendToClient(packetIn); + } + + public void handleChangeGameState(S2BPacketChangeGameState packetIn) { + this.sendToClient(packetIn); + } + + public void handleMaps(S34PacketMaps packetIn) { + this.sendToClient(packetIn); + } + + public void handleEffect(S28PacketEffect packetIn) { + this.sendToClient(packetIn); + } + + public void handleStatistics(S37PacketStatistics packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityEffect(S1DPacketEntityEffect packetIn) { + this.sendToClient(packetIn); + } + + public void handleCombatEvent(S42PacketCombatEvent packetIn) { + this.sendToClient(packetIn); + } + + public void handleServerDifficulty(S41PacketServerDifficulty packetIn) { + this.sendToClient(packetIn); + } + + public void handleCamera(S43PacketCamera packetIn) { + this.sendToClient(packetIn); + } + + public void handleWorldBorder(S44PacketWorldBorder packetIn) { + this.sendToClient(packetIn); + } + + public void handleTitle(S45PacketTitle packetIn) { + this.sendToClient(packetIn); + } + + public void handlePlayerListHeaderFooter(S47PacketPlayerListHeaderFooter packetIn) { + this.sendToClient(packetIn); + } + + public void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn) { + this.sendToClient(packetIn); + } + + public void handlePlayerListItem(S38PacketPlayerListItem packetIn) { + this.sendToClient(packetIn); + } + + public void handlePlayerAbilities(S39PacketPlayerAbilities packetIn) { + this.sendToClient(packetIn); + } + + public void handleSoundEffect(S29PacketSoundEffect packetIn) { + this.sendToClient(packetIn); + } + + public void handleResourcePack(S48PacketResourcePackSend packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityNBT(S49PacketUpdateEntityNBT packetIn) { + this.sendToClient(packetIn); + } + + public void handleCustomPayload(S3FPacketCustomPayload packetIn) { + this.sendToClient(packetIn); + } + + public void handleScoreboardObjective(S3BPacketScoreboardObjective packetIn) { + this.sendToClient(packetIn); + } + + public void handleUpdateScore(S3CPacketUpdateScore packetIn) { + this.sendToClient(packetIn); + } + + public void handleDisplayScoreboard(S3DPacketDisplayScoreboard packetIn) { + this.sendToClient(packetIn); + } + + public void handleTeams(S3EPacketTeams packetIn) { + this.sendToClient(packetIn); + } + + public void handleParticles(S2APacketParticles packetIn) { + this.sendToClient(packetIn); + } + + public void handleEntityProperties(S20PacketEntityProperties packetIn) { + this.sendToClient(packetIn); + } +} diff --git a/proxy/src/main/java/proxy/network/NetHandlerStatusClient.java b/proxy/src/main/java/proxy/network/NetHandlerStatusClient.java new file mode 100755 index 0000000..91ec4c4 --- /dev/null +++ b/proxy/src/main/java/proxy/network/NetHandlerStatusClient.java @@ -0,0 +1,19 @@ +package proxy.network; + +import net.minecraft.network.status.server.S00PacketServerInfo; +import net.minecraft.network.status.server.S01PacketPong; +import proxy.util.ChatComponent; + +public class NetHandlerStatusClient implements INetHandler { + public void handleServerInfo(S00PacketServerInfo packetIn) { + + } + + public void handlePong(S01PacketPong packetIn) { + + } + + public void onDisconnect(NetworkManager connection, ChatComponent reason) { + + } +} diff --git a/proxy/src/main/java/proxy/network/NetHandlerStatusServer.java b/proxy/src/main/java/proxy/network/NetHandlerStatusServer.java new file mode 100755 index 0000000..0c8230c --- /dev/null +++ b/proxy/src/main/java/proxy/network/NetHandlerStatusServer.java @@ -0,0 +1,41 @@ +package proxy.network; + +import net.minecraft.network.status.client.C00PacketServerQuery; +import net.minecraft.network.status.client.C01PacketPing; +import net.minecraft.network.status.server.S00PacketServerInfo; +import net.minecraft.network.status.server.S01PacketPong; +import proxy.Proxy; +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; + +public class NetHandlerStatusServer implements INetHandler { + private static final ChatComponent EXIT_MESSAGE = new ChatComponentText("Status request has been handled."); + + private final Proxy proxy; + private final NetworkManager networkManager; + + private boolean handled; + + public NetHandlerStatusServer(Proxy proxy, NetworkManager netManager) { + this.proxy = proxy; + this.networkManager = netManager; + } + + public void onDisconnect(NetworkManager connection, ChatComponent reason) { + } + + public void processServerQuery(C00PacketServerQuery packetIn) { + if(this.handled) { + this.networkManager.closeChannel(EXIT_MESSAGE); + } + else { + this.handled = true; + this.networkManager.sendPacket(new S00PacketServerInfo(this.proxy.getStatus())); + } + } + + public void processPing(C01PacketPing packetIn) { + this.networkManager.sendPacket(new S01PacketPong(packetIn.getClientTime())); + this.networkManager.closeChannel(EXIT_MESSAGE); + } +} diff --git a/proxy/src/main/java/proxy/network/NettyCompressionDecoder.java b/proxy/src/main/java/proxy/network/NettyCompressionDecoder.java new file mode 100755 index 0000000..51de107 --- /dev/null +++ b/proxy/src/main/java/proxy/network/NettyCompressionDecoder.java @@ -0,0 +1,61 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.DecoderException; +import java.util.List; +import java.util.zip.DataFormatException; +import java.util.zip.Inflater; + +public class NettyCompressionDecoder extends ByteToMessageDecoder +{ + private final Inflater inflater; + private int treshold; + + public NettyCompressionDecoder(int treshold) + { + this.treshold = treshold; + this.inflater = new Inflater(); + } + + protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws DataFormatException, Exception + { + if (p_decode_2_.readableBytes() != 0) + { + PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_); + int i = packetbuffer.readVarIntFromBuffer(); + + if (i == 0) + { + p_decode_3_.add(packetbuffer.readBytes(packetbuffer.readableBytes())); + } + else + { + if (i < this.treshold) + { + throw new DecoderException("Badly compressed packet - size of " + i + " is below server threshold of " + this.treshold); + } + + if (i > 2097152) + { + throw new DecoderException("Badly compressed packet - size of " + i + " is larger than protocol maximum of " + 2097152); + } + + byte[] abyte = new byte[packetbuffer.readableBytes()]; + packetbuffer.readBytes(abyte); + this.inflater.setInput(abyte); + byte[] abyte1 = new byte[i]; + this.inflater.inflate(abyte1); + p_decode_3_.add(Unpooled.wrappedBuffer(abyte1)); + this.inflater.reset(); + } + } + } + + public void setCompressionTreshold(int treshold) + { + this.treshold = treshold; + } +} diff --git a/proxy/src/main/java/proxy/network/NettyCompressionEncoder.java b/proxy/src/main/java/proxy/network/NettyCompressionEncoder.java new file mode 100755 index 0000000..57c146c --- /dev/null +++ b/proxy/src/main/java/proxy/network/NettyCompressionEncoder.java @@ -0,0 +1,52 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import java.util.zip.Deflater; + +public class NettyCompressionEncoder extends MessageToByteEncoder +{ + private final byte[] buffer = new byte[8192]; + private final Deflater deflater; + private int treshold; + + public NettyCompressionEncoder(int treshold) + { + this.treshold = treshold; + this.deflater = new Deflater(); + } + + protected void encode(ChannelHandlerContext p_encode_1_, ByteBuf p_encode_2_, ByteBuf p_encode_3_) throws Exception + { + int i = p_encode_2_.readableBytes(); + PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_); + + if (i < this.treshold) + { + packetbuffer.writeVarIntToBuffer(0); + packetbuffer.writeBytes(p_encode_2_); + } + else + { + byte[] abyte = new byte[i]; + p_encode_2_.readBytes(abyte); + packetbuffer.writeVarIntToBuffer(abyte.length); + this.deflater.setInput(abyte, 0, i); + this.deflater.finish(); + + while (!this.deflater.finished()) + { + int j = this.deflater.deflate(this.buffer); + packetbuffer.writeBytes((byte[])this.buffer, 0, j); + } + + this.deflater.reset(); + } + } + + public void setCompressionTreshold(int treshold) + { + this.treshold = treshold; + } +} diff --git a/proxy/src/main/java/proxy/network/NetworkManager.java b/proxy/src/main/java/proxy/network/NetworkManager.java new file mode 100755 index 0000000..332f820 --- /dev/null +++ b/proxy/src/main/java/proxy/network/NetworkManager.java @@ -0,0 +1,457 @@ +package proxy.network; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelException; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.epoll.Epoll; +import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.epoll.EpollSocketChannel; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.TimeoutException; +import io.netty.util.AttributeKey; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import java.net.InetAddress; +import java.net.SocketAddress; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +import proxy.util.ChatComponent; +import proxy.util.ChatComponentText; +import proxy.util.ITickable; +import proxy.util.LazyLoadBase; +import proxy.util.Log; + +public class NetworkManager extends SimpleChannelInboundHandler +{ + public static final AttributeKey STATE = AttributeKey.valueOf("protocol"); + public static final LazyLoadBase CLIENT_NIO_EVENTLOOP = new LazyLoadBase() + { + protected NioEventLoopGroup load() + { + return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build()); + } + }; + public static final LazyLoadBase CLIENT_EPOLL_EVENTLOOP = new LazyLoadBase() + { + protected EpollEventLoopGroup load() + { + return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Client IO #%d").setDaemon(true).build()); + } + }; + private final EnumPacketDirection direction; + private final Queue outboundPacketsQueue = new ConcurrentLinkedQueue(); + private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); + + /** The active channel */ + private Channel channel; + + /** The address of the remote party */ + private SocketAddress socketAddress; + + /** The INetHandler instance responsible for processing received packets */ + private INetHandler packetListener; + + /** A String indicating why the network has shutdown. */ + private ChatComponent terminationReason; + private boolean disconnected; + + public NetworkManager(EnumPacketDirection packetDirection) + { + this.direction = packetDirection; + } + + public void channelActive(ChannelHandlerContext p_channelActive_1_) throws Exception + { + super.channelActive(p_channelActive_1_); + this.channel = p_channelActive_1_.channel(); + this.socketAddress = this.channel.remoteAddress(); + + try + { + this.setConnectionState(EnumConnectionState.HANDSHAKING); + } + catch (Throwable throwable) + { + Log.error(throwable, "Could not set handshake state"); + } + } + + /** + * Sets the new connection state and registers which packets this channel may send and receive + */ + public void setConnectionState(EnumConnectionState newState) + { + this.channel.attr(STATE).set(newState); + this.channel.config().setAutoRead(true); + Log.debug("Enabled auto read"); + } + + public void channelInactive(ChannelHandlerContext p_channelInactive_1_) throws Exception + { + this.closeChannel(new ChatComponentText("End of stream")); + } + + public void exceptionCaught(ChannelHandlerContext p_exceptionCaught_1_, Throwable p_exceptionCaught_2_) throws Exception + { + ChatComponentText chatcomponenttranslation; + + if (p_exceptionCaught_2_ instanceof TimeoutException) + { + chatcomponenttranslation = new ChatComponentText("Network timeout"); + } + else + { + chatcomponenttranslation = new ChatComponentText("Internal Exception: " + p_exceptionCaught_2_); + } + + this.closeChannel(chatcomponenttranslation); + } + + protected void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_) throws Exception + { + if (this.channel.isOpen()) + { + try + { + p_channelRead0_2_.processPacket(this.packetListener); + } + catch (ThreadQuickExitException var4) + { + ; + } + } + } + + /** + * Sets the NetHandler for this NetworkManager, no checks are made if this handler is suitable for the particular + * connection state (protocol) + */ + public void setNetHandler(INetHandler handler) + { + if(handler == null) + throw new IllegalArgumentException("handler may not be null"); + Log.debug("Set listener of %s to %s", this, handler); + this.packetListener = handler; + } + + public void sendPacket(Packet packetIn) + { + if (this.isChannelOpen()) + { + this.flushOutboundQueue(); + this.dispatchPacket(packetIn, (GenericFutureListener > [])null); + } + else + { + this.readWriteLock.writeLock().lock(); + + try + { + this.outboundPacketsQueue.add(new NetworkManager.InboundHandlerTuplePacketListener(packetIn, (GenericFutureListener[])null)); + } + finally + { + this.readWriteLock.writeLock().unlock(); + } + } + } + + public void sendPacket(Packet packetIn, GenericFutureListener > listener) + { + if (this.isChannelOpen()) + { + this.flushOutboundQueue(); + this.dispatchPacket(packetIn, new GenericFutureListener[] {listener}); + } + else + { + this.readWriteLock.writeLock().lock(); + + try + { + this.outboundPacketsQueue.add(new NetworkManager.InboundHandlerTuplePacketListener(packetIn, new GenericFutureListener[] {listener})); + } + finally + { + this.readWriteLock.writeLock().unlock(); + } + } + } + + /** + * Will commit the packet to the channel. If the current thread 'owns' the channel it will write and flush the + * packet, otherwise it will add a task for the channel eventloop thread to do that. + */ + private void dispatchPacket(final Packet inPacket, final GenericFutureListener > [] futureListeners) + { + final EnumConnectionState enumconnectionstate = EnumConnectionState.getFromPacket(inPacket); + final EnumConnectionState enumconnectionstate1 = (EnumConnectionState)this.channel.attr(STATE).get(); + + if (enumconnectionstate1 != enumconnectionstate) + { + Log.debug("Disabled auto read"); + this.channel.config().setAutoRead(false); + } + + if (this.channel.eventLoop().inEventLoop()) + { + if (enumconnectionstate != enumconnectionstate1) + { + this.setConnectionState(enumconnectionstate); + } + + ChannelFuture channelfuture = this.channel.writeAndFlush(inPacket); + + if (futureListeners != null) + { + channelfuture.addListeners(futureListeners); + } + + channelfuture.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + } + else + { + this.channel.eventLoop().execute(new Runnable() + { + public void run() + { + if (enumconnectionstate != enumconnectionstate1) + { + NetworkManager.this.setConnectionState(enumconnectionstate); + } + + ChannelFuture channelfuture1 = NetworkManager.this.channel.writeAndFlush(inPacket); + + if (futureListeners != null) + { + channelfuture1.addListeners(futureListeners); + } + + channelfuture1.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + } + }); + } + } + + /** + * Will iterate through the outboundPacketQueue and dispatch all Packets + */ + private void flushOutboundQueue() + { + if (this.channel != null && this.channel.isOpen()) + { + this.readWriteLock.readLock().lock(); + + try + { + while (!this.outboundPacketsQueue.isEmpty()) + { + NetworkManager.InboundHandlerTuplePacketListener networkmanager$inboundhandlertuplepacketlistener = (NetworkManager.InboundHandlerTuplePacketListener)this.outboundPacketsQueue.poll(); + this.dispatchPacket(networkmanager$inboundhandlertuplepacketlistener.packet, networkmanager$inboundhandlertuplepacketlistener.futureListeners); + } + } + finally + { + this.readWriteLock.readLock().unlock(); + } + } + } + + /** + * Checks timeouts and processes all packets received + */ + public void processReceivedPackets() + { + this.flushOutboundQueue(); + + if (this.packetListener instanceof ITickable) + { + ((ITickable)this.packetListener).update(this); + } + + this.channel.flush(); + } + + /** + * Returns the socket address of the remote side. Server-only. + */ + public SocketAddress getRemoteAddress() + { + return this.socketAddress; + } + + /** + * Closes the channel, the parameter can be used for an exit message (not certain how it gets sent) + */ + public void closeChannel(ChatComponent message) + { + if (this.channel.isOpen()) + { + this.channel.close().awaitUninterruptibly(); + this.terminationReason = message; + } + } + + /** + * Create a new NetworkManager from the server host and connect it to the server + * + * @param address The address of the server + * @param serverPort The server port + * @param useNativeTransport True if the client use the native transport system + */ + public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport) + { + final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); + Class oclass; + LazyLoadBase lazyloadbase; + + if (Epoll.isAvailable() && useNativeTransport) + { + oclass = EpollSocketChannel.class; + lazyloadbase = CLIENT_EPOLL_EVENTLOOP; + } + else + { + oclass = NioSocketChannel.class; + lazyloadbase = CLIENT_NIO_EVENTLOOP; + } + + ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer() + { + protected void initChannel(Channel p_initChannel_1_) throws Exception + { + try + { + p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); + } + catch (ChannelException var3) + { + ; + } + + p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); + } + })).channel(oclass)).connect(address, serverPort).syncUninterruptibly(); + return networkmanager; + } + + public boolean isChannelOpen() + { + return this.channel != null && this.channel.isOpen(); + } + + public boolean hasNoChannel() + { + return this.channel == null; + } + + /** + * Gets the current handler for processing packets + */ + public INetHandler getNetHandler() + { + return this.packetListener; + } + + /** + * If this channel is closed, returns the exit message, null otherwise. + */ + public ChatComponent getExitMessage() + { + return this.terminationReason; + } + + /** + * Switches the channel to manual reading modus + */ + public void disableAutoRead() + { + this.channel.config().setAutoRead(false); + } + + public void setCompressionTreshold(int treshold) + { + if (treshold >= 0) + { + if (this.channel.pipeline().get("decompress") instanceof NettyCompressionDecoder) + { + ((NettyCompressionDecoder)this.channel.pipeline().get("decompress")).setCompressionTreshold(treshold); + } + else + { + this.channel.pipeline().addBefore("decoder", "decompress", new NettyCompressionDecoder(treshold)); + } + + if (this.channel.pipeline().get("compress") instanceof NettyCompressionEncoder) + { + ((NettyCompressionEncoder)this.channel.pipeline().get("decompress")).setCompressionTreshold(treshold); + } + else + { + this.channel.pipeline().addBefore("encoder", "compress", new NettyCompressionEncoder(treshold)); + } + } + else + { + if (this.channel.pipeline().get("decompress") instanceof NettyCompressionDecoder) + { + this.channel.pipeline().remove("decompress"); + } + + if (this.channel.pipeline().get("compress") instanceof NettyCompressionEncoder) + { + this.channel.pipeline().remove("compress"); + } + } + } + + public void checkDisconnected() + { + if (this.channel != null && !this.channel.isOpen()) + { + if (!this.disconnected) + { + this.disconnected = true; + + if (this.getExitMessage() != null) + { + this.getNetHandler().onDisconnect(this, this.getExitMessage()); + } + else if (this.getNetHandler() != null) + { + this.getNetHandler().onDisconnect(this, new ChatComponentText("Disconnected")); + } + } + else + { + Log.warn("handleDisconnection() called twice"); + } + } + } + + static class InboundHandlerTuplePacketListener + { + private final Packet packet; + private final GenericFutureListener > [] futureListeners; + + public InboundHandlerTuplePacketListener(Packet inPacket, GenericFutureListener > ... inFutureListeners) + { + this.packet = inPacket; + this.futureListeners = inFutureListeners; + } + } +} diff --git a/proxy/src/main/java/proxy/network/Packet.java b/proxy/src/main/java/proxy/network/Packet.java new file mode 100755 index 0000000..356261d --- /dev/null +++ b/proxy/src/main/java/proxy/network/Packet.java @@ -0,0 +1,9 @@ +package proxy.network; + +import java.io.IOException; + +public interface Packet { + void readPacketData(PacketBuffer buf) throws IOException; + void writePacketData(PacketBuffer buf) throws IOException; + void processPacket(T handler); +} diff --git a/proxy/src/main/java/proxy/network/PacketBuffer.java b/proxy/src/main/java/proxy/network/PacketBuffer.java new file mode 100755 index 0000000..6b1629e --- /dev/null +++ b/proxy/src/main/java/proxy/network/PacketBuffer.java @@ -0,0 +1,1054 @@ +package proxy.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import io.netty.buffer.ByteBufProcessor; +import io.netty.handler.codec.DecoderException; +import io.netty.handler.codec.EncoderException; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.GatheringByteChannel; +import java.nio.channels.ScatteringByteChannel; +import java.nio.charset.Charset; +import java.util.UUID; + +import proxy.nbt.NBTSizeTracker; +import proxy.nbt.NBTTagCompound; +import proxy.util.BlockPos; +import proxy.util.ChatComponent; +import proxy.util.ItemStack; + +public class PacketBuffer extends ByteBuf +{ + private static final Charset UTF_8 = Charset.forName("UTF-8"); + + private final ByteBuf buf; + + public PacketBuffer(ByteBuf wrapped) + { + this.buf = wrapped; + } + + /** + * Calculates the number of bytes required to fit the supplied int (0-5) if it were to be read/written using + * readVarIntFromBuffer or writeVarIntToBuffer + */ + public static int getVarIntSize(int input) + { + for (int i = 1; i < 5; ++i) + { + if ((input & -1 << i * 7) == 0) + { + return i; + } + } + + return 5; + } + + public void writeByteArray(byte[] array) + { + this.writeVarIntToBuffer(array.length); + this.writeBytes(array); + } + + public byte[] readByteArray() + { + byte[] abyte = new byte[this.readVarIntFromBuffer()]; + this.readBytes(abyte); + return abyte; + } + + public BlockPos readBlockPos() + { + return BlockPos.fromLong(this.readLong()); + } + + public void writeBlockPos(BlockPos pos) + { + this.writeLong(pos.toLong()); + } + + public ChatComponent readChatComponent() throws IOException + { + return ChatComponent.Serializer.jsonToComponent(this.readStringFromBuffer(32767)); + } + + public void writeChatComponent(ChatComponent component) throws IOException + { + this.writeString(ChatComponent.Serializer.componentToJson(component)); + } + + public > T readEnumValue(Class enumClass) + { + return (T)((Enum[])enumClass.getEnumConstants())[this.readVarIntFromBuffer()]; + } + + public void writeEnumValue(Enum value) + { + this.writeVarIntToBuffer(value.ordinal()); + } + + /** + * Reads a compressed int from the buffer. To do so it maximally reads 5 byte-sized chunks whose most significant + * bit dictates whether another byte should be read. + */ + public int readVarIntFromBuffer() + { + int i = 0; + int j = 0; + + while (true) + { + byte b0 = this.readByte(); + i |= (b0 & 127) << j++ * 7; + + if (j > 5) + { + throw new RuntimeException("VarInt too big"); + } + + if ((b0 & 128) != 128) + { + break; + } + } + + return i; + } + + public long readVarLong() + { + long i = 0L; + int j = 0; + + while (true) + { + byte b0 = this.readByte(); + i |= (long)(b0 & 127) << j++ * 7; + + if (j > 10) + { + throw new RuntimeException("VarLong too big"); + } + + if ((b0 & 128) != 128) + { + break; + } + } + + return i; + } + + public void writeUuid(UUID uuid) + { + this.writeLong(uuid.getMostSignificantBits()); + this.writeLong(uuid.getLeastSignificantBits()); + } + + public UUID readUuid() + { + return new UUID(this.readLong(), this.readLong()); + } + + /** + * Writes a compressed int to the buffer. The smallest number of bytes to fit the passed int will be written. Of + * each such byte only 7 bits will be used to describe the actual value since its most significant bit dictates + * whether the next byte is part of that same int. Micro-optimization for int values that are expected to have + * values below 128. + */ + public void writeVarIntToBuffer(int input) + { + while ((input & -128) != 0) + { + this.writeByte(input & 127 | 128); + input >>>= 7; + } + + this.writeByte(input); + } + + public void writeVarLong(long value) + { + while ((value & -128L) != 0L) + { + this.writeByte((int)(value & 127L) | 128); + value >>>= 7; + } + + this.writeByte((int)value); + } + + private static NBTTagCompound readTag(DataInput in) throws IOException { + if(in.readByte() != 10) + throw new IOException("Root tag must be a named compound tag"); + in.readUTF(); + NBTTagCompound tag = new NBTTagCompound(); + tag.read(in, 0, new NBTSizeTracker(2097152L)); + return tag; + } + + private static void writeTag(NBTTagCompound tag, DataOutput out) throws IOException { + out.writeByte(tag.getId()); + out.writeUTF(""); + tag.write(out); + } + + /** + * Writes a compressed NBTTagCompound to this buffer + */ + public void writeNBTTagCompoundToBuffer(NBTTagCompound nbt) + { + if (nbt == null) + { + this.writeByte(0); + } + else + { + try + { + writeTag(nbt, new ByteBufOutputStream(this)); + } + catch (IOException ioexception) + { + throw new EncoderException(ioexception); + } + } + } + + /** + * Reads a compressed NBTTagCompound from this buffer + */ + public NBTTagCompound readNBTTagCompoundFromBuffer() throws IOException + { + int i = this.readerIndex(); + byte b0 = this.readByte(); + + if (b0 == 0) + { + return null; + } + else + { + this.readerIndex(i); + return readTag(new ByteBufInputStream(this)); + } + } + + /** + * Writes the ItemStack's ID (short), then size (byte), then damage. (short) + */ + public void writeItemStackToBuffer(ItemStack stack) + { + if (stack == null) + { + this.writeShort(-1); + } + else + { + this.writeShort(stack.getId()); + this.writeByte(stack.getSize()); + this.writeShort(stack.getMeta()); + this.writeNBTTagCompoundToBuffer(stack.getTag()); + } + } + + /** + * Reads an ItemStack from this buffer + */ + public ItemStack readItemStackFromBuffer() throws IOException + { + ItemStack stack = null; + short id = this.readShort(); + + if (id >= 0) + { + byte size = this.readByte(); + short meta = this.readShort(); + stack = new ItemStack(id, size, meta, this.readNBTTagCompoundFromBuffer()); + } + + return stack; + } + + /** + * Reads a string from this buffer. Expected parameter is maximum allowed string length. Will throw IOException if + * string length exceeds this value! + */ + public String readStringFromBuffer(int maxLength) + { + int i = this.readVarIntFromBuffer(); + + if (i > maxLength * 4) + { + throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + i + " > " + maxLength * 4 + ")"); + } + else if (i < 0) + { + throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!"); + } + else + { + String s = new String(this.readBytes(i).array(), UTF_8); + + if (s.length() > maxLength) + { + throw new DecoderException("The received string length is longer than maximum allowed (" + i + " > " + maxLength + ")"); + } + else + { + return s; + } + } + } + + public PacketBuffer writeString(String string) + { + byte[] abyte = string.getBytes(UTF_8); + + if (abyte.length > 32767) + { + throw new EncoderException("String too big (was " + string.length() + " bytes encoded, max " + 32767 + ")"); + } + else + { + this.writeVarIntToBuffer(abyte.length); + this.writeBytes(abyte); + return this; + } + } + + public int capacity() + { + return this.buf.capacity(); + } + + public ByteBuf capacity(int p_capacity_1_) + { + return this.buf.capacity(p_capacity_1_); + } + + public int maxCapacity() + { + return this.buf.maxCapacity(); + } + + public ByteBufAllocator alloc() + { + return this.buf.alloc(); + } + + public ByteOrder order() + { + return this.buf.order(); + } + + public ByteBuf order(ByteOrder p_order_1_) + { + return this.buf.order(p_order_1_); + } + + public ByteBuf unwrap() + { + return this.buf.unwrap(); + } + + public boolean isDirect() + { + return this.buf.isDirect(); + } + + public int readerIndex() + { + return this.buf.readerIndex(); + } + + public ByteBuf readerIndex(int p_readerIndex_1_) + { + return this.buf.readerIndex(p_readerIndex_1_); + } + + public int writerIndex() + { + return this.buf.writerIndex(); + } + + public ByteBuf writerIndex(int p_writerIndex_1_) + { + return this.buf.writerIndex(p_writerIndex_1_); + } + + public ByteBuf setIndex(int p_setIndex_1_, int p_setIndex_2_) + { + return this.buf.setIndex(p_setIndex_1_, p_setIndex_2_); + } + + public int readableBytes() + { + return this.buf.readableBytes(); + } + + public int writableBytes() + { + return this.buf.writableBytes(); + } + + public int maxWritableBytes() + { + return this.buf.maxWritableBytes(); + } + + public boolean isReadable() + { + return this.buf.isReadable(); + } + + public boolean isReadable(int p_isReadable_1_) + { + return this.buf.isReadable(p_isReadable_1_); + } + + public boolean isWritable() + { + return this.buf.isWritable(); + } + + public boolean isWritable(int p_isWritable_1_) + { + return this.buf.isWritable(p_isWritable_1_); + } + + public ByteBuf clear() + { + return this.buf.clear(); + } + + public ByteBuf markReaderIndex() + { + return this.buf.markReaderIndex(); + } + + public ByteBuf resetReaderIndex() + { + return this.buf.resetReaderIndex(); + } + + public ByteBuf markWriterIndex() + { + return this.buf.markWriterIndex(); + } + + public ByteBuf resetWriterIndex() + { + return this.buf.resetWriterIndex(); + } + + public ByteBuf discardReadBytes() + { + return this.buf.discardReadBytes(); + } + + public ByteBuf discardSomeReadBytes() + { + return this.buf.discardSomeReadBytes(); + } + + public ByteBuf ensureWritable(int p_ensureWritable_1_) + { + return this.buf.ensureWritable(p_ensureWritable_1_); + } + + public int ensureWritable(int p_ensureWritable_1_, boolean p_ensureWritable_2_) + { + return this.buf.ensureWritable(p_ensureWritable_1_, p_ensureWritable_2_); + } + + public boolean getBoolean(int p_getBoolean_1_) + { + return this.buf.getBoolean(p_getBoolean_1_); + } + + public byte getByte(int p_getByte_1_) + { + return this.buf.getByte(p_getByte_1_); + } + + public short getUnsignedByte(int p_getUnsignedByte_1_) + { + return this.buf.getUnsignedByte(p_getUnsignedByte_1_); + } + + public short getShort(int p_getShort_1_) + { + return this.buf.getShort(p_getShort_1_); + } + + public int getUnsignedShort(int p_getUnsignedShort_1_) + { + return this.buf.getUnsignedShort(p_getUnsignedShort_1_); + } + + public int getMedium(int p_getMedium_1_) + { + return this.buf.getMedium(p_getMedium_1_); + } + + public int getUnsignedMedium(int p_getUnsignedMedium_1_) + { + return this.buf.getUnsignedMedium(p_getUnsignedMedium_1_); + } + + public int getInt(int p_getInt_1_) + { + return this.buf.getInt(p_getInt_1_); + } + + public long getUnsignedInt(int p_getUnsignedInt_1_) + { + return this.buf.getUnsignedInt(p_getUnsignedInt_1_); + } + + public long getLong(int p_getLong_1_) + { + return this.buf.getLong(p_getLong_1_); + } + + public char getChar(int p_getChar_1_) + { + return this.buf.getChar(p_getChar_1_); + } + + public float getFloat(int p_getFloat_1_) + { + return this.buf.getFloat(p_getFloat_1_); + } + + public double getDouble(int p_getDouble_1_) + { + return this.buf.getDouble(p_getDouble_1_); + } + + public ByteBuf getBytes(int p_getBytes_1_, ByteBuf p_getBytes_2_) + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_); + } + + public ByteBuf getBytes(int p_getBytes_1_, ByteBuf p_getBytes_2_, int p_getBytes_3_) + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_, p_getBytes_3_); + } + + public ByteBuf getBytes(int p_getBytes_1_, ByteBuf p_getBytes_2_, int p_getBytes_3_, int p_getBytes_4_) + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_, p_getBytes_3_, p_getBytes_4_); + } + + public ByteBuf getBytes(int p_getBytes_1_, byte[] p_getBytes_2_) + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_); + } + + public ByteBuf getBytes(int p_getBytes_1_, byte[] p_getBytes_2_, int p_getBytes_3_, int p_getBytes_4_) + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_, p_getBytes_3_, p_getBytes_4_); + } + + public ByteBuf getBytes(int p_getBytes_1_, ByteBuffer p_getBytes_2_) + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_); + } + + public ByteBuf getBytes(int p_getBytes_1_, OutputStream p_getBytes_2_, int p_getBytes_3_) throws IOException + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_, p_getBytes_3_); + } + + public int getBytes(int p_getBytes_1_, GatheringByteChannel p_getBytes_2_, int p_getBytes_3_) throws IOException + { + return this.buf.getBytes(p_getBytes_1_, p_getBytes_2_, p_getBytes_3_); + } + + public ByteBuf setBoolean(int p_setBoolean_1_, boolean p_setBoolean_2_) + { + return this.buf.setBoolean(p_setBoolean_1_, p_setBoolean_2_); + } + + public ByteBuf setByte(int p_setByte_1_, int p_setByte_2_) + { + return this.buf.setByte(p_setByte_1_, p_setByte_2_); + } + + public ByteBuf setShort(int p_setShort_1_, int p_setShort_2_) + { + return this.buf.setShort(p_setShort_1_, p_setShort_2_); + } + + public ByteBuf setMedium(int p_setMedium_1_, int p_setMedium_2_) + { + return this.buf.setMedium(p_setMedium_1_, p_setMedium_2_); + } + + public ByteBuf setInt(int p_setInt_1_, int p_setInt_2_) + { + return this.buf.setInt(p_setInt_1_, p_setInt_2_); + } + + public ByteBuf setLong(int p_setLong_1_, long p_setLong_2_) + { + return this.buf.setLong(p_setLong_1_, p_setLong_2_); + } + + public ByteBuf setChar(int p_setChar_1_, int p_setChar_2_) + { + return this.buf.setChar(p_setChar_1_, p_setChar_2_); + } + + public ByteBuf setFloat(int p_setFloat_1_, float p_setFloat_2_) + { + return this.buf.setFloat(p_setFloat_1_, p_setFloat_2_); + } + + public ByteBuf setDouble(int p_setDouble_1_, double p_setDouble_2_) + { + return this.buf.setDouble(p_setDouble_1_, p_setDouble_2_); + } + + public ByteBuf setBytes(int p_setBytes_1_, ByteBuf p_setBytes_2_) + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_); + } + + public ByteBuf setBytes(int p_setBytes_1_, ByteBuf p_setBytes_2_, int p_setBytes_3_) + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_, p_setBytes_3_); + } + + public ByteBuf setBytes(int p_setBytes_1_, ByteBuf p_setBytes_2_, int p_setBytes_3_, int p_setBytes_4_) + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_, p_setBytes_3_, p_setBytes_4_); + } + + public ByteBuf setBytes(int p_setBytes_1_, byte[] p_setBytes_2_) + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_); + } + + public ByteBuf setBytes(int p_setBytes_1_, byte[] p_setBytes_2_, int p_setBytes_3_, int p_setBytes_4_) + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_, p_setBytes_3_, p_setBytes_4_); + } + + public ByteBuf setBytes(int p_setBytes_1_, ByteBuffer p_setBytes_2_) + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_); + } + + public int setBytes(int p_setBytes_1_, InputStream p_setBytes_2_, int p_setBytes_3_) throws IOException + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_, p_setBytes_3_); + } + + public int setBytes(int p_setBytes_1_, ScatteringByteChannel p_setBytes_2_, int p_setBytes_3_) throws IOException + { + return this.buf.setBytes(p_setBytes_1_, p_setBytes_2_, p_setBytes_3_); + } + + public ByteBuf setZero(int p_setZero_1_, int p_setZero_2_) + { + return this.buf.setZero(p_setZero_1_, p_setZero_2_); + } + + public boolean readBoolean() + { + return this.buf.readBoolean(); + } + + public byte readByte() + { + return this.buf.readByte(); + } + + public short readUnsignedByte() + { + return this.buf.readUnsignedByte(); + } + + public short readShort() + { + return this.buf.readShort(); + } + + public int readUnsignedShort() + { + return this.buf.readUnsignedShort(); + } + + public int readMedium() + { + return this.buf.readMedium(); + } + + public int readUnsignedMedium() + { + return this.buf.readUnsignedMedium(); + } + + public int readInt() + { + return this.buf.readInt(); + } + + public long readUnsignedInt() + { + return this.buf.readUnsignedInt(); + } + + public long readLong() + { + return this.buf.readLong(); + } + + public char readChar() + { + return this.buf.readChar(); + } + + public float readFloat() + { + return this.buf.readFloat(); + } + + public double readDouble() + { + return this.buf.readDouble(); + } + + public ByteBuf readBytes(int p_readBytes_1_) + { + return this.buf.readBytes(p_readBytes_1_); + } + + public ByteBuf readSlice(int p_readSlice_1_) + { + return this.buf.readSlice(p_readSlice_1_); + } + + public ByteBuf readBytes(ByteBuf p_readBytes_1_) + { + return this.buf.readBytes(p_readBytes_1_); + } + + public ByteBuf readBytes(ByteBuf p_readBytes_1_, int p_readBytes_2_) + { + return this.buf.readBytes(p_readBytes_1_, p_readBytes_2_); + } + + public ByteBuf readBytes(ByteBuf p_readBytes_1_, int p_readBytes_2_, int p_readBytes_3_) + { + return this.buf.readBytes(p_readBytes_1_, p_readBytes_2_, p_readBytes_3_); + } + + public ByteBuf readBytes(byte[] p_readBytes_1_) + { + return this.buf.readBytes(p_readBytes_1_); + } + + public ByteBuf readBytes(byte[] p_readBytes_1_, int p_readBytes_2_, int p_readBytes_3_) + { + return this.buf.readBytes(p_readBytes_1_, p_readBytes_2_, p_readBytes_3_); + } + + public ByteBuf readBytes(ByteBuffer p_readBytes_1_) + { + return this.buf.readBytes(p_readBytes_1_); + } + + public ByteBuf readBytes(OutputStream p_readBytes_1_, int p_readBytes_2_) throws IOException + { + return this.buf.readBytes(p_readBytes_1_, p_readBytes_2_); + } + + public int readBytes(GatheringByteChannel p_readBytes_1_, int p_readBytes_2_) throws IOException + { + return this.buf.readBytes(p_readBytes_1_, p_readBytes_2_); + } + + public ByteBuf skipBytes(int p_skipBytes_1_) + { + return this.buf.skipBytes(p_skipBytes_1_); + } + + public ByteBuf writeBoolean(boolean p_writeBoolean_1_) + { + return this.buf.writeBoolean(p_writeBoolean_1_); + } + + public ByteBuf writeByte(int p_writeByte_1_) + { + return this.buf.writeByte(p_writeByte_1_); + } + + public ByteBuf writeShort(int p_writeShort_1_) + { + return this.buf.writeShort(p_writeShort_1_); + } + + public ByteBuf writeMedium(int p_writeMedium_1_) + { + return this.buf.writeMedium(p_writeMedium_1_); + } + + public ByteBuf writeInt(int p_writeInt_1_) + { + return this.buf.writeInt(p_writeInt_1_); + } + + public ByteBuf writeLong(long p_writeLong_1_) + { + return this.buf.writeLong(p_writeLong_1_); + } + + public ByteBuf writeChar(int p_writeChar_1_) + { + return this.buf.writeChar(p_writeChar_1_); + } + + public ByteBuf writeFloat(float p_writeFloat_1_) + { + return this.buf.writeFloat(p_writeFloat_1_); + } + + public ByteBuf writeDouble(double p_writeDouble_1_) + { + return this.buf.writeDouble(p_writeDouble_1_); + } + + public ByteBuf writeBytes(ByteBuf p_writeBytes_1_) + { + return this.buf.writeBytes(p_writeBytes_1_); + } + + public ByteBuf writeBytes(ByteBuf p_writeBytes_1_, int p_writeBytes_2_) + { + return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_); + } + + public ByteBuf writeBytes(ByteBuf p_writeBytes_1_, int p_writeBytes_2_, int p_writeBytes_3_) + { + return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_, p_writeBytes_3_); + } + + public ByteBuf writeBytes(byte[] p_writeBytes_1_) + { + return this.buf.writeBytes(p_writeBytes_1_); + } + + public ByteBuf writeBytes(byte[] p_writeBytes_1_, int p_writeBytes_2_, int p_writeBytes_3_) + { + return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_, p_writeBytes_3_); + } + + public ByteBuf writeBytes(ByteBuffer p_writeBytes_1_) + { + return this.buf.writeBytes(p_writeBytes_1_); + } + + public int writeBytes(InputStream p_writeBytes_1_, int p_writeBytes_2_) throws IOException + { + return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_); + } + + public int writeBytes(ScatteringByteChannel p_writeBytes_1_, int p_writeBytes_2_) throws IOException + { + return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_); + } + + public ByteBuf writeZero(int p_writeZero_1_) + { + return this.buf.writeZero(p_writeZero_1_); + } + + public int indexOf(int p_indexOf_1_, int p_indexOf_2_, byte p_indexOf_3_) + { + return this.buf.indexOf(p_indexOf_1_, p_indexOf_2_, p_indexOf_3_); + } + + public int bytesBefore(byte p_bytesBefore_1_) + { + return this.buf.bytesBefore(p_bytesBefore_1_); + } + + public int bytesBefore(int p_bytesBefore_1_, byte p_bytesBefore_2_) + { + return this.buf.bytesBefore(p_bytesBefore_1_, p_bytesBefore_2_); + } + + public int bytesBefore(int p_bytesBefore_1_, int p_bytesBefore_2_, byte p_bytesBefore_3_) + { + return this.buf.bytesBefore(p_bytesBefore_1_, p_bytesBefore_2_, p_bytesBefore_3_); + } + + public int forEachByte(ByteBufProcessor p_forEachByte_1_) + { + return this.buf.forEachByte(p_forEachByte_1_); + } + + public int forEachByte(int p_forEachByte_1_, int p_forEachByte_2_, ByteBufProcessor p_forEachByte_3_) + { + return this.buf.forEachByte(p_forEachByte_1_, p_forEachByte_2_, p_forEachByte_3_); + } + + public int forEachByteDesc(ByteBufProcessor p_forEachByteDesc_1_) + { + return this.buf.forEachByteDesc(p_forEachByteDesc_1_); + } + + public int forEachByteDesc(int p_forEachByteDesc_1_, int p_forEachByteDesc_2_, ByteBufProcessor p_forEachByteDesc_3_) + { + return this.buf.forEachByteDesc(p_forEachByteDesc_1_, p_forEachByteDesc_2_, p_forEachByteDesc_3_); + } + + public ByteBuf copy() + { + return this.buf.copy(); + } + + public ByteBuf copy(int p_copy_1_, int p_copy_2_) + { + return this.buf.copy(p_copy_1_, p_copy_2_); + } + + public ByteBuf slice() + { + return this.buf.slice(); + } + + public ByteBuf slice(int p_slice_1_, int p_slice_2_) + { + return this.buf.slice(p_slice_1_, p_slice_2_); + } + + public ByteBuf duplicate() + { + return this.buf.duplicate(); + } + + public int nioBufferCount() + { + return this.buf.nioBufferCount(); + } + + public ByteBuffer nioBuffer() + { + return this.buf.nioBuffer(); + } + + public ByteBuffer nioBuffer(int p_nioBuffer_1_, int p_nioBuffer_2_) + { + return this.buf.nioBuffer(p_nioBuffer_1_, p_nioBuffer_2_); + } + + public ByteBuffer internalNioBuffer(int p_internalNioBuffer_1_, int p_internalNioBuffer_2_) + { + return this.buf.internalNioBuffer(p_internalNioBuffer_1_, p_internalNioBuffer_2_); + } + + public ByteBuffer[] nioBuffers() + { + return this.buf.nioBuffers(); + } + + public ByteBuffer[] nioBuffers(int p_nioBuffers_1_, int p_nioBuffers_2_) + { + return this.buf.nioBuffers(p_nioBuffers_1_, p_nioBuffers_2_); + } + + public boolean hasArray() + { + return this.buf.hasArray(); + } + + public byte[] array() + { + return this.buf.array(); + } + + public int arrayOffset() + { + return this.buf.arrayOffset(); + } + + public boolean hasMemoryAddress() + { + return this.buf.hasMemoryAddress(); + } + + public long memoryAddress() + { + return this.buf.memoryAddress(); + } + + public String toString(Charset p_toString_1_) + { + return this.buf.toString(p_toString_1_); + } + + public String toString(int p_toString_1_, int p_toString_2_, Charset p_toString_3_) + { + return this.buf.toString(p_toString_1_, p_toString_2_, p_toString_3_); + } + + public int hashCode() + { + return this.buf.hashCode(); + } + + public boolean equals(Object p_equals_1_) + { + return this.buf.equals(p_equals_1_); + } + + public int compareTo(ByteBuf p_compareTo_1_) + { + return this.buf.compareTo(p_compareTo_1_); + } + + public String toString() + { + return this.buf.toString(); + } + + public ByteBuf retain(int p_retain_1_) + { + return this.buf.retain(p_retain_1_); + } + + public ByteBuf retain() + { + return this.buf.retain(); + } + + public int refCnt() + { + return this.buf.refCnt(); + } + + public boolean release() + { + return this.buf.release(); + } + + public boolean release(int p_release_1_) + { + return this.buf.release(p_release_1_); + } +} diff --git a/proxy/src/main/java/proxy/network/PacketThreadUtil.java b/proxy/src/main/java/proxy/network/PacketThreadUtil.java new file mode 100755 index 0000000..7d19b08 --- /dev/null +++ b/proxy/src/main/java/proxy/network/PacketThreadUtil.java @@ -0,0 +1,16 @@ +package proxy.network; + +import proxy.Proxy; + +public class PacketThreadUtil { + public static void checkThreadAndEnqueue(final Packet packet, final T handler, Proxy proxy) throws ThreadQuickExitException { + if(!proxy.isCallingFromMinecraftThread()) { + proxy.schedule(new Runnable() { + public void run() { + packet.processPacket(handler); + } + }); + throw ThreadQuickExitException.INSTANCE; + } + } +} diff --git a/proxy/src/main/java/proxy/network/ServerStatusResponse.java b/proxy/src/main/java/proxy/network/ServerStatusResponse.java new file mode 100755 index 0000000..59f52a9 --- /dev/null +++ b/proxy/src/main/java/proxy/network/ServerStatusResponse.java @@ -0,0 +1,249 @@ +package proxy.network; + +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.util.UUID; + +import proxy.util.ChatComponent; +import proxy.util.GameProfile; +import proxy.util.JsonUtils; + +public class ServerStatusResponse +{ + private ChatComponent serverMotd; + private ServerStatusResponse.PlayerCountData playerCount; + private ServerStatusResponse.MinecraftProtocolVersionIdentifier protocolVersion; + private String favicon; + + public ChatComponent getServerDescription() + { + return this.serverMotd; + } + + public void setServerDescription(ChatComponent motd) + { + this.serverMotd = motd; + } + + public ServerStatusResponse.PlayerCountData getPlayerCountData() + { + return this.playerCount; + } + + public void setPlayerCountData(ServerStatusResponse.PlayerCountData countData) + { + this.playerCount = countData; + } + + public ServerStatusResponse.MinecraftProtocolVersionIdentifier getProtocolVersionInfo() + { + return this.protocolVersion; + } + + public void setProtocolVersionInfo(ServerStatusResponse.MinecraftProtocolVersionIdentifier protocolVersionData) + { + this.protocolVersion = protocolVersionData; + } + + public void setFavicon(String faviconBlob) + { + this.favicon = faviconBlob; + } + + public String getFavicon() + { + return this.favicon; + } + + public static class MinecraftProtocolVersionIdentifier + { + private final String name; + private final int protocol; + + public MinecraftProtocolVersionIdentifier(String nameIn, int protocolIn) + { + this.name = nameIn; + this.protocol = protocolIn; + } + + public String getName() + { + return this.name; + } + + public int getProtocol() + { + return this.protocol; + } + + public static class Serializer implements JsonDeserializer, JsonSerializer + { + public ServerStatusResponse.MinecraftProtocolVersionIdentifier deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException + { + JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "version"); + return new ServerStatusResponse.MinecraftProtocolVersionIdentifier(JsonUtils.getString(jsonobject, "name"), JsonUtils.getInt(jsonobject, "protocol")); + } + + public JsonElement serialize(ServerStatusResponse.MinecraftProtocolVersionIdentifier p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) + { + JsonObject jsonobject = new JsonObject(); + jsonobject.addProperty("name", p_serialize_1_.getName()); + jsonobject.addProperty("protocol", (Number)Integer.valueOf(p_serialize_1_.getProtocol())); + return jsonobject; + } + } + } + + public static class PlayerCountData + { + private final int maxPlayers; + private final int onlinePlayerCount; + private GameProfile[] players; + + public PlayerCountData(int maxOnlinePlayers, int onlinePlayers) + { + this.maxPlayers = maxOnlinePlayers; + this.onlinePlayerCount = onlinePlayers; + } + + public int getMaxPlayers() + { + return this.maxPlayers; + } + + public int getOnlinePlayerCount() + { + return this.onlinePlayerCount; + } + + public GameProfile[] getPlayers() + { + return this.players; + } + + public void setPlayers(GameProfile[] playersIn) + { + this.players = playersIn; + } + + public static class Serializer implements JsonDeserializer, JsonSerializer + { + public ServerStatusResponse.PlayerCountData deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException + { + JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "players"); + ServerStatusResponse.PlayerCountData serverstatusresponse$playercountdata = new ServerStatusResponse.PlayerCountData(JsonUtils.getInt(jsonobject, "max"), JsonUtils.getInt(jsonobject, "online")); + + if (JsonUtils.isJsonArray(jsonobject, "sample")) + { + JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sample"); + + if (jsonarray.size() > 0) + { + GameProfile[] agameprofile = new GameProfile[jsonarray.size()]; + + for (int i = 0; i < agameprofile.length; ++i) + { + JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonarray.get(i), "player[" + i + "]"); + String s = JsonUtils.getString(jsonobject1, "id"); + agameprofile[i] = new GameProfile(UUID.fromString(s), JsonUtils.getString(jsonobject1, "name")); + } + + serverstatusresponse$playercountdata.setPlayers(agameprofile); + } + } + + return serverstatusresponse$playercountdata; + } + + public JsonElement serialize(ServerStatusResponse.PlayerCountData p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) + { + JsonObject jsonobject = new JsonObject(); + jsonobject.addProperty("max", (Number)Integer.valueOf(p_serialize_1_.getMaxPlayers())); + jsonobject.addProperty("online", (Number)Integer.valueOf(p_serialize_1_.getOnlinePlayerCount())); + + if (p_serialize_1_.getPlayers() != null && p_serialize_1_.getPlayers().length > 0) + { + JsonArray jsonarray = new JsonArray(); + + for (int i = 0; i < p_serialize_1_.getPlayers().length; ++i) + { + JsonObject jsonobject1 = new JsonObject(); + UUID uuid = p_serialize_1_.getPlayers()[i].getId(); + jsonobject1.addProperty("id", uuid == null ? "" : uuid.toString()); + jsonobject1.addProperty("name", p_serialize_1_.getPlayers()[i].getName()); + jsonarray.add(jsonobject1); + } + + jsonobject.add("sample", jsonarray); + } + + return jsonobject; + } + } + } + + public static class Serializer implements JsonDeserializer, JsonSerializer + { + public ServerStatusResponse deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException + { + JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "status"); + ServerStatusResponse serverstatusresponse = new ServerStatusResponse(); + + if (jsonobject.has("description")) + { + serverstatusresponse.setServerDescription((ChatComponent)p_deserialize_3_.deserialize(jsonobject.get("description"), ChatComponent.class)); + } + + if (jsonobject.has("players")) + { + serverstatusresponse.setPlayerCountData((ServerStatusResponse.PlayerCountData)p_deserialize_3_.deserialize(jsonobject.get("players"), ServerStatusResponse.PlayerCountData.class)); + } + + if (jsonobject.has("version")) + { + serverstatusresponse.setProtocolVersionInfo((ServerStatusResponse.MinecraftProtocolVersionIdentifier)p_deserialize_3_.deserialize(jsonobject.get("version"), ServerStatusResponse.MinecraftProtocolVersionIdentifier.class)); + } + + if (jsonobject.has("favicon")) + { + serverstatusresponse.setFavicon(JsonUtils.getString(jsonobject, "favicon")); + } + + return serverstatusresponse; + } + + public JsonElement serialize(ServerStatusResponse p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) + { + JsonObject jsonobject = new JsonObject(); + + if (p_serialize_1_.getServerDescription() != null) + { + jsonobject.add("description", p_serialize_3_.serialize(p_serialize_1_.getServerDescription())); + } + + if (p_serialize_1_.getPlayerCountData() != null) + { + jsonobject.add("players", p_serialize_3_.serialize(p_serialize_1_.getPlayerCountData())); + } + + if (p_serialize_1_.getProtocolVersionInfo() != null) + { + jsonobject.add("version", p_serialize_3_.serialize(p_serialize_1_.getProtocolVersionInfo())); + } + + if (p_serialize_1_.getFavicon() != null) + { + jsonobject.addProperty("favicon", p_serialize_1_.getFavicon()); + } + + return jsonobject; + } + } +} diff --git a/proxy/src/main/java/proxy/network/ThreadQuickExitException.java b/proxy/src/main/java/proxy/network/ThreadQuickExitException.java new file mode 100755 index 0000000..df57f15 --- /dev/null +++ b/proxy/src/main/java/proxy/network/ThreadQuickExitException.java @@ -0,0 +1,14 @@ +package proxy.network; + +public final class ThreadQuickExitException extends RuntimeException { + public static final ThreadQuickExitException INSTANCE = new ThreadQuickExitException(); + + private ThreadQuickExitException() { + this.setStackTrace(new StackTraceElement[0]); + } + + public synchronized Throwable fillInStackTrace() { + this.setStackTrace(new StackTraceElement[0]); + return this; + } +} diff --git a/proxy/src/main/java/proxy/util/BlockPos.java b/proxy/src/main/java/proxy/util/BlockPos.java new file mode 100755 index 0000000..000d865 --- /dev/null +++ b/proxy/src/main/java/proxy/util/BlockPos.java @@ -0,0 +1,45 @@ +package proxy.util; + +public class BlockPos { + private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); + private static final int NUM_Z_BITS = NUM_X_BITS; + private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS; + private static final int Y_SHIFT = 0 + NUM_Z_BITS; + private static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS; + private static final long X_MASK = (1L << NUM_X_BITS) - 1L; + private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L; + private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L; + + private final int x; + private final int y; + private final int z; + + public BlockPos(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public long toLong() { + return ((long)this.getX() & X_MASK) << X_SHIFT | ((long)this.getY() & Y_MASK) << Y_SHIFT | ((long)this.getZ() & Z_MASK) << 0; + } + + public static BlockPos fromLong(long serialized) { + int i = (int)(serialized << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS); + int j = (int)(serialized << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS); + int k = (int)(serialized << 64 - NUM_Z_BITS >> 64 - NUM_Z_BITS); + return new BlockPos(i, j, k); + } +} diff --git a/proxy/src/main/java/proxy/util/ChatColor.java b/proxy/src/main/java/proxy/util/ChatColor.java new file mode 100755 index 0000000..7e3c792 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatColor.java @@ -0,0 +1,44 @@ +package proxy.util; + +import java.util.regex.Pattern; + +public enum ChatColor { + BLACK('0'), + DARK_BLUE('1'), + DARK_GREEN('2'), + DARK_AQUA('3'), + DARK_RED('4'), + DARK_PURPLE('5'), + GOLD('6'), + GRAY('7'), + DARK_GRAY('8'), + BLUE('9'), + GREEN('a'), + AQUA('b'), + RED('c'), + LIGHT_PURPLE('d'), + YELLOW('e'), + WHITE('f'), + OBFUSCATED('k'), + BOLD('l'), + STRIKETHROUGH('m'), + UNDERLINE('n'), + ITALIC('o'), + RESET('r'); + + private static final Pattern STRIP_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]"); + + private final String value; + + private ChatColor(char code) { + this.value = "\u00a7" + code; + } + + public String toString() { + return this.value; + } + + public static String strip(String str) { + return str == null ? null : STRIP_PATTERN.matcher(str).replaceAll(""); + } +} diff --git a/proxy/src/main/java/proxy/util/ChatComponent.java b/proxy/src/main/java/proxy/util/ChatComponent.java new file mode 100755 index 0000000..775aa61 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatComponent.java @@ -0,0 +1,261 @@ +package proxy.util; + +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map.Entry; + +public abstract class ChatComponent +{ + private List siblings = Lists.newArrayList(); + private ChatStyle style; + + public static class Serializer implements JsonDeserializer, JsonSerializer + { + private static final Gson GSON; + + public ChatComponent deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException + { + if (p_deserialize_1_.isJsonPrimitive()) + { + return new ChatComponentText(p_deserialize_1_.getAsString()); + } + else if (!p_deserialize_1_.isJsonObject()) + { + if (p_deserialize_1_.isJsonArray()) + { + JsonArray jsonarray1 = p_deserialize_1_.getAsJsonArray(); + ChatComponent ichatcomponent1 = null; + + for (JsonElement jsonelement : jsonarray1) + { + ChatComponent ichatcomponent2 = this.deserialize(jsonelement, jsonelement.getClass(), p_deserialize_3_); + + if (ichatcomponent1 == null) + { + ichatcomponent1 = ichatcomponent2; + } + else + { + ichatcomponent1.siblings.add(ichatcomponent2); + } + } + + return ichatcomponent1; + } + else + { + throw new JsonParseException("Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component"); + } + } + else + { + JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); + ChatComponent ichatcomponent; + + if (jsonobject.has("text")) + { + ichatcomponent = new ChatComponentText(jsonobject.get("text").getAsString()); + } + else if (jsonobject.has("translate")) + { + String s = jsonobject.get("translate").getAsString(); + + if (jsonobject.has("with")) + { + JsonArray jsonarray = jsonobject.getAsJsonArray("with"); + Object[] aobject = new Object[jsonarray.size()]; + + for (int i = 0; i < aobject.length; ++i) + { + aobject[i] = this.deserialize(jsonarray.get(i), p_deserialize_2_, p_deserialize_3_); + + if (aobject[i] instanceof ChatComponentText) + { + ChatComponentText chatcomponenttext = (ChatComponentText)aobject[i]; + + if ((((ChatComponent)chatcomponenttext).style == null || ((ChatComponent)chatcomponenttext).style.isEmpty()) && ((ChatComponent)chatcomponenttext).siblings.isEmpty()) + { + aobject[i] = chatcomponenttext.getText(); + } + } + } + + ichatcomponent = new ChatComponentTranslation(s, aobject); + } + else + { + ichatcomponent = new ChatComponentTranslation(s, new Object[0]); + } + } + else if (jsonobject.has("score")) + { + JsonObject jsonobject1 = jsonobject.getAsJsonObject("score"); + + if (!jsonobject1.has("name") || !jsonobject1.has("objective")) + { + throw new JsonParseException("A score component needs a least a name and an objective"); + } + + ichatcomponent = new ChatComponentScore(JsonUtils.getString(jsonobject1, "name"), JsonUtils.getString(jsonobject1, "objective")); + + if (jsonobject1.has("value")) + { + ((ChatComponentScore)ichatcomponent).setValue(JsonUtils.getString(jsonobject1, "value")); + } + } + else + { + if (!jsonobject.has("selector")) + { + throw new JsonParseException("Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component"); + } + + ichatcomponent = new ChatComponentSelector(JsonUtils.getString(jsonobject, "selector")); + } + + if (jsonobject.has("extra")) + { + JsonArray jsonarray2 = jsonobject.getAsJsonArray("extra"); + + if (jsonarray2.size() <= 0) + { + throw new JsonParseException("Unexpected empty array of components"); + } + + for (int j = 0; j < jsonarray2.size(); ++j) + { + ichatcomponent.siblings.add(this.deserialize(jsonarray2.get(j), p_deserialize_2_, p_deserialize_3_)); + } + } + + ichatcomponent.style = (ChatStyle)p_deserialize_3_.deserialize(p_deserialize_1_, ChatStyle.class); + return ichatcomponent; + } + } + + private void serializeChatStyle(ChatStyle style, JsonObject object, JsonSerializationContext ctx) + { + JsonElement jsonelement = ctx.serialize(style); + + if (jsonelement.isJsonObject()) + { + JsonObject jsonobject = (JsonObject)jsonelement; + + for (Entry entry : jsonobject.entrySet()) + { + object.add((String)entry.getKey(), (JsonElement)entry.getValue()); + } + } + } + + public JsonElement serialize(ChatComponent p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) + { + if (p_serialize_1_ instanceof ChatComponentText && (p_serialize_1_.style == null || p_serialize_1_.style.isEmpty()) && p_serialize_1_.siblings.isEmpty()) + { + return new JsonPrimitive(((ChatComponentText)p_serialize_1_).getText()); + } + else + { + JsonObject jsonobject = new JsonObject(); + + if (p_serialize_1_.style != null && !p_serialize_1_.style.isEmpty()) + { + this.serializeChatStyle(p_serialize_1_.style, jsonobject, p_serialize_3_); + } + + if (!p_serialize_1_.siblings.isEmpty()) + { + JsonArray jsonarray = new JsonArray(); + + for (ChatComponent ichatcomponent : p_serialize_1_.siblings) + { + jsonarray.add(this.serialize((ChatComponent)ichatcomponent, ichatcomponent.getClass(), p_serialize_3_)); + } + + jsonobject.add("extra", jsonarray); + } + + if (p_serialize_1_ instanceof ChatComponentText) + { + jsonobject.addProperty("text", ((ChatComponentText)p_serialize_1_).getText()); + } + else if (p_serialize_1_ instanceof ChatComponentTranslation) + { + ChatComponentTranslation chatcomponenttranslation = (ChatComponentTranslation)p_serialize_1_; + jsonobject.addProperty("translate", chatcomponenttranslation.getKey()); + + if (chatcomponenttranslation.getFormatArgs() != null && chatcomponenttranslation.getFormatArgs().length > 0) + { + JsonArray jsonarray1 = new JsonArray(); + + for (Object object : chatcomponenttranslation.getFormatArgs()) + { + if (object instanceof ChatComponent) + { + jsonarray1.add(this.serialize((ChatComponent)((ChatComponent)object), object.getClass(), p_serialize_3_)); + } + else + { + jsonarray1.add(new JsonPrimitive(String.valueOf(object))); + } + } + + jsonobject.add("with", jsonarray1); + } + } + else if (p_serialize_1_ instanceof ChatComponentScore) + { + ChatComponentScore chatcomponentscore = (ChatComponentScore)p_serialize_1_; + JsonObject jsonobject1 = new JsonObject(); + jsonobject1.addProperty("name", chatcomponentscore.getName()); + jsonobject1.addProperty("objective", chatcomponentscore.getObjective()); + jsonobject1.addProperty("value", chatcomponentscore.getValue()); + jsonobject.add("score", jsonobject1); + } + else + { + if (!(p_serialize_1_ instanceof ChatComponentSelector)) + { + throw new IllegalArgumentException("Don\'t know how to serialize " + p_serialize_1_ + " as a Component"); + } + + ChatComponentSelector chatcomponentselector = (ChatComponentSelector)p_serialize_1_; + jsonobject.addProperty("selector", chatcomponentselector.getSelector()); + } + + return jsonobject; + } + } + + public static String componentToJson(ChatComponent component) + { + return GSON.toJson((Object)component); + } + + public static ChatComponent jsonToComponent(String json) + { + return (ChatComponent)GSON.fromJson(json, ChatComponent.class); + } + + static + { + GsonBuilder gsonbuilder = new GsonBuilder(); + gsonbuilder.registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer()); + gsonbuilder.registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()); + gsonbuilder.registerTypeAdapterFactory(new EnumTypeAdapterFactory()); + GSON = gsonbuilder.create(); + } + } +} diff --git a/proxy/src/main/java/proxy/util/ChatComponentScore.java b/proxy/src/main/java/proxy/util/ChatComponentScore.java new file mode 100755 index 0000000..426de0b --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatComponentScore.java @@ -0,0 +1,32 @@ +package proxy.util; + +public class ChatComponentScore extends ChatComponent { + private final String name; + private final String objective; + private String value = ""; + + public ChatComponentScore(String nameIn, String objectiveIn) { + this.name = nameIn; + this.objective = objectiveIn; + } + + public String getName() { + return this.name; + } + + public String getObjective() { + return this.objective; + } + + public void setValue(String valueIn) { + this.value = valueIn; + } + + public String getValue() { + return this.value; + } + + public String toString() { + return this.value; + } +} diff --git a/proxy/src/main/java/proxy/util/ChatComponentSelector.java b/proxy/src/main/java/proxy/util/ChatComponentSelector.java new file mode 100755 index 0000000..49df6a5 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatComponentSelector.java @@ -0,0 +1,17 @@ +package proxy.util; + +public class ChatComponentSelector extends ChatComponent { + private final String selector; + + public ChatComponentSelector(String selectorIn) { + this.selector = selectorIn; + } + + public String getSelector() { + return this.selector; + } + + public String toString() { + return this.selector; + } +} diff --git a/proxy/src/main/java/proxy/util/ChatComponentText.java b/proxy/src/main/java/proxy/util/ChatComponentText.java new file mode 100755 index 0000000..1836b65 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatComponentText.java @@ -0,0 +1,17 @@ +package proxy.util; + +public class ChatComponentText extends ChatComponent { + private final String text; + + public ChatComponentText(String msg) { + this.text = msg; + } + + public String getText() { + return this.text; + } + + public String toString() { + return this.text; + } +} diff --git a/proxy/src/main/java/proxy/util/ChatComponentTranslation.java b/proxy/src/main/java/proxy/util/ChatComponentTranslation.java new file mode 100755 index 0000000..cc6f628 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatComponentTranslation.java @@ -0,0 +1,27 @@ +package proxy.util; + +public class ChatComponentTranslation extends ChatComponent { + private final String key; + private final Object[] formatArgs; + + public ChatComponentTranslation(String translationKey, Object... args) { + this.key = translationKey; + this.formatArgs = args; + } + + public String getKey() { + return this.key; + } + + public Object[] getFormatArgs() { + return this.formatArgs; + } + + public String toString() { + StringBuilder sb = new StringBuilder(this.key); + for(Object arg : this.formatArgs) { + sb.append(' ').append(arg); + } + return sb.toString(); + } +} diff --git a/proxy/src/main/java/proxy/util/ChatStyle.java b/proxy/src/main/java/proxy/util/ChatStyle.java new file mode 100755 index 0000000..05627ce --- /dev/null +++ b/proxy/src/main/java/proxy/util/ChatStyle.java @@ -0,0 +1,189 @@ +package proxy.util; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; + +public class ChatStyle +{ + private ChatColor color; + private Boolean bold; + private Boolean italic; + private Boolean underlined; + private Boolean strikethrough; + private Boolean obfuscated; + private ClickEvent chatClickEvent; + private HoverEvent chatHoverEvent; + private String insertion; + + public boolean isEmpty() + { + return this.bold == null && this.italic == null && this.strikethrough == null && this.underlined == null && this.obfuscated == null && this.color == null && this.chatClickEvent == null && this.chatHoverEvent == null; + } + + public static class Serializer implements JsonDeserializer, JsonSerializer + { + public ChatStyle deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException + { + if (p_deserialize_1_.isJsonObject()) + { + ChatStyle chatstyle = new ChatStyle(); + JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); + + if (jsonobject == null) + { + return null; + } + else + { + if (jsonobject.has("bold")) + { + chatstyle.bold = Boolean.valueOf(jsonobject.get("bold").getAsBoolean()); + } + + if (jsonobject.has("italic")) + { + chatstyle.italic = Boolean.valueOf(jsonobject.get("italic").getAsBoolean()); + } + + if (jsonobject.has("underlined")) + { + chatstyle.underlined = Boolean.valueOf(jsonobject.get("underlined").getAsBoolean()); + } + + if (jsonobject.has("strikethrough")) + { + chatstyle.strikethrough = Boolean.valueOf(jsonobject.get("strikethrough").getAsBoolean()); + } + + if (jsonobject.has("obfuscated")) + { + chatstyle.obfuscated = Boolean.valueOf(jsonobject.get("obfuscated").getAsBoolean()); + } + + if (jsonobject.has("color")) + { + chatstyle.color = (ChatColor)p_deserialize_3_.deserialize(jsonobject.get("color"), ChatColor.class); + } + + if (jsonobject.has("insertion")) + { + chatstyle.insertion = jsonobject.get("insertion").getAsString(); + } + + if (jsonobject.has("clickEvent")) + { + JsonObject jsonobject1 = jsonobject.getAsJsonObject("clickEvent"); + + if (jsonobject1 != null) + { + JsonPrimitive jsonprimitive = jsonobject1.getAsJsonPrimitive("action"); + ClickEvent.Action clickevent$action = jsonprimitive == null ? null : ClickEvent.Action.getValueByCanonicalName(jsonprimitive.getAsString()); + JsonPrimitive jsonprimitive1 = jsonobject1.getAsJsonPrimitive("value"); + String s = jsonprimitive1 == null ? null : jsonprimitive1.getAsString(); + + if (clickevent$action != null && s != null && clickevent$action.shouldAllowInChat()) + { + chatstyle.chatClickEvent = new ClickEvent(clickevent$action, s); + } + } + } + + if (jsonobject.has("hoverEvent")) + { + JsonObject jsonobject2 = jsonobject.getAsJsonObject("hoverEvent"); + + if (jsonobject2 != null) + { + JsonPrimitive jsonprimitive2 = jsonobject2.getAsJsonPrimitive("action"); + HoverEvent.Action hoverevent$action = jsonprimitive2 == null ? null : HoverEvent.Action.getValueByCanonicalName(jsonprimitive2.getAsString()); + ChatComponent ichatcomponent = (ChatComponent)p_deserialize_3_.deserialize(jsonobject2.get("value"), ChatComponent.class); + + if (hoverevent$action != null && ichatcomponent != null && hoverevent$action.shouldAllowInChat()) + { + chatstyle.chatHoverEvent = new HoverEvent(hoverevent$action, ichatcomponent); + } + } + } + + return chatstyle; + } + } + else + { + return null; + } + } + + public JsonElement serialize(ChatStyle p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) + { + if (p_serialize_1_.isEmpty()) + { + return null; + } + else + { + JsonObject jsonobject = new JsonObject(); + + if (p_serialize_1_.bold != null) + { + jsonobject.addProperty("bold", p_serialize_1_.bold); + } + + if (p_serialize_1_.italic != null) + { + jsonobject.addProperty("italic", p_serialize_1_.italic); + } + + if (p_serialize_1_.underlined != null) + { + jsonobject.addProperty("underlined", p_serialize_1_.underlined); + } + + if (p_serialize_1_.strikethrough != null) + { + jsonobject.addProperty("strikethrough", p_serialize_1_.strikethrough); + } + + if (p_serialize_1_.obfuscated != null) + { + jsonobject.addProperty("obfuscated", p_serialize_1_.obfuscated); + } + + if (p_serialize_1_.color != null) + { + jsonobject.add("color", p_serialize_3_.serialize(p_serialize_1_.color)); + } + + if (p_serialize_1_.insertion != null) + { + jsonobject.add("insertion", p_serialize_3_.serialize(p_serialize_1_.insertion)); + } + + if (p_serialize_1_.chatClickEvent != null) + { + JsonObject jsonobject1 = new JsonObject(); + jsonobject1.addProperty("action", p_serialize_1_.chatClickEvent.getAction().getCanonicalName()); + jsonobject1.addProperty("value", p_serialize_1_.chatClickEvent.getValue()); + jsonobject.add("clickEvent", jsonobject1); + } + + if (p_serialize_1_.chatHoverEvent != null) + { + JsonObject jsonobject2 = new JsonObject(); + jsonobject2.addProperty("action", p_serialize_1_.chatHoverEvent.getAction().getCanonicalName()); + jsonobject2.add("value", p_serialize_3_.serialize(p_serialize_1_.chatHoverEvent.getValue())); + jsonobject.add("hoverEvent", jsonobject2); + } + + return jsonobject; + } + } + } +} diff --git a/proxy/src/main/java/proxy/util/ClickEvent.java b/proxy/src/main/java/proxy/util/ClickEvent.java new file mode 100755 index 0000000..48b666e --- /dev/null +++ b/proxy/src/main/java/proxy/util/ClickEvent.java @@ -0,0 +1,59 @@ +package proxy.util; + +import java.util.HashMap; +import java.util.Map; + +public class ClickEvent { + private final ClickEvent.Action action; + private final String value; + + public ClickEvent(ClickEvent.Action theAction, String theValue) { + this.action = theAction; + this.value = theValue; + } + + public ClickEvent.Action getAction() { + return this.action; + } + + public String getValue() { + return this.value; + } + + public static enum Action { + OPEN_URL("open_url", true), + OPEN_FILE("open_file", false), + RUN_COMMAND("run_command", true), + TWITCH_USER_INFO("twitch_user_info", false), + SUGGEST_COMMAND("suggest_command", true), + CHANGE_PAGE("change_page", true); + + private static final Map nameMapping = new HashMap(); + + private final boolean allowedInChat; + private final String canonicalName; + + private Action(String canonicalNameIn, boolean allowedInChatIn) { + this.canonicalName = canonicalNameIn; + this.allowedInChat = allowedInChatIn; + } + + public boolean shouldAllowInChat() { + return this.allowedInChat; + } + + public String getCanonicalName() { + return this.canonicalName; + } + + public static ClickEvent.Action getValueByCanonicalName(String canonicalNameIn) { + return nameMapping.get(canonicalNameIn); + } + + static { + for(ClickEvent.Action clickevent$action : values()) { + nameMapping.put(clickevent$action.getCanonicalName(), clickevent$action); + } + } + } +} diff --git a/proxy/src/main/java/proxy/util/DataWatcher.java b/proxy/src/main/java/proxy/util/DataWatcher.java new file mode 100755 index 0000000..3d7d238 --- /dev/null +++ b/proxy/src/main/java/proxy/util/DataWatcher.java @@ -0,0 +1,201 @@ +package proxy.util; + +import java.io.IOException; +import java.util.List; +import com.google.common.collect.Lists; + +import proxy.network.PacketBuffer; + +public class DataWatcher +{ + private static class Vec3f { + protected final float x; + protected final float y; + protected final float z; + + public Vec3f(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public float getX() { + return this.x; + } + + public float getY() { + return this.y; + } + + public float getZ() { + return this.z; + } + } + + public static void writeWatchedListToPacketBuffer(List objectsList, PacketBuffer buffer) throws IOException + { + if (objectsList != null) + { + for (DataWatcher.WatchableObject datawatcher$watchableobject : objectsList) + { + writeWatchableObjectToPacketBuffer(buffer, datawatcher$watchableobject); + } + } + + buffer.writeByte(127); + } + + private static void writeWatchableObjectToPacketBuffer(PacketBuffer buffer, DataWatcher.WatchableObject object) throws IOException + { + int i = (object.getObjectType() << 5 | object.getDataValueId() & 31) & 255; + buffer.writeByte(i); + + switch (object.getObjectType()) + { + case 0: + buffer.writeByte(((Byte)object.getObject()).byteValue()); + break; + + case 1: + buffer.writeShort(((Short)object.getObject()).shortValue()); + break; + + case 2: + buffer.writeInt(((Integer)object.getObject()).intValue()); + break; + + case 3: + buffer.writeFloat(((Float)object.getObject()).floatValue()); + break; + + case 4: + buffer.writeString((String)object.getObject()); + break; + + case 5: + ItemStack itemstack = (ItemStack)object.getObject(); + buffer.writeItemStackToBuffer(itemstack); + break; + + case 6: + BlockPos blockpos = (BlockPos)object.getObject(); + buffer.writeInt(blockpos.getX()); + buffer.writeInt(blockpos.getY()); + buffer.writeInt(blockpos.getZ()); + break; + + case 7: + Vec3f rotations = (Vec3f)object.getObject(); + buffer.writeFloat(rotations.getX()); + buffer.writeFloat(rotations.getY()); + buffer.writeFloat(rotations.getZ()); + } + } + + public static List readWatchedListFromPacketBuffer(PacketBuffer buffer) throws IOException + { + List list = null; + + for (int i = buffer.readByte(); i != 127; i = buffer.readByte()) + { + if (list == null) + { + list = Lists.newArrayList(); + } + + int j = (i & 224) >> 5; + int k = i & 31; + DataWatcher.WatchableObject datawatcher$watchableobject = null; + + switch (j) + { + case 0: + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Byte.valueOf(buffer.readByte())); + break; + + case 1: + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Short.valueOf(buffer.readShort())); + break; + + case 2: + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Integer.valueOf(buffer.readInt())); + break; + + case 3: + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Float.valueOf(buffer.readFloat())); + break; + + case 4: + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readStringFromBuffer(32767)); + break; + + case 5: + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readItemStackFromBuffer()); + break; + + case 6: + int l = buffer.readInt(); + int i1 = buffer.readInt(); + int j1 = buffer.readInt(); + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, new BlockPos(l, i1, j1)); + break; + + case 7: + float f = buffer.readFloat(); + float f1 = buffer.readFloat(); + float f2 = buffer.readFloat(); + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, new Vec3f(f, f1, f2)); + } + + list.add(datawatcher$watchableobject); + } + + return list; + } + + public static class WatchableObject + { + private final int objectType; + private final int dataValueId; + private Object watchedObject; + private boolean watched; + + public WatchableObject(int type, int id, Object object) + { + this.dataValueId = id; + this.watchedObject = object; + this.objectType = type; + this.watched = true; + } + + public int getDataValueId() + { + return this.dataValueId; + } + + public void setObject(Object object) + { + this.watchedObject = object; + } + + public Object getObject() + { + return this.watchedObject; + } + + public int getObjectType() + { + return this.objectType; + } + + public boolean isWatched() + { + return this.watched; + } + + public void setWatched(boolean watched) + { + this.watched = watched; + } + } +} diff --git a/proxy/src/main/java/proxy/util/EnumTypeAdapterFactory.java b/proxy/src/main/java/proxy/util/EnumTypeAdapterFactory.java new file mode 100755 index 0000000..505a663 --- /dev/null +++ b/proxy/src/main/java/proxy/util/EnumTypeAdapterFactory.java @@ -0,0 +1,67 @@ +package proxy.util; + +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class EnumTypeAdapterFactory implements TypeAdapterFactory +{ + public TypeAdapter create(Gson gson, TypeToken token) + { + Class oclass = (Class)token.getRawType(); + + if (!oclass.isEnum()) + { + return null; + } + else + { + final Map map = new HashMap(); + + for (T t : oclass.getEnumConstants()) + { + map.put(this.func_151232_a(t), t); + } + + return new TypeAdapter() + { + public void write(JsonWriter p_write_1_, T p_write_2_) throws IOException + { + if (p_write_2_ == null) + { + p_write_1_.nullValue(); + } + else + { + p_write_1_.value(EnumTypeAdapterFactory.this.func_151232_a(p_write_2_)); + } + } + public T read(JsonReader p_read_1_) throws IOException + { + if (p_read_1_.peek() == JsonToken.NULL) + { + p_read_1_.nextNull(); + return (T)null; + } + else + { + return (T)map.get(p_read_1_.nextString()); + } + } + }; + } + } + + private String func_151232_a(Object p_151232_1_) + { + return p_151232_1_ instanceof Enum ? ((Enum)p_151232_1_).name().toLowerCase(Locale.US) : p_151232_1_.toString().toLowerCase(Locale.US); + } +} diff --git a/proxy/src/main/java/proxy/util/GameProfile.java b/proxy/src/main/java/proxy/util/GameProfile.java new file mode 100644 index 0000000..4cedbb2 --- /dev/null +++ b/proxy/src/main/java/proxy/util/GameProfile.java @@ -0,0 +1,64 @@ +package proxy.util; + +import java.util.UUID; + +public class GameProfile { + private final UUID id; + private final String name; + private final PropertyMap properties = new PropertyMap(); + private boolean legacy; + + public GameProfile(UUID id, String name) { + this.id = id; + this.name = name; + } + + public UUID getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public PropertyMap getProperties() { + return this.properties; + } + + public boolean equals(Object o) { + if(this == o) { + return true; + } else if(o != null && this.getClass() == o.getClass()) { + GameProfile that = (GameProfile)o; + if(this.id != null) { + if(!this.id.equals(that.id)) { + return false; + } + } else if(that.id != null) { + return false; + } + + if(this.name != null) { + if(!this.name.equals(that.name)) { + return false; + } + } else if(that.name != null) { + return false; + } + + return true; + } else { + return false; + } + } + + public int hashCode() { + int result = this.id != null?this.id.hashCode():0; + result = 31 * result + (this.name != null?this.name.hashCode():0); + return result; + } + + public boolean isLegacy() { + return this.legacy; + } +} diff --git a/proxy/src/main/java/proxy/util/HoverEvent.java b/proxy/src/main/java/proxy/util/HoverEvent.java new file mode 100755 index 0000000..d25c571 --- /dev/null +++ b/proxy/src/main/java/proxy/util/HoverEvent.java @@ -0,0 +1,57 @@ +package proxy.util; + +import java.util.HashMap; +import java.util.Map; + +public class HoverEvent { + private final HoverEvent.Action action; + private final ChatComponent value; + + public HoverEvent(HoverEvent.Action actionIn, ChatComponent valueIn) { + this.action = actionIn; + this.value = valueIn; + } + + public HoverEvent.Action getAction() { + return this.action; + } + + public ChatComponent getValue() { + return this.value; + } + + public static enum Action { + SHOW_TEXT("show_text", true), + SHOW_ACHIEVEMENT("show_achievement", true), + SHOW_ITEM("show_item", true), + SHOW_ENTITY("show_entity", true); + + private static final Map nameMapping = new HashMap(); + + private final boolean allowedInChat; + private final String canonicalName; + + private Action(String canonicalNameIn, boolean allowedInChatIn) { + this.canonicalName = canonicalNameIn; + this.allowedInChat = allowedInChatIn; + } + + public boolean shouldAllowInChat() { + return this.allowedInChat; + } + + public String getCanonicalName() { + return this.canonicalName; + } + + public static HoverEvent.Action getValueByCanonicalName(String canonicalNameIn) { + return nameMapping.get(canonicalNameIn); + } + + static { + for(HoverEvent.Action hoverevent$action : values()) { + nameMapping.put(hoverevent$action.getCanonicalName(), hoverevent$action); + } + } + } +} diff --git a/proxy/src/main/java/proxy/util/ITickable.java b/proxy/src/main/java/proxy/util/ITickable.java new file mode 100755 index 0000000..fb0b38f --- /dev/null +++ b/proxy/src/main/java/proxy/util/ITickable.java @@ -0,0 +1,8 @@ +package proxy.util; + +import proxy.network.NetworkManager; + +public interface ITickable +{ + void update(NetworkManager connection); +} diff --git a/proxy/src/main/java/proxy/util/ItemStack.java b/proxy/src/main/java/proxy/util/ItemStack.java new file mode 100755 index 0000000..ebf6ddc --- /dev/null +++ b/proxy/src/main/java/proxy/util/ItemStack.java @@ -0,0 +1,37 @@ +package proxy.util; + +import proxy.nbt.NBTTagCompound; + +public final class ItemStack { + private final short id; + private final byte size; + private final short meta; + private final NBTTagCompound tag; + + public ItemStack(short id, byte size, short meta, NBTTagCompound tag) { + this.id = id; + this.size = size; + this.meta = meta; + this.tag = tag; + } + + public ItemStack copy() { + return new ItemStack(this.id, this.size, this.meta, (NBTTagCompound)this.tag.copy()); + } + + public short getId() { + return this.id; + } + + public byte getSize() { + return this.size; + } + + public short getMeta() { + return this.meta; + } + + public NBTTagCompound getTag() { + return this.tag; + } +} diff --git a/proxy/src/main/java/proxy/util/JsonUtils.java b/proxy/src/main/java/proxy/util/JsonUtils.java new file mode 100755 index 0000000..0b02695 --- /dev/null +++ b/proxy/src/main/java/proxy/util/JsonUtils.java @@ -0,0 +1,338 @@ +package proxy.util; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSyntaxException; + +public class JsonUtils +{ + /** + * Does the given JsonObject contain a string field with the given name? + */ + public static boolean isString(JsonObject p_151205_0_, String p_151205_1_) + { + return !isJsonPrimitive(p_151205_0_, p_151205_1_) ? false : p_151205_0_.getAsJsonPrimitive(p_151205_1_).isString(); + } + + /** + * Is the given JsonElement a string? + */ + public static boolean isString(JsonElement p_151211_0_) + { + return !p_151211_0_.isJsonPrimitive() ? false : p_151211_0_.getAsJsonPrimitive().isString(); + } + + public static boolean isBoolean(JsonObject p_180199_0_, String p_180199_1_) + { + return !isJsonPrimitive(p_180199_0_, p_180199_1_) ? false : p_180199_0_.getAsJsonPrimitive(p_180199_1_).isBoolean(); + } + + /** + * Does the given JsonObject contain an array field with the given name? + */ + public static boolean isJsonArray(JsonObject p_151202_0_, String p_151202_1_) + { + return !hasField(p_151202_0_, p_151202_1_) ? false : p_151202_0_.get(p_151202_1_).isJsonArray(); + } + + /** + * Does the given JsonObject contain a field with the given name whose type is primitive (String, Java primitive, or + * Java primitive wrapper)? + */ + public static boolean isJsonPrimitive(JsonObject p_151201_0_, String p_151201_1_) + { + return !hasField(p_151201_0_, p_151201_1_) ? false : p_151201_0_.get(p_151201_1_).isJsonPrimitive(); + } + + /** + * Does the given JsonObject contain a field with the given name? + */ + public static boolean hasField(JsonObject p_151204_0_, String p_151204_1_) + { + return p_151204_0_ == null ? false : p_151204_0_.get(p_151204_1_) != null; + } + + /** + * Gets the string value of the given JsonElement. Expects the second parameter to be the name of the element's + * field if an error message needs to be thrown. + */ + public static String getString(JsonElement p_151206_0_, String p_151206_1_) + { + if (p_151206_0_.isJsonPrimitive()) + { + return p_151206_0_.getAsString(); + } + else + { + throw new JsonSyntaxException("Expected " + p_151206_1_ + " to be a string, was " + toString(p_151206_0_)); + } + } + + /** + * Gets the string value of the field on the JsonObject with the given name. + */ + public static String getString(JsonObject p_151200_0_, String p_151200_1_) + { + if (p_151200_0_.has(p_151200_1_)) + { + return getString(p_151200_0_.get(p_151200_1_), p_151200_1_); + } + else + { + throw new JsonSyntaxException("Missing " + p_151200_1_ + ", expected to find a string"); + } + } + + /** + * Gets the string value of the field on the JsonObject with the given name, or the given default value if the field + * is missing. + */ + public static String getString(JsonObject p_151219_0_, String p_151219_1_, String p_151219_2_) + { + return p_151219_0_.has(p_151219_1_) ? getString(p_151219_0_.get(p_151219_1_), p_151219_1_) : p_151219_2_; + } + + /** + * Gets the boolean value of the given JsonElement. Expects the second parameter to be the name of the element's + * field if an error message needs to be thrown. + */ + public static boolean getBoolean(JsonElement p_151216_0_, String p_151216_1_) + { + if (p_151216_0_.isJsonPrimitive()) + { + return p_151216_0_.getAsBoolean(); + } + else + { + throw new JsonSyntaxException("Expected " + p_151216_1_ + " to be a Boolean, was " + toString(p_151216_0_)); + } + } + + /** + * Gets the boolean value of the field on the JsonObject with the given name. + */ + public static boolean getBoolean(JsonObject p_151212_0_, String p_151212_1_) + { + if (p_151212_0_.has(p_151212_1_)) + { + return getBoolean(p_151212_0_.get(p_151212_1_), p_151212_1_); + } + else + { + throw new JsonSyntaxException("Missing " + p_151212_1_ + ", expected to find a Boolean"); + } + } + + /** + * Gets the boolean value of the field on the JsonObject with the given name, or the given default value if the + * field is missing. + */ + public static boolean getBoolean(JsonObject p_151209_0_, String p_151209_1_, boolean p_151209_2_) + { + return p_151209_0_.has(p_151209_1_) ? getBoolean(p_151209_0_.get(p_151209_1_), p_151209_1_) : p_151209_2_; + } + + /** + * Gets the float value of the given JsonElement. Expects the second parameter to be the name of the element's + * field if an error message needs to be thrown. + */ + public static float getFloat(JsonElement p_151220_0_, String p_151220_1_) + { + if (p_151220_0_.isJsonPrimitive() && p_151220_0_.getAsJsonPrimitive().isNumber()) + { + return p_151220_0_.getAsFloat(); + } + else + { + throw new JsonSyntaxException("Expected " + p_151220_1_ + " to be a Float, was " + toString(p_151220_0_)); + } + } + + /** + * Gets the float value of the field on the JsonObject with the given name. + */ + public static float getFloat(JsonObject p_151217_0_, String p_151217_1_) + { + if (p_151217_0_.has(p_151217_1_)) + { + return getFloat(p_151217_0_.get(p_151217_1_), p_151217_1_); + } + else + { + throw new JsonSyntaxException("Missing " + p_151217_1_ + ", expected to find a Float"); + } + } + + /** + * Gets the float value of the field on the JsonObject with the given name, or the given default value if the field + * is missing. + */ + public static float getFloat(JsonObject p_151221_0_, String p_151221_1_, float p_151221_2_) + { + return p_151221_0_.has(p_151221_1_) ? getFloat(p_151221_0_.get(p_151221_1_), p_151221_1_) : p_151221_2_; + } + + /** + * Gets the integer value of the given JsonElement. Expects the second parameter to be the name of the element's + * field if an error message needs to be thrown. + */ + public static int getInt(JsonElement p_151215_0_, String p_151215_1_) + { + if (p_151215_0_.isJsonPrimitive() && p_151215_0_.getAsJsonPrimitive().isNumber()) + { + return p_151215_0_.getAsInt(); + } + else + { + throw new JsonSyntaxException("Expected " + p_151215_1_ + " to be a Int, was " + toString(p_151215_0_)); + } + } + + /** + * Gets the integer value of the field on the JsonObject with the given name. + */ + public static int getInt(JsonObject p_151203_0_, String p_151203_1_) + { + if (p_151203_0_.has(p_151203_1_)) + { + return getInt(p_151203_0_.get(p_151203_1_), p_151203_1_); + } + else + { + throw new JsonSyntaxException("Missing " + p_151203_1_ + ", expected to find a Int"); + } + } + + /** + * Gets the integer value of the field on the JsonObject with the given name, or the given default value if the + * field is missing. + */ + public static int getInt(JsonObject p_151208_0_, String p_151208_1_, int p_151208_2_) + { + return p_151208_0_.has(p_151208_1_) ? getInt(p_151208_0_.get(p_151208_1_), p_151208_1_) : p_151208_2_; + } + + /** + * Gets the given JsonElement as a JsonObject. Expects the second parameter to be the name of the element's field + * if an error message needs to be thrown. + */ + public static JsonObject getJsonObject(JsonElement p_151210_0_, String p_151210_1_) + { + if (p_151210_0_.isJsonObject()) + { + return p_151210_0_.getAsJsonObject(); + } + else + { + throw new JsonSyntaxException("Expected " + p_151210_1_ + " to be a JsonObject, was " + toString(p_151210_0_)); + } + } + + public static JsonObject getJsonObject(JsonObject base, String key) + { + if (base.has(key)) + { + return getJsonObject(base.get(key), key); + } + else + { + throw new JsonSyntaxException("Missing " + key + ", expected to find a JsonObject"); + } + } + + /** + * Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is + * missing. + */ + public static JsonObject getJsonObject(JsonObject p_151218_0_, String p_151218_1_, JsonObject p_151218_2_) + { + return p_151218_0_.has(p_151218_1_) ? getJsonObject(p_151218_0_.get(p_151218_1_), p_151218_1_) : p_151218_2_; + } + + /** + * Gets the given JsonElement as a JsonArray. Expects the second parameter to be the name of the element's field if + * an error message needs to be thrown. + */ + public static JsonArray getJsonArray(JsonElement p_151207_0_, String p_151207_1_) + { + if (p_151207_0_.isJsonArray()) + { + return p_151207_0_.getAsJsonArray(); + } + else + { + throw new JsonSyntaxException("Expected " + p_151207_1_ + " to be a JsonArray, was " + toString(p_151207_0_)); + } + } + + /** + * Gets the JsonArray field on the JsonObject with the given name. + */ + public static JsonArray getJsonArray(JsonObject p_151214_0_, String p_151214_1_) + { + if (p_151214_0_.has(p_151214_1_)) + { + return getJsonArray(p_151214_0_.get(p_151214_1_), p_151214_1_); + } + else + { + throw new JsonSyntaxException("Missing " + p_151214_1_ + ", expected to find a JsonArray"); + } + } + + /** + * Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is + * missing. + */ + public static JsonArray getJsonArray(JsonObject p_151213_0_, String p_151213_1_, JsonArray p_151213_2_) + { + return p_151213_0_.has(p_151213_1_) ? getJsonArray(p_151213_0_.get(p_151213_1_), p_151213_1_) : p_151213_2_; + } + + /** + * Gets a human-readable description of the given JsonElement's type. For example: "a number (4)" + */ + public static String toString(JsonElement p_151222_0_) + { + String s = String.valueOf(p_151222_0_); + s = s.length() > 10 ? s.substring(0, 10) + "..." : s; + + if (p_151222_0_ == null) + { + return "null (missing)"; + } + else if (p_151222_0_.isJsonNull()) + { + return "null (json)"; + } + else if (p_151222_0_.isJsonArray()) + { + return "an array (" + s + ")"; + } + else if (p_151222_0_.isJsonObject()) + { + return "an object (" + s + ")"; + } + else + { + if (p_151222_0_.isJsonPrimitive()) + { + JsonPrimitive jsonprimitive = p_151222_0_.getAsJsonPrimitive(); + + if (jsonprimitive.isNumber()) + { + return "a number (" + s + ")"; + } + + if (jsonprimitive.isBoolean()) + { + return "a boolean (" + s + ")"; + } + } + + return s; + } + } +} diff --git a/proxy/src/main/java/proxy/util/LazyLoadBase.java b/proxy/src/main/java/proxy/util/LazyLoadBase.java new file mode 100755 index 0000000..e3f1093 --- /dev/null +++ b/proxy/src/main/java/proxy/util/LazyLoadBase.java @@ -0,0 +1,17 @@ +package proxy.util; + +public abstract class LazyLoadBase { + private T value; + private boolean isLoaded = false; + + public T getValue() { + if(!this.isLoaded) { + this.isLoaded = true; + this.value = this.load(); + } + + return this.value; + } + + protected abstract T load(); +} diff --git a/proxy/src/main/java/proxy/util/Log.java b/proxy/src/main/java/proxy/util/Log.java new file mode 100644 index 0000000..1505fbe --- /dev/null +++ b/proxy/src/main/java/proxy/util/Log.java @@ -0,0 +1,53 @@ +package proxy.util; + +public class Log { + private static final boolean DEBUG = System.getProperty("log.debug") != null; + + private static void log(String prefix, String msg) { + System.err.printf("[%s|%s] %s\n", prefix, Thread.currentThread().getName(), msg); + } + + public static void error(String msg) { + log("error", msg); + } + + public static void error(String fmt, Object ... args) { + log("error", String.format(fmt, args)); + } + + public static void error(Throwable t, String msg) { + log("error", msg); + t.printStackTrace(System.err); + } + + public static void error(Throwable t, String fmt, Object ... args) { + log("error", String.format(fmt, args)); + t.printStackTrace(System.err); + } + + public static void warn(String msg) { + log("warn", msg); + } + + public static void warn(String fmt, Object ... args) { + log("warn", String.format(fmt, args)); + } + + public static void info(String msg) { + log("info", msg); + } + + public static void info(String fmt, Object ... args) { + log("info", String.format(fmt, args)); + } + + public static void debug(String msg) { + if(DEBUG) + log("debug", msg); + } + + public static void debug(String fmt, Object ... args) { + if(DEBUG) + log("debug", String.format(fmt, args)); + } +} diff --git a/proxy/src/main/java/proxy/util/MathHelper.java b/proxy/src/main/java/proxy/util/MathHelper.java new file mode 100755 index 0000000..1093802 --- /dev/null +++ b/proxy/src/main/java/proxy/util/MathHelper.java @@ -0,0 +1,559 @@ +package proxy.util; + +import java.util.Random; +import java.util.UUID; + +public class MathHelper +{ + public static final float SQRT_2 = sqrt_float(2.0F); + + /** + * A table of sin values computed from 0 (inclusive) to 2*pi (exclusive), with steps of 2*PI / 65536. + */ + private static final float[] SIN_TABLE = new float[65536]; + + /** + * Though it looks like an array, this is really more like a mapping. Key (index of this array) is the upper 5 bits + * of the result of multiplying a 32-bit unsigned integer by the B(2, 5) De Bruijn sequence 0x077CB531. Value + * (value stored in the array) is the unique index (from the right) of the leftmost one-bit in a 32-bit unsigned + * integer that can cause the upper 5 bits to get that value. Used for highly optimized "find the log-base-2 of + * this number" calculations. + */ + private static final int[] multiplyDeBruijnBitPosition; + private static final double field_181163_d; + private static final double[] field_181164_e; + private static final double[] field_181165_f; + + /** + * sin looked up in a table + */ + public static float sin(float p_76126_0_) + { + return SIN_TABLE[(int)(p_76126_0_ * 10430.378F) & 65535]; + } + + /** + * cos looked up in the sin table with the appropriate offset + */ + public static float cos(float value) + { + return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535]; + } + + public static float sqrt_float(float value) + { + return (float)Math.sqrt((double)value); + } + + public static float sqrt_double(double value) + { + return (float)Math.sqrt(value); + } + + /** + * Returns the greatest integer less than or equal to the float argument + */ + public static int floor_float(float value) + { + int i = (int)value; + return value < (float)i ? i - 1 : i; + } + + /** + * returns par0 cast as an int, and no greater than Integer.MAX_VALUE-1024 + */ + public static int truncateDoubleToInt(double value) + { + return (int)(value + 1024.0D) - 1024; + } + + /** + * Returns the greatest integer less than or equal to the double argument + */ + public static int floor_double(double value) + { + int i = (int)value; + return value < (double)i ? i - 1 : i; + } + + /** + * Long version of floor_double + */ + public static long floor_double_long(double value) + { + long i = (long)value; + return value < (double)i ? i - 1L : i; + } + + public static int func_154353_e(double value) + { + return (int)(value >= 0.0D ? value : -value + 1.0D); + } + + public static float abs(float value) + { + return value >= 0.0F ? value : -value; + } + + /** + * Returns the unsigned value of an int. + */ + public static int abs_int(int value) + { + return value >= 0 ? value : -value; + } + + public static int ceiling_float_int(float value) + { + int i = (int)value; + return value > (float)i ? i + 1 : i; + } + + public static int ceiling_double_int(double value) + { + int i = (int)value; + return value > (double)i ? i + 1 : i; + } + + /** + * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and + * third parameters. + */ + public static int clamp_int(int num, int min, int max) + { + return num < min ? min : (num > max ? max : num); + } + + /** + * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and + * third parameters + */ + public static float clamp_float(float num, float min, float max) + { + return num < min ? min : (num > max ? max : num); + } + + public static double clamp_double(double num, double min, double max) + { + return num < min ? min : (num > max ? max : num); + } + + public static double denormalizeClamp(double lowerBnd, double upperBnd, double slide) + { + return slide < 0.0D ? lowerBnd : (slide > 1.0D ? upperBnd : lowerBnd + (upperBnd - lowerBnd) * slide); + } + + /** + * Maximum of the absolute value of two numbers. + */ + public static double abs_max(double p_76132_0_, double p_76132_2_) + { + if (p_76132_0_ < 0.0D) + { + p_76132_0_ = -p_76132_0_; + } + + if (p_76132_2_ < 0.0D) + { + p_76132_2_ = -p_76132_2_; + } + + return p_76132_0_ > p_76132_2_ ? p_76132_0_ : p_76132_2_; + } + + /** + * Buckets an integer with specifed bucket sizes. Args: i, bucketSize + */ + public static int bucketInt(int p_76137_0_, int p_76137_1_) + { + return p_76137_0_ < 0 ? -((-p_76137_0_ - 1) / p_76137_1_) - 1 : p_76137_0_ / p_76137_1_; + } + + public static int getRandomIntegerInRange(Random p_76136_0_, int p_76136_1_, int p_76136_2_) + { + return p_76136_1_ >= p_76136_2_ ? p_76136_1_ : p_76136_0_.nextInt(p_76136_2_ - p_76136_1_ + 1) + p_76136_1_; + } + + public static float randomFloatClamp(Random p_151240_0_, float p_151240_1_, float p_151240_2_) + { + return p_151240_1_ >= p_151240_2_ ? p_151240_1_ : p_151240_0_.nextFloat() * (p_151240_2_ - p_151240_1_) + p_151240_1_; + } + + public static double getRandomDoubleInRange(Random p_82716_0_, double p_82716_1_, double p_82716_3_) + { + return p_82716_1_ >= p_82716_3_ ? p_82716_1_ : p_82716_0_.nextDouble() * (p_82716_3_ - p_82716_1_) + p_82716_1_; + } + + public static double average(long[] values) + { + long i = 0L; + + for (long j : values) + { + i += j; + } + + return (double)i / (double)values.length; + } + + public static boolean epsilonEquals(float p_180185_0_, float p_180185_1_) + { + return abs(p_180185_1_ - p_180185_0_) < 1.0E-5F; + } + + public static int normalizeAngle(int p_180184_0_, int p_180184_1_) + { + return (p_180184_0_ % p_180184_1_ + p_180184_1_) % p_180184_1_; + } + + /** + * the angle is reduced to an angle between -180 and +180 by mod, and a 360 check + */ + public static float wrapAngleTo180_float(float value) + { + value = value % 360.0F; + + if (value >= 180.0F) + { + value -= 360.0F; + } + + if (value < -180.0F) + { + value += 360.0F; + } + + return value; + } + + /** + * the angle is reduced to an angle between -180 and +180 by mod, and a 360 check + */ + public static double wrapAngleTo180_double(double value) + { + value = value % 360.0D; + + if (value >= 180.0D) + { + value -= 360.0D; + } + + if (value < -180.0D) + { + value += 360.0D; + } + + return value; + } + + /** + * parses the string as integer or returns the second parameter if it fails + */ + public static int parseIntWithDefault(String p_82715_0_, int p_82715_1_) + { + try + { + return Integer.parseInt(p_82715_0_); + } + catch (Throwable var3) + { + return p_82715_1_; + } + } + + /** + * parses the string as integer or returns the second parameter if it fails. this value is capped to par2 + */ + public static int parseIntWithDefaultAndMax(String p_82714_0_, int p_82714_1_, int p_82714_2_) + { + return Math.max(p_82714_2_, parseIntWithDefault(p_82714_0_, p_82714_1_)); + } + + /** + * parses the string as double or returns the second parameter if it fails. + */ + public static double parseDoubleWithDefault(String p_82712_0_, double p_82712_1_) + { + try + { + return Double.parseDouble(p_82712_0_); + } + catch (Throwable var4) + { + return p_82712_1_; + } + } + + public static double parseDoubleWithDefaultAndMax(String p_82713_0_, double p_82713_1_, double p_82713_3_) + { + return Math.max(p_82713_3_, parseDoubleWithDefault(p_82713_0_, p_82713_1_)); + } + + /** + * Returns the input value rounded up to the next highest power of two. + */ + public static int roundUpToPowerOfTwo(int value) + { + int i = value - 1; + i = i | i >> 1; + i = i | i >> 2; + i = i | i >> 4; + i = i | i >> 8; + i = i | i >> 16; + return i + 1; + } + + /** + * Is the given value a power of two? (1, 2, 4, 8, 16, ...) + */ + private static boolean isPowerOfTwo(int value) + { + return value != 0 && (value & value - 1) == 0; + } + + /** + * Uses a B(2, 5) De Bruijn sequence and a lookup table to efficiently calculate the log-base-two of the given + * value. Optimized for cases where the input value is a power-of-two. If the input value is not a power-of-two, + * then subtract 1 from the return value. + */ + private static int calculateLogBaseTwoDeBruijn(int value) + { + value = isPowerOfTwo(value) ? value : roundUpToPowerOfTwo(value); + return multiplyDeBruijnBitPosition[(int)((long)value * 125613361L >> 27) & 31]; + } + + /** + * Efficiently calculates the floor of the base-2 log of an integer value. This is effectively the index of the + * highest bit that is set. For example, if the number in binary is 0...100101, this will return 5. + */ + public static int calculateLogBaseTwo(int value) + { + return calculateLogBaseTwoDeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1); + } + + public static int roundUp(int p_154354_0_, int p_154354_1_) + { + if (p_154354_1_ == 0) + { + return 0; + } + else if (p_154354_0_ == 0) + { + return p_154354_1_; + } + else + { + if (p_154354_0_ < 0) + { + p_154354_1_ *= -1; + } + + int i = p_154354_0_ % p_154354_1_; + return i == 0 ? p_154354_0_ : p_154354_0_ + p_154354_1_ - i; + } + } + + public static int func_180183_b(float p_180183_0_, float p_180183_1_, float p_180183_2_) + { + return func_180181_b(floor_float(p_180183_0_ * 255.0F), floor_float(p_180183_1_ * 255.0F), floor_float(p_180183_2_ * 255.0F)); + } + + public static int func_180181_b(int p_180181_0_, int p_180181_1_, int p_180181_2_) + { + int lvt_3_1_ = (p_180181_0_ << 8) + p_180181_1_; + lvt_3_1_ = (lvt_3_1_ << 8) + p_180181_2_; + return lvt_3_1_; + } + + public static int func_180188_d(int p_180188_0_, int p_180188_1_) + { + int i = (p_180188_0_ & 16711680) >> 16; + int j = (p_180188_1_ & 16711680) >> 16; + int k = (p_180188_0_ & 65280) >> 8; + int l = (p_180188_1_ & 65280) >> 8; + int i1 = (p_180188_0_ & 255) >> 0; + int j1 = (p_180188_1_ & 255) >> 0; + int k1 = (int)((float)i * (float)j / 255.0F); + int l1 = (int)((float)k * (float)l / 255.0F); + int i2 = (int)((float)i1 * (float)j1 / 255.0F); + return p_180188_0_ & -16777216 | k1 << 16 | l1 << 8 | i2; + } + + public static double func_181162_h(double p_181162_0_) + { + return p_181162_0_ - Math.floor(p_181162_0_); + } + + public static long getCoordinateRandom(int x, int y, int z) + { + long i = (long)(x * 3129871) ^ (long)z * 116129781L ^ (long)y; + i = i * i * 42317861L + i * 11L; + return i; + } + + public static UUID getRandomUuid(Random rand) + { + long i = rand.nextLong() & -61441L | 16384L; + long j = rand.nextLong() & 4611686018427387903L | Long.MIN_VALUE; + return new UUID(i, j); + } + + public static double func_181160_c(double p_181160_0_, double p_181160_2_, double p_181160_4_) + { + return (p_181160_0_ - p_181160_2_) / (p_181160_4_ - p_181160_2_); + } + + public static double atan2(double p_181159_0_, double p_181159_2_) + { + double d0 = p_181159_2_ * p_181159_2_ + p_181159_0_ * p_181159_0_; + + if (Double.isNaN(d0)) + { + return Double.NaN; + } + else + { + boolean flag = p_181159_0_ < 0.0D; + + if (flag) + { + p_181159_0_ = -p_181159_0_; + } + + boolean flag1 = p_181159_2_ < 0.0D; + + if (flag1) + { + p_181159_2_ = -p_181159_2_; + } + + boolean flag2 = p_181159_0_ > p_181159_2_; + + if (flag2) + { + double d1 = p_181159_2_; + p_181159_2_ = p_181159_0_; + p_181159_0_ = d1; + } + + double d9 = func_181161_i(d0); + p_181159_2_ = p_181159_2_ * d9; + p_181159_0_ = p_181159_0_ * d9; + double d2 = field_181163_d + p_181159_0_; + int i = (int)Double.doubleToRawLongBits(d2); + double d3 = field_181164_e[i]; + double d4 = field_181165_f[i]; + double d5 = d2 - field_181163_d; + double d6 = p_181159_0_ * d4 - p_181159_2_ * d5; + double d7 = (6.0D + d6 * d6) * d6 * 0.16666666666666666D; + double d8 = d3 + d7; + + if (flag2) + { + d8 = (Math.PI / 2D) - d8; + } + + if (flag1) + { + d8 = Math.PI - d8; + } + + if (flag) + { + d8 = -d8; + } + + return d8; + } + } + + public static double func_181161_i(double p_181161_0_) + { + double d0 = 0.5D * p_181161_0_; + long i = Double.doubleToRawLongBits(p_181161_0_); + i = 6910469410427058090L - (i >> 1); + p_181161_0_ = Double.longBitsToDouble(i); + p_181161_0_ = p_181161_0_ * (1.5D - d0 * p_181161_0_ * p_181161_0_); + return p_181161_0_; + } + + public static int hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_) + { + int i = (int)(p_181758_0_ * 6.0F) % 6; + float f = p_181758_0_ * 6.0F - (float)i; + float f1 = p_181758_2_ * (1.0F - p_181758_1_); + float f2 = p_181758_2_ * (1.0F - f * p_181758_1_); + float f3 = p_181758_2_ * (1.0F - (1.0F - f) * p_181758_1_); + float f4; + float f5; + float f6; + + switch (i) + { + case 0: + f4 = p_181758_2_; + f5 = f3; + f6 = f1; + break; + + case 1: + f4 = f2; + f5 = p_181758_2_; + f6 = f1; + break; + + case 2: + f4 = f1; + f5 = p_181758_2_; + f6 = f3; + break; + + case 3: + f4 = f1; + f5 = f2; + f6 = p_181758_2_; + break; + + case 4: + f4 = f3; + f5 = f1; + f6 = p_181758_2_; + break; + + case 5: + f4 = p_181758_2_; + f5 = f1; + f6 = f2; + break; + + default: + throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + p_181758_0_ + ", " + p_181758_1_ + ", " + p_181758_2_); + } + + int j = clamp_int((int)(f4 * 255.0F), 0, 255); + int k = clamp_int((int)(f5 * 255.0F), 0, 255); + int l = clamp_int((int)(f6 * 255.0F), 0, 255); + return j << 16 | k << 8 | l; + } + + static + { + for (int i = 0; i < 65536; ++i) + { + SIN_TABLE[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D); + } + + multiplyDeBruijnBitPosition = new int[] {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; + field_181163_d = Double.longBitsToDouble(4805340802404319232L); + field_181164_e = new double[257]; + field_181165_f = new double[257]; + + for (int j = 0; j < 257; ++j) + { + double d0 = (double)j / 256.0D; + double d1 = Math.asin(d0); + field_181165_f[j] = Math.cos(d1); + field_181164_e[j] = d1; + } + } +} diff --git a/proxy/src/main/java/proxy/util/Property.java b/proxy/src/main/java/proxy/util/Property.java new file mode 100644 index 0000000..e417251 --- /dev/null +++ b/proxy/src/main/java/proxy/util/Property.java @@ -0,0 +1,33 @@ +package proxy.util; + +public class Property { + private final String name; + private final String value; + private final String signature; + + public Property(String value, String name) { + this(value, name, (String)null); + } + + public Property(String name, String value, String signature) { + this.name = name; + this.value = value; + this.signature = signature; + } + + public String getName() { + return this.name; + } + + public String getValue() { + return this.value; + } + + public String getSignature() { + return this.signature; + } + + public boolean hasSignature() { + return this.signature != null; + } +} diff --git a/proxy/src/main/java/proxy/util/PropertyMap.java b/proxy/src/main/java/proxy/util/PropertyMap.java new file mode 100644 index 0000000..7e750b2 --- /dev/null +++ b/proxy/src/main/java/proxy/util/PropertyMap.java @@ -0,0 +1,72 @@ +package proxy.util; + +import com.google.common.collect.ForwardingMultimap; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Multimap; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.util.Map.Entry; + +public class PropertyMap extends ForwardingMultimap { + private final Multimap properties = LinkedHashMultimap.create(); + + protected Multimap delegate() { + return this.properties; + } + + public static class Serializer implements JsonSerializer, JsonDeserializer { + public PropertyMap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + PropertyMap result = new PropertyMap(); + if(json instanceof JsonObject) { + JsonObject object = (JsonObject)json; + + for(Entry entry : object.entrySet()) { + if(entry.getValue() instanceof JsonArray) { + for(JsonElement element : (JsonArray)entry.getValue()) { + result.put(entry.getKey(), new Property((String)entry.getKey(), element.getAsString())); + } + } + } + } else if(json instanceof JsonArray) { + for(JsonElement element : (JsonArray)json) { + if(element instanceof JsonObject) { + JsonObject object = (JsonObject)element; + String name = object.getAsJsonPrimitive("name").getAsString(); + String value = object.getAsJsonPrimitive("value").getAsString(); + if(object.has("signature")) { + result.put(name, new Property(name, value, object.getAsJsonPrimitive("signature").getAsString())); + } else { + result.put(name, new Property(name, value)); + } + } + } + } + + return result; + } + + public JsonElement serialize(PropertyMap src, Type typeOfSrc, JsonSerializationContext context) { + JsonArray result = new JsonArray(); + + for(Property property : src.values()) { + JsonObject object = new JsonObject(); + object.addProperty("name", property.getName()); + object.addProperty("value", property.getValue()); + if(property.hasSignature()) { + object.addProperty("signature", property.getSignature()); + } + + result.add(object); + } + + return result; + } + } +} diff --git a/proxy/src/main/java/proxy/util/User.java b/proxy/src/main/java/proxy/util/User.java new file mode 100644 index 0000000..2348fdc --- /dev/null +++ b/proxy/src/main/java/proxy/util/User.java @@ -0,0 +1,48 @@ +package proxy.util; + +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +public class User { + private static final Charset UTF_8 = Charset.forName("UTF-8"); + + private final String username; + private final byte[] hash; + private final byte[] salt; + + public User(String username, byte[] hash, byte[] salt) { + this.username = username; + this.hash = hash; + this.salt = salt; + } + + public String getName() { + return this.username; + } + + public boolean checkPassword(String password) { + return MessageDigest.isEqual(hashPassword(password, this.salt), this.hash); + } + + private static byte[] hashPassword(String pass, byte[] salt) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA-512"); + digest.update(pass.getBytes(UTF_8)); + digest.update(salt); + return digest.digest(); + } + catch(NoSuchAlgorithmException e) { + Log.error("Could not generate password hash"); + return null; + } + } + + public static User createUser(String user, String pass) { + SecureRandom rand = new SecureRandom(); + byte[] salt = new byte[32]; + rand.nextBytes(salt); + return new User(user, hashPassword(pass, salt), salt); + } +}