diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java index d4cdbc3..2bcdb2c 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java @@ -48,7 +48,7 @@ public class OPCFabricClient implements ClientModInitializer { for (HandshakeBuilder.HandshakeMovement movement : movements) { invoker.sendIm(new PlayerMoveC2SPacket.LookAndOnGround(movement.yaw, movement.pitch, client.player.isOnGround()), null); try { - Thread.sleep(10); + Thread.sleep(100); } catch (InterruptedException ignored) {} //OPCFabric.LOGGER.info("Sent move packet with yaw: " + (entity.getYaw() + movement.deltaYaw) + " and pitch: " + (entity.getPitch() + movement.deltaPitch)); } diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/ChatMessageS2CPacketMixin.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/ChatMessageS2CPacketMixin.java new file mode 100644 index 0000000..b570ab9 --- /dev/null +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/ChatMessageS2CPacketMixin.java @@ -0,0 +1,42 @@ +package org.muellerssoftware.openproximitychatfabric.mixins; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.network.listener.ClientPlayPacketListener; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; +import org.muellerssoftware.openproximitychatfabric.OPCFabric; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.net.InetSocketAddress; +import java.util.UUID; + +@Mixin(net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket.class) +public class ChatMessageS2CPacketMixin { + @Inject(method = "apply(Lnet/minecraft/network/listener/ClientPlayPacketListener;)V", at = @At("HEAD")) + public void onApply(ClientPlayPacketListener clientPlayPacketListener, CallbackInfo ci) { + SignedMessage message = ((ChatMessageS2CPacket) (Object) this).message(); + + String messageContent = message.getContent().getString(); + + UUID sender = message.createMetadata().sender(); + + assert MinecraftClient.getInstance().player != null; + if (sender.equals(MinecraftClient.getInstance().player.getUuid())) return; + + if (OPCFabric.tracked_players.containsKey(sender)) { + if (messageContent.matches("(\\b25[0-5]|\\b2[0-4][0-9]|\\b[01]?[0-9][0-9]?)(\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}:((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))")) { // Massive regex to check if the message is a valid IP address + OPCFabric.LOGGER.info("Found IP address in message from player " + sender + ": " + messageContent); + try { + OPCFabric.tracked_players.get(sender).tryBuild().addAddress(InetSocketAddress.createUnresolved(messageContent.split(":")[0], Integer.parseInt(messageContent.split(":")[1]))); + } catch (Exception e) { + OPCFabric.LOGGER.error("Failed to add address to handshake", e); + } + } + } + + OPCFabric.LOGGER.info(((ChatMessageS2CPacket)(Object)this).message().createMetadata().sender().toString()); + } +} diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java index 817eede..c3bcc65 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java @@ -43,7 +43,7 @@ public class OtherClientPlayerEntityMixin { OPCFabric.LOGGER.info("Handshake for player {} was built, connecting", handshake.getPlayer().getName()); assert MinecraftClient.getInstance().player != null; - MinecraftClient.getInstance().player.sendCommand("msg " + handshake.getPlayer().getName().getString() + Objects.requireNonNull(UPnPManager.INSTANCE.getGateway()).getExternalIPAddress() + ":" + VoiceServer.INSTANCE.getPort()); + MinecraftClient.getInstance().player.sendCommand("msg " + handshake.getPlayer().getName().getString() + " " + Objects.requireNonNull(UPnPManager.INSTANCE.getGateway()).getExternalIPAddress() + ":" + VoiceServer.INSTANCE.getPort(), null); builder.built = true; } diff --git a/src/main/resources/OpenProximityChatFabric.mixins.json b/src/main/resources/OpenProximityChatFabric.mixins.json index 2f42ca0..ede0ec9 100644 --- a/src/main/resources/OpenProximityChatFabric.mixins.json +++ b/src/main/resources/OpenProximityChatFabric.mixins.json @@ -9,7 +9,8 @@ "PlayerMoveMixin", "LivingEntityAccessor", "OtherClientPlayerEntityMixin", - "ClientConnectionInvoker" + "ClientConnectionInvoker", + "ChatMessageS2CPacketMixin" ], "injectors": { "defaultRequire": 1