Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Merge pull request #1313 from creeper123123321/master
Send light update before chunk packet, maybe better ByteBuf releasing…
Dieser Commit ist enthalten in:
Commit
b04acf98c7
@ -10,10 +10,12 @@ import us.myles.ViaVersion.api.protocol.Protocol;
|
|||||||
import us.myles.ViaVersion.api.remapper.ValueCreator;
|
import us.myles.ViaVersion.api.remapper.ValueCreator;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.TypeConverter;
|
import us.myles.ViaVersion.api.type.TypeConverter;
|
||||||
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
import us.myles.ViaVersion.exception.InformativeException;
|
import us.myles.ViaVersion.exception.InformativeException;
|
||||||
import us.myles.ViaVersion.packets.Direction;
|
import us.myles.ViaVersion.packets.Direction;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
import us.myles.ViaVersion.util.PipelineUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -298,8 +300,14 @@ public class PacketWrapper {
|
|||||||
*/
|
*/
|
||||||
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
||||||
if (!isCancelled()) {
|
if (!isCancelled()) {
|
||||||
|
try {
|
||||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING);
|
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING);
|
||||||
user().sendRawPacket(output, currentThread);
|
user().sendRawPacket(output, currentThread);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!PipelineUtil.containsCause(e, CancelException.class)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,8 +501,14 @@ public class PacketWrapper {
|
|||||||
*/
|
*/
|
||||||
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
||||||
if (!isCancelled()) {
|
if (!isCancelled()) {
|
||||||
|
try {
|
||||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
|
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
|
||||||
user().sendRawPacketToServer(output, currentThread);
|
user().sendRawPacketToServer(output, currentThread);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!PipelineUtil.containsCause(e, CancelException.class)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +213,7 @@ public class UserConnection {
|
|||||||
*/
|
*/
|
||||||
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
|
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
|
||||||
final ByteBuf buf = packet.alloc().buffer();
|
final ByteBuf buf = packet.alloc().buffer();
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -220,7 +221,6 @@ public class UserConnection {
|
|||||||
Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e);
|
Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e);
|
||||||
}
|
}
|
||||||
buf.writeBytes(packet);
|
buf.writeBytes(packet);
|
||||||
packet.release();
|
|
||||||
final ChannelHandlerContext context = PipelineUtil
|
final ChannelHandlerContext context = PipelineUtil
|
||||||
.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline());
|
.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline());
|
||||||
if (currentThread) {
|
if (currentThread) {
|
||||||
@ -230,6 +230,7 @@ public class UserConnection {
|
|||||||
getChannel().pipeline().fireChannelRead(buf);
|
getChannel().pipeline().fireChannelRead(buf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
channel.eventLoop().submit(new Runnable() {
|
channel.eventLoop().submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -240,6 +241,14 @@ public class UserConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// Couldn't schedule
|
||||||
|
buf.release();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
packet.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
|
try {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
@ -94,7 +95,9 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
buf.readerIndex(0);
|
buf.readerIndex(0);
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||||
output.writeBytes(buf);
|
output.writeBytes(buf);
|
||||||
|
} finally {
|
||||||
buf.release(); // release buffer
|
buf.release(); // release buffer
|
||||||
|
}
|
||||||
|
|
||||||
// Write biome data
|
// Write biome data
|
||||||
if (chunk.isBiomeData()) {
|
if (chunk.isBiomeData()) {
|
||||||
|
@ -184,8 +184,8 @@ public class WorldPackets {
|
|||||||
}
|
}
|
||||||
lightPacket.write(Type.VAR_INT, skyLightMask);
|
lightPacket.write(Type.VAR_INT, skyLightMask);
|
||||||
lightPacket.write(Type.VAR_INT, blockLightMask);
|
lightPacket.write(Type.VAR_INT, blockLightMask);
|
||||||
lightPacket.write(Type.VAR_INT, 0); //TODO find out what these two bitmasks mean
|
lightPacket.write(Type.VAR_INT, 0); // empty sky light mask
|
||||||
lightPacket.write(Type.VAR_INT, 0); //TODO
|
lightPacket.write(Type.VAR_INT, 0); // empty block light mask
|
||||||
for (ChunkSection section : chunk.getSections()) {
|
for (ChunkSection section : chunk.getSections()) {
|
||||||
if (section == null || !section.hasSkyLight()) continue;
|
if (section == null || !section.hasSkyLight()) continue;
|
||||||
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getSkyLight()).toArray(new Byte[0]));
|
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getSkyLight()).toArray(new Byte[0]));
|
||||||
@ -209,7 +209,7 @@ public class WorldPackets {
|
|||||||
entityTracker.setChunkCenterZ(chunk.getZ());
|
entityTracker.setChunkCenterZ(chunk.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
lightPacket.send(Protocol1_14To1_13_2.class, true, false);
|
lightPacket.send(Protocol1_14To1_13_2.class, true, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.NBT.write(output, chunk.getHeightMap());
|
Type.NBT.write(output, chunk.getHeightMap());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
|
try {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
@ -90,7 +91,9 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
buf.readerIndex(0);
|
buf.readerIndex(0);
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||||
output.writeBytes(buf);
|
output.writeBytes(buf);
|
||||||
|
} finally {
|
||||||
buf.release(); // release buffer
|
buf.release(); // release buffer
|
||||||
|
}
|
||||||
|
|
||||||
// Write biome data
|
// Write biome data
|
||||||
if (chunk.isBiomeData()) {
|
if (chunk.isBiomeData()) {
|
||||||
|
@ -82,6 +82,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
|
try {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
@ -95,7 +96,9 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
buf.readerIndex(0);
|
buf.readerIndex(0);
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||||
output.writeBytes(buf);
|
output.writeBytes(buf);
|
||||||
|
} finally {
|
||||||
buf.release(); // release buffer
|
buf.release(); // release buffer
|
||||||
|
}
|
||||||
|
|
||||||
// Write biome data
|
// Write biome data
|
||||||
if (chunk.isBiomeData()) {
|
if (chunk.isBiomeData()) {
|
||||||
|
@ -78,6 +78,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
|
try {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
@ -91,7 +92,9 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
buf.readerIndex(0);
|
buf.readerIndex(0);
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||||
output.writeBytes(buf);
|
output.writeBytes(buf);
|
||||||
|
} finally {
|
||||||
buf.release(); // release buffer
|
buf.release(); // release buffer
|
||||||
|
}
|
||||||
|
|
||||||
// Write biome data
|
// Write biome data
|
||||||
if (chunk.isBiomeData()) {
|
if (chunk.isBiomeData()) {
|
||||||
|
@ -17,7 +17,6 @@ import us.myles.ViaVersion.api.type.Type;
|
|||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk1_8;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
||||||
@ -163,13 +162,16 @@ public class WorldPackets {
|
|||||||
|
|
||||||
PacketWrapper output = (PacketWrapper) obj;
|
PacketWrapper output = (PacketWrapper) obj;
|
||||||
ByteBuf buffer = wrapper.user().getChannel().alloc().buffer();
|
ByteBuf buffer = wrapper.user().getChannel().alloc().buffer();
|
||||||
|
try {
|
||||||
output.setId(-1); // -1 for no writing of id
|
output.setId(-1); // -1 for no writing of id
|
||||||
output.writeToBuffer(buffer);
|
output.writeToBuffer(buffer);
|
||||||
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
|
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
|
||||||
chunkPacket.send(Protocol1_9To1_8.class, false, true);
|
chunkPacket.send(Protocol1_9To1_8.class, false, true);
|
||||||
|
} finally {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -141,6 +141,7 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
|
|||||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
|
try {
|
||||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
@ -154,7 +155,9 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
|
|||||||
buf.readerIndex(0);
|
buf.readerIndex(0);
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
|
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
|
||||||
output.writeBytes(buf);
|
output.writeBytes(buf);
|
||||||
|
} finally {
|
||||||
buf.release(); // release buffer
|
buf.release(); // release buffer
|
||||||
|
}
|
||||||
|
|
||||||
// Write biome data
|
// Write biome data
|
||||||
if (chunk.hasBiomeData()) {
|
if (chunk.hasBiomeData()) {
|
||||||
|
@ -6,7 +6,6 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -90,14 +89,15 @@ public class PipelineUtil {
|
|||||||
*
|
*
|
||||||
* @param t The throwable
|
* @param t The throwable
|
||||||
* @param c The exception to look for
|
* @param c The exception to look for
|
||||||
* @return True if the stack trace contained it as its cause.
|
* @return True if the stack trace contained it as its cause or if t is an instance of c.
|
||||||
*/
|
*/
|
||||||
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
|
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
|
||||||
while (t != null) {
|
do {
|
||||||
t = t.getCause();
|
if (t != null) {
|
||||||
if (t != null)
|
|
||||||
if (c.isAssignableFrom(t.getClass())) return true;
|
if (c.isAssignableFrom(t.getClass())) return true;
|
||||||
|
t = t.getCause();
|
||||||
}
|
}
|
||||||
|
} while (t != null);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +77,12 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
|||||||
if (needsCompress) {
|
if (needsCompress) {
|
||||||
ByteBuf old = bytebuf;
|
ByteBuf old = bytebuf;
|
||||||
bytebuf = ctx.alloc().buffer();
|
bytebuf = ctx.alloc().buffer();
|
||||||
|
try {
|
||||||
PipelineUtil.callEncode((MessageToByteEncoder) ctx.pipeline().get("compression-encoder"), ctx, old, bytebuf);
|
PipelineUtil.callEncode((MessageToByteEncoder) ctx.pipeline().get("compression-encoder"), ctx, old, bytebuf);
|
||||||
|
} finally {
|
||||||
old.release();
|
old.release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
out.add(bytebuf);
|
out.add(bytebuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +100,7 @@ public class VelocityServerHandler {
|
|||||||
|
|
||||||
user.getVelocityLock().writeLock().lock();
|
user.getVelocityLock().writeLock().lock();
|
||||||
|
|
||||||
|
try {
|
||||||
VelocityStorage storage = user.get(VelocityStorage.class);
|
VelocityStorage storage = user.get(VelocityStorage.class);
|
||||||
|
|
||||||
if (e.getServer() != null) {
|
if (e.getServer() != null) {
|
||||||
@ -192,7 +193,9 @@ public class VelocityServerHandler {
|
|||||||
setProtocolVersion.invoke(connection, version);
|
setProtocolVersion.invoke(connection, version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
user.getVelocityLock().writeLock().unlock();
|
user.getVelocityLock().writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren