From 0446af29aaf5e70d7ceb0dd2731ae127dd236f5e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 Jun 2022 22:10:10 +0200 Subject: [PATCH] Cannot spoof chat my ass Signed-off-by: Lixfel --- .../bungeecore/commands/TpCommand.java | 3 +- .../bungeecore/listeners/ChatListener.java | 3 +- src/de/steamwar/bungeecore/util/Chat19.java | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/bungeecore/util/Chat19.java diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 4fa1cf8..3961f8c 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 a09cdbf..483dc9d 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 0000000..1110355 --- /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); + } +}