Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Add cookie handling, TransferProvider for other platforms
Dieser Commit ist enthalten in:
Ursprung
e6814a13a9
Commit
8ffbc7047f
@ -29,7 +29,11 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_17;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
|
||||
|
||||
@ -210,8 +214,7 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
|
||||
IntTag logicalHeight = tag.get("logical_height");
|
||||
if (minY.asInt() != 0 || height.asInt() > 256 || logicalHeight.asInt() > 256) {
|
||||
if (warn && !warned) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Custom worlds heights are NOT SUPPORTED for 1.16 players and older and may lead to errors!");
|
||||
ViaBackwards.getPlatform().getLogger().warning("You have min/max set to " + minY.asInt() + "/" + height.asInt());
|
||||
ViaBackwards.getPlatform().getLogger().warning("Increased world height is NOT SUPPORTED for 1.16 players and below. They will see a void below y 0 and above 256");
|
||||
warned = true;
|
||||
}
|
||||
|
||||
|
@ -21,17 +21,24 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.data.BackwardsMappings;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.provider.TransferProvider;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter.BlockItemPacketRewriter1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.CookieStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.SecureChatStorage;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ByteArrayType;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundConfigurationPackets1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
|
||||
@ -47,6 +54,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundPackets1_20_5, ClientboundPackets1_20_3, ServerboundPackets1_20_5, ServerboundPackets1_20_3> {
|
||||
|
||||
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();
|
||||
private static final ByteArrayType COOKIE_DATA_TYPE = new ByteArrayType(5120);
|
||||
private final EntityPacketRewriter1_20_5 entityRewriter = new EntityPacketRewriter1_20_5(this);
|
||||
private final BlockItemPacketRewriter1_20_5 itemRewriter = new BlockItemPacketRewriter1_20_5(this);
|
||||
private final TranslatableRewriter<ClientboundPackets1_20_5> translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT);
|
||||
@ -95,37 +103,59 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundP
|
||||
wrapper.write(Type.BOOLEAN, wrapper.user().get(SecureChatStorage.class).enforcesSecureChat());
|
||||
});
|
||||
|
||||
// TODO
|
||||
registerClientbound(State.LOGIN, ClientboundLoginPackets.COOKIE_REQUEST.getId(), -1, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.COOKIE_REQUEST.getId(), -1, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.STORE_COOKIE.getId(), -1, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.TRANSFER.getId(), -1, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_20_5.COOKIE_REQUEST, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_20_5.STORE_COOKIE, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_20_5.TRANSFER, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
});
|
||||
registerClientbound(State.LOGIN, ClientboundLoginPackets.COOKIE_REQUEST.getId(), -1, wrapper -> handleCookieRequest(wrapper, ServerboundLoginPackets.COOKIE_RESPONSE));
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.COOKIE_REQUEST.getId(), -1, wrapper -> handleCookieRequest(wrapper, ServerboundConfigurationPackets1_20_5.COOKIE_RESPONSE));
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.STORE_COOKIE.getId(), -1, this::handleStoreCookie);
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.TRANSFER.getId(), -1, this::handleTransfer);
|
||||
registerClientbound(ClientboundPackets1_20_5.COOKIE_REQUEST, null, wrapper -> handleCookieRequest(wrapper, ServerboundPackets1_20_5.COOKIE_RESPONSE));
|
||||
registerClientbound(ClientboundPackets1_20_5.STORE_COOKIE, null, this::handleStoreCookie);
|
||||
registerClientbound(ClientboundPackets1_20_5.TRANSFER, null, this::handleTransfer);
|
||||
|
||||
registerClientboundPacketIdChanges(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.class, ClientboundConfigurationPackets1_20_3.class);
|
||||
registerServerboundPacketIdChanges(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.class, ServerboundConfigurationPackets1_20_5.class);
|
||||
}
|
||||
|
||||
private void handleStoreCookie(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
|
||||
final String resourceLocation = wrapper.read(Type.STRING);
|
||||
final byte[] data = wrapper.read(COOKIE_DATA_TYPE);
|
||||
wrapper.user().get(CookieStorage.class).cookies().put(resourceLocation, data);
|
||||
}
|
||||
|
||||
private void handleCookieRequest(final PacketWrapper wrapper, final ServerboundPacketType responseType) throws Exception {
|
||||
wrapper.cancel();
|
||||
|
||||
final String resourceLocation = wrapper.read(Type.STRING);
|
||||
final byte[] data = wrapper.user().get(CookieStorage.class).cookies().get(resourceLocation);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PacketWrapper responsePacket = wrapper.create(responseType);
|
||||
responsePacket.write(Type.STRING, resourceLocation);
|
||||
responsePacket.write(COOKIE_DATA_TYPE, data);
|
||||
responsePacket.scheduleSendToServer(Protocol1_20_3To1_20_5.class);
|
||||
}
|
||||
|
||||
private void handleTransfer(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
|
||||
final String host = wrapper.read(Type.STRING);
|
||||
final int port = wrapper.read(Type.VAR_INT);
|
||||
Via.getManager().getProviders().get(TransferProvider.class).connectToServer(wrapper.user(), host, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final UserConnection user) {
|
||||
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
|
||||
user.put(new SecureChatStorage());
|
||||
user.put(new CookieStorage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final ViaProviders providers) {
|
||||
providers.register(TransferProvider.class, TransferProvider.NOOP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
final class NoopTransferProvider implements TransferProvider {
|
||||
|
||||
@Override
|
||||
public void connectToServer(final UserConnection connection, final String host, final int port) {
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TransferProvider extends Provider {
|
||||
|
||||
TransferProvider NOOP = new NoopTransferProvider();
|
||||
|
||||
void connectToServer(UserConnection connection, String host, int port);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CookieStorage implements StorableObject {
|
||||
|
||||
private final Map<String, byte[]> cookies = new HashMap<>();
|
||||
|
||||
public Map<String, byte[]> cookies() {
|
||||
return cookies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOnServerSwitch() {
|
||||
return false;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren