Fix: pass through last seen update in a few missing places

This is hardly useful in the case of signed player chat messages, as these fundamentally cannot be spoofed or modified - however, for any unsigned input (particularly commands without any signed arguments), 'last seen' updates are still required and should be passed through in a consistent state.
This commit is contained in:
Gegy 2023-11-27 18:30:32 +01:00 committed by Riley Park
parent b5ee9dd20a
commit 077968089e
5 changed files with 14 additions and 3 deletions

View File

@ -1112,6 +1112,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
ChatBuilderV2 message = getChatBuilderFactory().builder().asPlayer(this).message(input);
this.chatQueue.queuePacket(chatState -> {
message.setTimestamp(chatState.lastTimestamp);
message.setLastSeenMessages(chatState.createLastSeen());
return message.toServer();
});
} else {

View File

@ -21,6 +21,7 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ChatType;
import com.velocitypowered.proxy.protocol.packet.chat.LastSeenMessages;
import java.time.Instant;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
@ -36,6 +37,7 @@ public abstract class ChatBuilderV2 {
protected @Nullable Identity senderIdentity;
protected Instant timestamp;
protected ChatType type = ChatType.CHAT;
protected @Nullable LastSeenMessages lastSeenMessages;
protected ChatBuilderV2(ProtocolVersion version) {
this.version = version;
@ -77,6 +79,11 @@ public abstract class ChatBuilderV2 {
return this;
}
public ChatBuilderV2 setLastSeenMessages(LastSeenMessages lastSeenMessages) {
this.lastSeenMessages = lastSeenMessages;
return this;
}
public abstract MinecraftPacket toClient();
public abstract MinecraftPacket toServer();

View File

@ -41,6 +41,7 @@ public class SessionChatBuilder extends ChatBuilderV2 {
@Override
public MinecraftPacket toServer() {
LastSeenMessages lastSeenMessages = this.lastSeenMessages != null ? this.lastSeenMessages : new LastSeenMessages();
if (message.startsWith("/")) {
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_5)) {
UnsignedPlayerCommandPacket command = new UnsignedPlayerCommandPacket();
@ -52,7 +53,7 @@ public class SessionChatBuilder extends ChatBuilderV2 {
command.salt = 0L;
command.timeStamp = timestamp;
command.argumentSignatures = new SessionPlayerCommandPacket.ArgumentSignatures();
command.lastSeenMessages = new LastSeenMessages();
command.lastSeenMessages = lastSeenMessages;
return command;
}
} else {
@ -62,8 +63,8 @@ public class SessionChatBuilder extends ChatBuilderV2 {
chat.signature = new byte[0];
chat.timestamp = timestamp;
chat.salt = 0L;
chat.lastSeenMessages = new LastSeenMessages();
chat.lastSeenMessages = lastSeenMessages;
return chat;
}
}
}
}

View File

@ -73,6 +73,7 @@ public class SessionChatHandler implements ChatHandler<SessionPlayerChatPacket>
}
return this.player.getChatBuilderFactory().builder().message(packet.message)
.setTimestamp(packet.timestamp)
.setLastSeenMessages(newLastSeenMessages)
.toServer();
}
return packet.withLastSeenMessages(newLastSeenMessages);

View File

@ -86,6 +86,7 @@ public class SessionCommandHandler implements CommandHandler<SessionPlayerComman
return this.player.getChatBuilderFactory()
.builder()
.setTimestamp(packet.timeStamp)
.setLastSeenMessages(packet.lastSeenMessages)
.asPlayer(this.player)
.message("/" + newCommand)
.toServer();