diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 4fa1cf83..3961f8cd 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; @@ -55,7 +56,7 @@ public class TpCommand extends BasicCommand { //Give control of teleport command to server if(server == null) { - player.chat("/tp " + String.join(" ", args)); + Chat19.chat(player, "/tp " + String.join(" ", args)); return; } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index a09cdbfe..483dc9db 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.comms.packets.PingPacket; import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.*; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -123,7 +124,7 @@ public class ChatListener extends BasicListener { return; } - player.chat(message); + Chat19.chat(player, message); } private static String modifyFilter(ChatSender sender, String message) { diff --git a/src/de/steamwar/bungeecore/util/Chat19.java b/src/de/steamwar/bungeecore/util/Chat19.java new file mode 100644 index 00000000..11103554 --- /dev/null +++ b/src/de/steamwar/bungeecore/util/Chat19.java @@ -0,0 +1,67 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.util; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.md_5.bungee.ServerConnection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.protocol.PacketWrapper; +import net.md_5.bungee.protocol.ProtocolConstants; +import net.md_5.bungee.protocol.packet.Chat; + +import java.time.Instant; + +public class Chat19 extends Chat { + + public static void chat(ProxiedPlayer p, String message) { + if(p.getPendingConnection().getVersion() >= 759) { + Chat19 packet = new Chat19(message); + + ByteBuf buf = Unpooled.buffer(); + writeVarInt(0x04, buf); + packet.write(buf, ProtocolConstants.Direction.TO_SERVER, p.getPendingConnection().getVersion()); + ((ServerConnection) p.getServer()).getCh().write(new PacketWrapper(packet, buf)); + } else { + p.chat(message); + } + } + + private final Instant timestamp = Instant.now(); + private final long salt = 0L; + private final byte[] signature = new byte[0]; + private final boolean signedPreview = false; + + public Chat19 (String message) { + super(message); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { + if (direction == ProtocolConstants.Direction.TO_CLIENT || protocolVersion != 759) + throw new UnsupportedOperationException(); + + writeString(getMessage(), buf); + buf.writeLong(timestamp.toEpochMilli()); + buf.writeLong(salt); + writeArray(signature, buf); + buf.writeBoolean(signedPreview); + } +}