13
0
geforkt von Mirrors/Velocity

Fix Minecraft 1.7 support (bad merge)

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-06-23 13:17:36 -04:00
Ursprung 68e5b64c33
Commit ae6afc8b18
3 geänderte Dateien mit 25 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -37,6 +37,7 @@ import io.netty.util.ReferenceCountUtil;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.GeneralSecurityException;
import java.util.concurrent.TimeUnit;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.logging.log4j.LogManager;
@ -207,14 +208,18 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
*/
public void closeWith(Object msg) {
if (channel.isActive()) {
if (channel.eventLoop().inEventLoop()) {
if (channel.eventLoop().inEventLoop()
&& this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
knownDisconnect = true;
channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE);
} else {
channel.eventLoop().execute(() -> {
// 1.7.x versions have a race condition with switching protocol versions, so just explicitly
// close the connection after a short while.
this.setAutoReading(false);
channel.eventLoop().schedule(() -> {
knownDisconnect = true;
channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE);
});
}, 250, TimeUnit.MILLISECONDS);
}
}
}

Datei anzeigen

@ -130,8 +130,8 @@ public class JoinGame implements MinecraftPacket {
+ ", levelType='" + levelType + '\''
+ ", viewDistance=" + viewDistance
+ ", reducedDebugInfo=" + reducedDebugInfo
+ ", dimensionRegistry='" + dimensionRegistry.toString() + '\''
+ ", dimensionInfo='" + dimensionInfo.toString() + '\''
+ ", dimensionRegistry='" + dimensionRegistry + '\''
+ ", dimensionInfo='" + dimensionInfo + '\''
+ ", previousGamemode=" + previousGamemode
+ '}';
}
@ -139,7 +139,7 @@ public class JoinGame implements MinecraftPacket {
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
this.entityId = buf.readInt();
this.gamemode = buf.readByte();
this.gamemode = buf.readUnsignedByte();
String dimensionIdentifier = null;
String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
@ -167,7 +167,9 @@ public class JoinGame implements MinecraftPacket {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
this.viewDistance = ProtocolUtils.readVarInt(buf);
}
this.reducedDebugInfo = buf.readBoolean();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
this.reducedDebugInfo = buf.readBoolean();
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
this.showRespawnScreen = buf.readBoolean();
}
@ -208,9 +210,11 @@ public class JoinGame implements MinecraftPacket {
ProtocolUtils.writeString(buf, levelType);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
ProtocolUtils.writeVarInt(buf,viewDistance);
ProtocolUtils.writeVarInt(buf, viewDistance);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
buf.writeBoolean(reducedDebugInfo);
}
buf.writeBoolean(reducedDebugInfo);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
buf.writeBoolean(showRespawnScreen);
}

Datei anzeigen

@ -1,6 +1,7 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.UuidUtils;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -47,8 +48,10 @@ public class ServerLoginSuccess implements MinecraftPacket {
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
uuid = ProtocolUtils.readUuidIntArray(buf);
} else {
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) {
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
} else {
uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32));
}
username = ProtocolUtils.readString(buf, 16);
}
@ -60,8 +63,10 @@ public class ServerLoginSuccess implements MinecraftPacket {
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
ProtocolUtils.writeUuidIntArray(buf, uuid);
} else {
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) {
ProtocolUtils.writeString(buf, uuid.toString());
} else {
ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid));
}
if (username == null) {
throw new IllegalStateException("No username specified!");