Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-20 06:50:10 +01:00
Implemented ViaVersion's SignableCommandArgumentsProvider (#633)
Dieser Commit ist enthalten in:
Ursprung
4f4bff6898
Commit
2bd687b19d
@ -29,9 +29,11 @@ import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.packets.EntityP
|
|||||||
import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.storage.DimensionRegistryStorage;
|
import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.storage.DimensionRegistryStorage;
|
||||||
import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.storage.NonceStorage;
|
import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.storage.NonceStorage;
|
||||||
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1;
|
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1;
|
||||||
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
|
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
|
||||||
@ -53,8 +55,10 @@ import com.viaversion.viaversion.rewriter.CommandRewriter;
|
|||||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||||
|
import com.viaversion.viaversion.util.Pair;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@ -227,28 +231,44 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
|
|||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
map(Type.STRING); // Message
|
map(Type.STRING); // Message
|
||||||
handler(wrapper -> wrapper.write(Type.LONG, Instant.now().toEpochMilli())); // Timestamp
|
|
||||||
create(Type.LONG, 0L); // Salt
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class);
|
final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class);
|
||||||
|
|
||||||
final String message = wrapper.get(Type.STRING, 0);
|
|
||||||
if (!message.isEmpty() && message.charAt(0) == '/') {
|
|
||||||
wrapper.setPacketType(ServerboundPackets1_19.CHAT_COMMAND);
|
|
||||||
wrapper.set(Type.STRING, 0, message.substring(1));
|
|
||||||
wrapper.write(Type.VAR_INT, 0); // No signatures
|
|
||||||
} else {
|
|
||||||
if (chatSession != null) {
|
|
||||||
final UUID sender = wrapper.user().getProtocolInfo().getUuid();
|
final UUID sender = wrapper.user().getProtocolInfo().getUuid();
|
||||||
final Instant timestamp = Instant.now();
|
final Instant timestamp = Instant.now();
|
||||||
final long salt = ThreadLocalRandom.current().nextLong();
|
final long salt = ThreadLocalRandom.current().nextLong();
|
||||||
|
|
||||||
|
wrapper.write(Type.LONG, timestamp.toEpochMilli()); // Timestamp
|
||||||
|
wrapper.write(Type.LONG, chatSession != null ? salt : 0L); // Salt
|
||||||
|
|
||||||
|
final String message = wrapper.get(Type.STRING, 0);
|
||||||
|
if (!message.isEmpty() && message.charAt(0) == '/') {
|
||||||
|
final String command = message.substring(1);
|
||||||
|
|
||||||
|
wrapper.setPacketType(ServerboundPackets1_19.CHAT_COMMAND);
|
||||||
|
wrapper.set(Type.STRING, 0, command);
|
||||||
|
|
||||||
|
final SignableCommandArgumentsProvider argumentsProvider = Via.getManager().getProviders().get(SignableCommandArgumentsProvider.class);
|
||||||
|
if (chatSession != null && argumentsProvider != null) {
|
||||||
|
final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt);
|
||||||
|
|
||||||
|
final List<Pair<String, String>> arguments = argumentsProvider.getSignableArguments(command);
|
||||||
|
wrapper.write(Type.VAR_INT, arguments.size());
|
||||||
|
for (final Pair<String, String> argument : arguments) {
|
||||||
|
final byte[] signature = chatSession.signChatMessage(metadata, new DecoratableMessage(argument.value()));
|
||||||
|
|
||||||
|
wrapper.write(Type.STRING, argument.key());
|
||||||
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wrapper.write(Type.VAR_INT, 0); // No signatures
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (chatSession != null) {
|
||||||
final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt);
|
final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt);
|
||||||
final DecoratableMessage decoratableMessage = new DecoratableMessage(message);
|
final DecoratableMessage decoratableMessage = new DecoratableMessage(message);
|
||||||
final byte[] signature = chatSession.signChatMessage(metadata, decoratableMessage);
|
final byte[] signature = chatSession.signChatMessage(metadata, decoratableMessage);
|
||||||
|
|
||||||
wrapper.set(Type.LONG, 0, timestamp.toEpochMilli()); // Timestamp
|
|
||||||
wrapper.set(Type.LONG, 1, salt); // Salt
|
|
||||||
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature
|
||||||
} else {
|
} else {
|
||||||
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES); // Signature
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES); // Signature
|
||||||
|
@ -28,11 +28,13 @@ import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.ChatS
|
|||||||
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.ChatTypeStorage1_19_3;
|
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.ChatTypeStorage1_19_3;
|
||||||
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.NonceStorage;
|
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.storage.NonceStorage;
|
||||||
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1;
|
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1;
|
||||||
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
|
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
@ -55,8 +57,10 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
|||||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||||
import com.viaversion.viaversion.util.CipherUtil;
|
import com.viaversion.viaversion.util.CipherUtil;
|
||||||
|
import com.viaversion.viaversion.util.Pair;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_1, ServerboundPackets1_19_3, ServerboundPackets1_19_1> {
|
public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_1, ServerboundPackets1_19_3, ServerboundPackets1_19_1> {
|
||||||
|
|
||||||
@ -286,14 +290,35 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundP
|
|||||||
map(Type.LONG); // Timestamp
|
map(Type.LONG); // Timestamp
|
||||||
map(Type.LONG); // Salt
|
map(Type.LONG); // Salt
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
|
final ChatSession1_19_3 chatSession = wrapper.user().get(ChatSession1_19_3.class);
|
||||||
|
final SignableCommandArgumentsProvider argumentsProvider = Via.getManager().getProviders().get(SignableCommandArgumentsProvider.class);
|
||||||
|
|
||||||
|
final String command = wrapper.get(Type.STRING, 0);
|
||||||
|
final long timestamp = wrapper.get(Type.LONG, 0);
|
||||||
|
final long salt = wrapper.get(Type.LONG, 1);
|
||||||
|
|
||||||
final int signatures = wrapper.read(Type.VAR_INT);
|
final int signatures = wrapper.read(Type.VAR_INT);
|
||||||
wrapper.write(Type.VAR_INT, 0);
|
|
||||||
for (int i = 0; i < signatures; i++) {
|
for (int i = 0; i < signatures; i++) {
|
||||||
wrapper.read(Type.STRING); // Name
|
wrapper.read(Type.STRING); // Name
|
||||||
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
|
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
|
||||||
}
|
}
|
||||||
wrapper.read(Type.BOOLEAN); // Signed preview
|
wrapper.read(Type.BOOLEAN); // Signed preview
|
||||||
|
|
||||||
|
if (chatSession != null && argumentsProvider != null) {
|
||||||
|
final MessageMetadata metadata = new MessageMetadata(null, timestamp, salt);
|
||||||
|
|
||||||
|
final List<Pair<String, String>> arguments = argumentsProvider.getSignableArguments(command);
|
||||||
|
wrapper.write(Type.VAR_INT, arguments.size());
|
||||||
|
for (final Pair<String, String> argument : arguments) {
|
||||||
|
final byte[] signature = chatSession.signChatMessage(metadata, argument.value(), new PlayerMessageSignature[0]);
|
||||||
|
|
||||||
|
wrapper.write(Type.STRING, argument.key());
|
||||||
|
wrapper.write(Protocol1_19_1To1_19_3.SIGNATURE_BYTES_TYPE, signature);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wrapper.write(Type.VAR_INT, 0); // No signatures
|
||||||
|
}
|
||||||
|
|
||||||
final int offset = 0;
|
final int offset = 0;
|
||||||
final BitSet acknowledged = new BitSet(20);
|
final BitSet acknowledged = new BitSet(20);
|
||||||
wrapper.write(Type.VAR_INT, offset);
|
wrapper.write(Type.VAR_INT, offset);
|
||||||
|
@ -26,10 +26,12 @@ import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ChatReg
|
|||||||
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ChatRegistryStorage1_19_1;
|
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ChatRegistryStorage1_19_1;
|
||||||
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.NonceStorage;
|
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.NonceStorage;
|
||||||
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ReceivedMessagesStorage;
|
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ReceivedMessagesStorage;
|
||||||
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
|
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
|
||||||
@ -55,6 +57,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPacke
|
|||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets;
|
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets;
|
||||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||||
import com.viaversion.viaversion.util.CipherUtil;
|
import com.viaversion.viaversion.util.CipherUtil;
|
||||||
|
import com.viaversion.viaversion.util.Pair;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -230,6 +233,33 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
|
|||||||
map(Type.LONG); // Timestamp
|
map(Type.LONG); // Timestamp
|
||||||
map(Type.LONG); // Salt
|
map(Type.LONG); // Salt
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
|
final ReceivedMessagesStorage messagesStorage = wrapper.user().get(ReceivedMessagesStorage.class);
|
||||||
|
final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class);
|
||||||
|
final SignableCommandArgumentsProvider argumentsProvider = Via.getManager().getProviders().get(SignableCommandArgumentsProvider.class);
|
||||||
|
|
||||||
|
if (chatSession != null && argumentsProvider != null) {
|
||||||
|
final int signatures = wrapper.read(Type.VAR_INT);
|
||||||
|
for (int i = 0; i < signatures; i++) {
|
||||||
|
wrapper.read(Type.STRING); // Argument name
|
||||||
|
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
|
||||||
|
}
|
||||||
|
|
||||||
|
final UUID sender = wrapper.user().getProtocolInfo().getUuid();
|
||||||
|
final String command = wrapper.get(Type.STRING, 0);
|
||||||
|
final long timestamp = wrapper.get(Type.LONG, 0);
|
||||||
|
final long salt = wrapper.get(Type.LONG, 1);
|
||||||
|
|
||||||
|
final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt);
|
||||||
|
|
||||||
|
final List<Pair<String, String>> arguments = argumentsProvider.getSignableArguments(command);
|
||||||
|
wrapper.write(Type.VAR_INT, arguments.size());
|
||||||
|
for (final Pair<String, String> argument : arguments) {
|
||||||
|
final byte[] signature = chatSession.signChatMessage(metadata, new DecoratableMessage(argument.value()), messagesStorage.lastSignatures());
|
||||||
|
|
||||||
|
wrapper.write(Type.STRING, argument.key());
|
||||||
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
final int signatures = wrapper.passthrough(Type.VAR_INT);
|
final int signatures = wrapper.passthrough(Type.VAR_INT);
|
||||||
for (int i = 0; i < signatures; i++) {
|
for (int i = 0; i < signatures; i++) {
|
||||||
wrapper.passthrough(Type.STRING); // Argument name
|
wrapper.passthrough(Type.STRING); // Argument name
|
||||||
@ -238,10 +268,10 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
|
|||||||
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
|
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
|
||||||
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES);
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wrapper.passthrough(Type.BOOLEAN); // Signed preview
|
wrapper.passthrough(Type.BOOLEAN); // Signed preview
|
||||||
|
|
||||||
final ReceivedMessagesStorage messagesStorage = wrapper.user().get(ReceivedMessagesStorage.class);
|
|
||||||
messagesStorage.resetUnacknowledgedCount();
|
messagesStorage.resetUnacknowledgedCount();
|
||||||
wrapper.write(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY, messagesStorage.lastSignatures());
|
wrapper.write(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY, messagesStorage.lastSignatures());
|
||||||
wrapper.write(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE, null); // No last unacknowledged
|
wrapper.write(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE, null); // No last unacknowledged
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren