Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Preserve client settings packets
Dieser Commit ist enthalten in:
Ursprung
b79e7df039
Commit
e672f8d7cd
@ -4,11 +4,8 @@ import com.velocitypowered.proxy.VelocityServer;
|
|||||||
import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
||||||
import com.velocitypowered.proxy.data.ServerInfo;
|
import com.velocitypowered.proxy.data.ServerInfo;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.packets.Chat;
|
import com.velocitypowered.proxy.protocol.packets.*;
|
||||||
import com.velocitypowered.proxy.protocol.packets.JoinGame;
|
|
||||||
import com.velocitypowered.proxy.protocol.packets.KeepAlive;
|
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.protocol.packets.Respawn;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -58,6 +55,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (packet instanceof ClientSettings) {
|
||||||
|
player.setClientSettings((ClientSettings) packet);
|
||||||
|
// forward it on
|
||||||
|
}
|
||||||
|
|
||||||
if (packet instanceof Chat) {
|
if (packet instanceof Chat) {
|
||||||
Chat chat = (Chat) packet;
|
Chat chat = (Chat) packet;
|
||||||
if (chat.getMessage().equals("/connect")) {
|
if (chat.getMessage().equals("/connect")) {
|
||||||
@ -106,6 +108,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
player.getConnection().flush();
|
player.getConnection().flush();
|
||||||
currentDimension = joinGame.getDimension();
|
currentDimension = joinGame.getDimension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (player.getClientSettings() != null) {
|
||||||
|
player.getConnectedServer().getChannel().write(player.getClientSettings());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentDimension(int currentDimension) {
|
public void setCurrentDimension(int currentDimension) {
|
||||||
|
@ -5,6 +5,7 @@ import com.velocitypowered.proxy.data.GameProfile;
|
|||||||
import com.velocitypowered.proxy.protocol.packets.Chat;
|
import com.velocitypowered.proxy.protocol.packets.Chat;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
||||||
|
import com.velocitypowered.proxy.protocol.packets.ClientSettings;
|
||||||
import com.velocitypowered.proxy.util.ThrowableUtils;
|
import com.velocitypowered.proxy.util.ThrowableUtils;
|
||||||
import com.velocitypowered.proxy.data.ServerInfo;
|
import com.velocitypowered.proxy.data.ServerInfo;
|
||||||
import com.velocitypowered.proxy.protocol.packets.Disconnect;
|
import com.velocitypowered.proxy.protocol.packets.Disconnect;
|
||||||
@ -28,6 +29,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation {
|
|||||||
private final GameProfile profile;
|
private final GameProfile profile;
|
||||||
private final MinecraftConnection connection;
|
private final MinecraftConnection connection;
|
||||||
private ServerConnection connectedServer;
|
private ServerConnection connectedServer;
|
||||||
|
private ClientSettings clientSettings;
|
||||||
|
|
||||||
public ConnectedPlayer(GameProfile profile, MinecraftConnection connection) {
|
public ConnectedPlayer(GameProfile profile, MinecraftConnection connection) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
@ -58,6 +60,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation {
|
|||||||
return connectedServer;
|
return connectedServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientSettings getClientSettings() {
|
||||||
|
return clientSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientSettings(ClientSettings clientSettings) {
|
||||||
|
this.clientSettings = clientSettings;
|
||||||
|
}
|
||||||
|
|
||||||
public void handleConnectionException(ServerInfo info, Throwable throwable) {
|
public void handleConnectionException(ServerInfo info, Throwable throwable) {
|
||||||
String error = ThrowableUtils.briefDescription(throwable);
|
String error = ThrowableUtils.briefDescription(throwable);
|
||||||
String userMessage;
|
String userMessage;
|
||||||
|
@ -39,6 +39,9 @@ public enum StateRegistry {
|
|||||||
SERVERBOUND.register(KeepAlive.class, KeepAlive::new,
|
SERVERBOUND.register(KeepAlive.class, KeepAlive::new,
|
||||||
map(0x0C, MINECRAFT_1_12),
|
map(0x0C, MINECRAFT_1_12),
|
||||||
map(0x0B, MINECRAFT_1_12_1));
|
map(0x0B, MINECRAFT_1_12_1));
|
||||||
|
SERVERBOUND.register(ClientSettings.class, ClientSettings::new,
|
||||||
|
map(0x05, MINECRAFT_1_12),
|
||||||
|
map(0x04, MINECRAFT_1_12_1));
|
||||||
|
|
||||||
CLIENTBOUND.register(Chat.class, Chat::new,
|
CLIENTBOUND.register(Chat.class, Chat::new,
|
||||||
map(0x0F, MINECRAFT_1_12));
|
map(0x0F, MINECRAFT_1_12));
|
||||||
@ -107,10 +110,6 @@ public enum StateRegistry {
|
|||||||
|
|
||||||
for (final PacketMapping mapping : mappings) {
|
for (final PacketMapping mapping : mappings) {
|
||||||
ProtocolVersion version = this.versions.get(mapping.protocolVersion);
|
ProtocolVersion version = this.versions.get(mapping.protocolVersion);
|
||||||
if (version == null) {
|
|
||||||
version = new ProtocolVersion(mapping.protocolVersion);
|
|
||||||
this.versions.put(mapping.protocolVersion, version);
|
|
||||||
}
|
|
||||||
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
||||||
version.packetClassToId.put(clazz, mapping.id);
|
version.packetClassToId.put(clazz, mapping.id);
|
||||||
|
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol.packets;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class ClientSettings implements MinecraftPacket {
|
||||||
|
private String locale;
|
||||||
|
private byte viewDistance;
|
||||||
|
private int chatMode;
|
||||||
|
private boolean chatColors;
|
||||||
|
private short skinParts;
|
||||||
|
private int mainHand;
|
||||||
|
|
||||||
|
public String getLocale() {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocale(String locale) {
|
||||||
|
this.locale = locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getViewDistance() {
|
||||||
|
return viewDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setViewDistance(byte viewDistance) {
|
||||||
|
this.viewDistance = viewDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getChatMode() {
|
||||||
|
return chatMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChatMode(int chatMode) {
|
||||||
|
this.chatMode = chatMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChatColors() {
|
||||||
|
return chatColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChatColors(boolean chatColors) {
|
||||||
|
this.chatColors = chatColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getSkinParts() {
|
||||||
|
return skinParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkinParts(short skinParts) {
|
||||||
|
this.skinParts = skinParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMainHand() {
|
||||||
|
return mainHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMainHand(int mainHand) {
|
||||||
|
this.mainHand = mainHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClientSettings{" +
|
||||||
|
"locale='" + locale + '\'' +
|
||||||
|
", viewDistance=" + viewDistance +
|
||||||
|
", chatMode=" + chatMode +
|
||||||
|
", chatColors=" + chatColors +
|
||||||
|
", skinParts=" + skinParts +
|
||||||
|
", mainHand=" + mainHand +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
this.locale = ProtocolUtils.readString(buf, 16);
|
||||||
|
this.viewDistance = buf.readByte();
|
||||||
|
this.chatMode = ProtocolUtils.readVarInt(buf);
|
||||||
|
this.chatColors = buf.readBoolean();
|
||||||
|
this.skinParts = buf.readUnsignedByte();
|
||||||
|
this.mainHand = ProtocolUtils.readVarInt(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
ProtocolUtils.writeString(buf, locale);
|
||||||
|
buf.writeByte(viewDistance);
|
||||||
|
ProtocolUtils.writeVarInt(buf, chatMode);
|
||||||
|
buf.writeBoolean(chatColors);
|
||||||
|
buf.writeByte(skinParts);
|
||||||
|
ProtocolUtils.writeVarInt(buf, mainHand);
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren