diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatHeaderListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatHeaderListener.java index 5c6134b..081316b 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatHeaderListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatHeaderListener.java @@ -8,7 +8,7 @@ import io.github._4drian3d.unsignedvelocity.configuration.Configuration; import io.github._4drian3d.unsignedvelocity.listener.packet.ConfigurablePacketListener; -public final class ChatHeaderListener extends ConfigurablePacketListener { +public class ChatHeaderListener extends ConfigurablePacketListener { @Inject public ChatHeaderListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); @@ -20,9 +20,9 @@ public boolean canBeLoaded() { } @Override - public void onPacketSend(final PacketSendEvent event) { + public void onPacketSend(PacketSendEvent event) { if (event.isCancelled()) return; - final PacketTypeCommon packetType = event.getPacketType(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Play.Server.PLAYER_CHAT_HEADER) { event.setCancelled(true); } diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatSessionListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatSessionListener.java index 3f70a88..e5469fa 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatSessionListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ChatSessionListener.java @@ -8,7 +8,7 @@ import io.github._4drian3d.unsignedvelocity.configuration.Configuration; import io.github._4drian3d.unsignedvelocity.listener.packet.ConfigurablePacketListener; -public final class ChatSessionListener extends ConfigurablePacketListener { +public class ChatSessionListener extends ConfigurablePacketListener { @Inject public ChatSessionListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); @@ -20,9 +20,9 @@ public boolean canBeLoaded() { } @Override - public void onPacketReceive(final PacketReceiveEvent event) { + public void onPacketReceive(PacketReceiveEvent event) { if (event.isCancelled()) return; - final PacketTypeCommon packetType = event.getPacketType(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Play.Client.CHAT_SESSION_UPDATE) { event.setCancelled(true); } diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ClientChatListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ClientChatListener.java index d6bed59..d6d78d7 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ClientChatListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ClientChatListener.java @@ -13,7 +13,7 @@ import java.time.Instant; -public final class ClientChatListener extends ConfigurablePacketListener { +public class ClientChatListener extends ConfigurablePacketListener { @Inject public ClientChatListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); @@ -25,18 +25,17 @@ public boolean canBeLoaded() { } @Override - public void onPacketReceive(final PacketReceiveEvent event) { + public void onPacketReceive(PacketReceiveEvent event) { if (event.isCancelled()) return; - final PacketTypeCommon packetType = event.getPacketType(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Play.Client.CHAT_MESSAGE) { - final WrapperPlayClientChatMessage packet = new WrapperPlayClientChatMessage(event); - if (packet.getMessageSignData().isEmpty()) { - return; + WrapperPlayClientChatMessage packet = new WrapperPlayClientChatMessage(event); + if (packet.getMessageSignData().isPresent()) { + MessageSignData packetMessageSignData = packet.getMessageSignData().get(); + Instant packetTimestamp = packetMessageSignData.getTimestamp(); + packet.setMessageSignData(new MessageSignData(new SaltSignature(0L, new byte[0]), packetTimestamp)); + event.markForReEncode(true); } - MessageSignData packetMessageSignData = packet.getMessageSignData().get(); - Instant packetTimestamp = packetMessageSignData.getTimestamp(); - packet.setMessageSignData(new MessageSignData(new SaltSignature(0L, new byte[0]), packetTimestamp)); - event.markForReEncode(true); } } } diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ServerChatListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ServerChatListener.java index 9cead38..f6af899 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ServerChatListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/chat/ServerChatListener.java @@ -19,14 +19,14 @@ import java.util.Optional; -public final class ServerChatListener extends ConfigurablePacketListener { +public class ServerChatListener extends ConfigurablePacketListener { @Inject public ServerChatListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); } private static @Nullable Component getComponentFromChatPacket(PacketSendEvent event) { - final WrapperPlayServerChatMessage packet = new WrapperPlayServerChatMessage(event); + WrapperPlayServerChatMessage packet = new WrapperPlayServerChatMessage(event); ChatMessage chatMessage = packet.getMessage(); Component messageContent = chatMessage.getChatContent(); if (chatMessage instanceof ChatMessage_v1_19) { @@ -48,18 +48,17 @@ public boolean canBeLoaded() { } @Override - public void onPacketSend(final PacketSendEvent event) { + public void onPacketSend(PacketSendEvent event) { if (event.isCancelled()) return; - final PacketTypeCommon packetType = event.getPacketType(); + ClientVersion version = event.getUser().getClientVersion(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Play.Server.CHAT_MESSAGE) { - if (event.getUser().getClientVersion().isOlderThan(ClientVersion.V_1_19)) { - return; + if (version.isNewerThan(ClientVersion.V_1_18_2)) { + Component messageContent = getComponentFromChatPacket(event); + WrapperPlayServerSystemChatMessage newPacket = new WrapperPlayServerSystemChatMessage(false, messageContent); + event.getUser().sendPacketSilently(newPacket); + event.setCancelled(true); } - - Component messageContent = getComponentFromChatPacket(event); - final WrapperPlayServerSystemChatMessage newPacket = new WrapperPlayServerSystemChatMessage(false, messageContent); - event.getUser().sendPacketSilently(newPacket); - event.setCancelled(true); } } } diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/command/CommandListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/command/CommandListener.java index fb86fbd..393f008 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/command/CommandListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/command/CommandListener.java @@ -13,7 +13,7 @@ import java.time.Instant; -public final class CommandListener extends ConfigurablePacketListener { +public class CommandListener extends ConfigurablePacketListener { @Inject public CommandListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); @@ -25,11 +25,11 @@ public boolean canBeLoaded() { } @Override - public void onPacketReceive(final PacketReceiveEvent event) { + public void onPacketReceive(PacketReceiveEvent event) { if (event.isCancelled()) return; - final PacketTypeCommon packetType = event.getPacketType(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Play.Client.CHAT_COMMAND) { - final WrapperPlayClientChatCommand packet = new WrapperPlayClientChatCommand(event); + WrapperPlayClientChatCommand packet = new WrapperPlayClientChatCommand(event); MessageSignData packetMessageSignData = packet.getMessageSignData(); Instant packetTimestamp = packetMessageSignData.getTimestamp(); packet.setMessageSignData(new MessageSignData(new SaltSignature(0L, new byte[0]), packetTimestamp)); diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/data/ServerDataListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/data/ServerDataListener.java index 8151141..a628ff2 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/data/ServerDataListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/data/ServerDataListener.java @@ -5,14 +5,13 @@ import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; import com.github.retrooper.packetevents.protocol.player.ClientVersion; -import com.github.retrooper.packetevents.protocol.player.User; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerServerData; import com.google.inject.Inject; import io.github._4drian3d.unsignedvelocity.configuration.Configuration; import io.github._4drian3d.unsignedvelocity.listener.packet.ConfigurablePacketListener; -public final class ServerDataListener extends ConfigurablePacketListener { +public class ServerDataListener extends ConfigurablePacketListener { @Inject public ServerDataListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); @@ -24,24 +23,20 @@ public boolean canBeLoaded() { } @Override - public void onPacketSend(final PacketSendEvent event) { + public void onPacketSend(PacketSendEvent event) { if (event.isCancelled()) return; - final User user = event.getUser(); - final PacketTypeCommon packetType = event.getPacketType(); + ClientVersion version = event.getUser().getClientVersion(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Play.Server.SERVER_DATA) { - if (user.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_19_1) && user.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_20_3)) { - final WrapperPlayServerServerData packet = new WrapperPlayServerServerData(event); - if (!packet.isEnforceSecureChat()) { - packet.setEnforceSecureChat(true); - } + if (version.isNewerThan(ClientVersion.V_1_19) && version.isOlderThan(ClientVersion.V_1_20_5)) { + WrapperPlayServerServerData packet = new WrapperPlayServerServerData(event); + packet.setEnforceSecureChat(true); event.markForReEncode(true); } } else if (packetType == PacketType.Play.Server.JOIN_GAME) { - if (user.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20_5)) { - final WrapperPlayServerJoinGame packet = new WrapperPlayServerJoinGame(event); - if (!packet.isEnforcesSecureChat()) { - packet.setEnforcesSecureChat(true); - } + if (version.isNewerThan(ClientVersion.V_1_20_3)) { + WrapperPlayServerJoinGame packet = new WrapperPlayServerJoinGame(event); + packet.setEnforcesSecureChat(true); event.markForReEncode(true); } } diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/login/LoginListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/login/LoginListener.java index 3b34c02..eea2fb1 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/login/LoginListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/login/LoginListener.java @@ -5,7 +5,6 @@ import com.github.retrooper.packetevents.event.PacketListenerPriority; import com.github.retrooper.packetevents.event.PacketReceiveEvent; import com.github.retrooper.packetevents.event.PacketSendEvent; -import com.github.retrooper.packetevents.manager.server.VersionComparison; import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; import com.github.retrooper.packetevents.protocol.player.ClientVersion; @@ -23,7 +22,7 @@ import java.security.PublicKey; import java.util.concurrent.TimeUnit; -public final class LoginListener extends ConfigurablePacketListener { +public class LoginListener extends ConfigurablePacketListener { private final ProxyServer server; private final Cache cache; @@ -53,53 +52,46 @@ public boolean canBeLoaded() { @Override public void onPacketReceive(PacketReceiveEvent event) { - final User user = event.getUser(); - final PacketTypeCommon packetType = event.getPacketType(); + if (event.isCancelled()) return; + User user = event.getUser(); + ClientVersion version = user.getClientVersion(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Login.Client.LOGIN_START) { - if (!user.getClientVersion().is(VersionComparison.EQUALS, ClientVersion.V_1_19) && !user.getClientVersion().is(VersionComparison.EQUALS, ClientVersion.V_1_19_1)) { - return; - } - - WrapperLoginClientLoginStart packet = new WrapperLoginClientLoginStart(event); - - if (packet.getSignatureData().isEmpty()) { - return; + if (version.isNewerThan(ClientVersion.V_1_18_2) && version.isOlderThan(ClientVersion.V_1_19_3)) { + WrapperLoginClientLoginStart packet = new WrapperLoginClientLoginStart(event); + if (packet.getSignatureData().isPresent()) { + packet.setSignatureData(null); + event.markForReEncode(true); + } } - packet.setSignatureData(null); - event.markForReEncode(true); } else if (packetType == PacketType.Login.Client.ENCRYPTION_RESPONSE) { - if (!user.getClientVersion().is(VersionComparison.EQUALS, ClientVersion.V_1_19) && !user.getClientVersion().is(VersionComparison.EQUALS, ClientVersion.V_1_19_1)) { - return; - } - - WrapperLoginClientEncryptionResponse packet = new WrapperLoginClientEncryptionResponse(event); - - boolean cacheContainsUser = cache.getIfPresent(user) != null; - if (packet.getSaltSignature().isPresent() && cacheContainsUser) { + if (version.isNewerThan(ClientVersion.V_1_18_2) && version.isOlderThan(ClientVersion.V_1_19_3)) { + WrapperLoginClientEncryptionResponse packet = new WrapperLoginClientEncryptionResponse(event); byte[] encryptedVerifyToken = cache.getIfPresent(user); - - packet.setSaltSignature(null); - packet.setEncryptedVerifyToken(encryptedVerifyToken); + if (packet.getSaltSignature().isPresent() && encryptedVerifyToken != null) { + packet.setSaltSignature(null); + packet.setEncryptedVerifyToken(encryptedVerifyToken); + } + cache.invalidate(user); + event.markForReEncode(true); } - cache.invalidate(user); - event.markForReEncode(true); } } @Override public void onPacketSend(PacketSendEvent event) { if (event.isCancelled()) return; - final User user = event.getUser(); - final PacketTypeCommon packetType = event.getPacketType(); + User user = event.getUser(); + ClientVersion version = user.getClientVersion(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Login.Server.ENCRYPTION_REQUEST) { - if (!user.getClientVersion().is(VersionComparison.EQUALS, ClientVersion.V_1_19) && !user.getClientVersion().is(VersionComparison.EQUALS, ClientVersion.V_1_19_1)) { - return; + if (version.isNewerThan(ClientVersion.V_1_18_2) && version.isOlderThan(ClientVersion.V_1_19_3)) { + WrapperLoginServerEncryptionRequest packet = new WrapperLoginServerEncryptionRequest(event); + PublicKey serverPublicKey = packet.getPublicKey(); + byte[] serverVerifyToken = packet.getVerifyToken(); + byte[] encryptedVerifyToken = MinecraftEncryptionUtil.encryptRSA(serverPublicKey, serverVerifyToken); + cache.put(user, encryptedVerifyToken); } - WrapperLoginServerEncryptionRequest packet = new WrapperLoginServerEncryptionRequest(event); - PublicKey serverPublicKey = packet.getPublicKey(); - byte[] serverVerifyToken = packet.getVerifyToken(); - byte[] encryptedVerifyToken = MinecraftEncryptionUtil.encryptRSA(serverPublicKey, serverVerifyToken); - cache.put(user, encryptedVerifyToken); } } } diff --git a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/status/ServerResponseListener.java b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/status/ServerResponseListener.java index 5975661..27026b2 100644 --- a/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/status/ServerResponseListener.java +++ b/src/main/java/io/github/_4drian3d/unsignedvelocity/listener/packet/status/ServerResponseListener.java @@ -5,14 +5,13 @@ import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; import com.github.retrooper.packetevents.protocol.player.ClientVersion; -import com.github.retrooper.packetevents.protocol.player.User; import com.github.retrooper.packetevents.wrapper.status.server.WrapperStatusServerResponse; import com.google.gson.JsonObject; import com.google.inject.Inject; import io.github._4drian3d.unsignedvelocity.configuration.Configuration; import io.github._4drian3d.unsignedvelocity.listener.packet.ConfigurablePacketListener; -public final class ServerResponseListener extends ConfigurablePacketListener { +public class ServerResponseListener extends ConfigurablePacketListener { @Inject public ServerResponseListener(Configuration configuration) { super(PacketListenerPriority.LOWEST, configuration); @@ -24,12 +23,12 @@ public boolean canBeLoaded() { } @Override - public void onPacketSend(final PacketSendEvent event) { + public void onPacketSend(PacketSendEvent event) { if (event.isCancelled()) return; - final User user = event.getUser(); - final PacketTypeCommon packetType = event.getPacketType(); + ClientVersion version = event.getUser().getClientVersion(); + PacketTypeCommon packetType = event.getPacketType(); if (packetType == PacketType.Status.Server.RESPONSE) { - if (user.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_19)) { + if (version.isNewerThan(ClientVersion.V_1_18_2)) { WrapperStatusServerResponse packet = new WrapperStatusServerResponse(event); JsonObject component = packet.getComponent(); component.addProperty("preventsChatReports", true);