3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-25 15:50:12 +01:00

Add option to replace ping packets by using container acks

Closes ViaVersion/ViaVersion#2624
Dieser Commit ist enthalten in:
kennytv 2021-07-17 11:11:40 +02:00
Ursprung fa707e5391
Commit 455bb546f0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
7 geänderte Dateien mit 90 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
private boolean addTeamColorToPrefix; private boolean addTeamColorToPrefix;
private boolean fix1_13FacePlayer; private boolean fix1_13FacePlayer;
private boolean alwaysShowOriginalMobName; private boolean alwaysShowOriginalMobName;
private boolean handlePingsAsInvAcknowledgements;
public ViaBackwardsConfig(File configFile) { public ViaBackwardsConfig(File configFile) {
super(configFile); super(configFile);
@ -47,6 +48,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
addTeamColorToPrefix = getBoolean("add-teamcolor-to-prefix", true); addTeamColorToPrefix = getBoolean("add-teamcolor-to-prefix", true);
fix1_13FacePlayer = getBoolean("fix-1_13-face-player", false); fix1_13FacePlayer = getBoolean("fix-1_13-face-player", false);
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true); alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
} }
@Override @Override
@ -69,6 +71,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
return alwaysShowOriginalMobName; return alwaysShowOriginalMobName;
} }
@Override
public boolean handlePingsAsInvAcknowledgements() {
return handlePingsAsInvAcknowledgements || Boolean.getBoolean("com.viaversion.handlePingsAsInvAcknowledgements");
}
@Override @Override
public URL getDefaultConfigURL() { public URL getDefaultConfigURL() {
return getClass().getClassLoader().getResource("assets/viabackwards/config.yml"); return getClass().getClassLoader().getResource("assets/viabackwards/config.yml");

Datei anzeigen

@ -46,4 +46,6 @@ public interface ViaBackwardsConfig {
* @return true if enabled * @return true if enabled
*/ */
boolean alwaysShowOriginalMobName(); boolean alwaysShowOriginalMobName();
boolean handlePingsAsInvAcknowledgements();
} }

Datei anzeigen

@ -145,7 +145,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
// Apologize (may happen in some cases, maybe if inventory is full?) // Apologize (may happen in some cases, maybe if inventory is full?)
PacketWrapper confirm = wrapper.create(ServerboundPackets1_12.WINDOW_CONFIRMATION); PacketWrapper confirm = wrapper.create(ServerboundPackets1_12.WINDOW_CONFIRMATION);
confirm.write(Type.BYTE, wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue()); confirm.write(Type.UNSIGNED_BYTE, wrapper.get(Type.UNSIGNED_BYTE, 0));
confirm.write(Type.SHORT, wrapper.get(Type.SHORT, 1)); confirm.write(Type.SHORT, wrapper.get(Type.SHORT, 1));
confirm.write(Type.BOOLEAN, false); // Success - not used confirm.write(Type.BOOLEAN, false); // Success - not used

Datei anzeigen

@ -17,12 +17,14 @@
*/ */
package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17; package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappings;
import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPackets1_17; import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPackets1_17;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17; import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PingRequests;
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.TagData; import com.viaversion.viaversion.api.minecraft.TagData;
@ -186,8 +188,21 @@ public final class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPac
handler(wrapper -> { handler(wrapper -> {
wrapper.cancel(); wrapper.cancel();
// Plugins expecting a real response will have to handle this accordingly themselves
int id = wrapper.read(Type.INT); int id = wrapper.read(Type.INT);
short shortId = (short) id;
if (id == shortId && ViaBackwards.getConfig().handlePingsAsInvAcknowledgements()) {
wrapper.user().get(PingRequests.class).addId(shortId);
// Send inventory acknowledgement to replace ping packet functionality in the unsigned byte range
PacketWrapper acknowledgementPacket = wrapper.create(ClientboundPackets1_16_2.WINDOW_CONFIRMATION);
acknowledgementPacket.write(Type.UNSIGNED_BYTE, (short) 0); // Inventory id
acknowledgementPacket.write(Type.SHORT, shortId); // Confirmation id
acknowledgementPacket.write(Type.BOOLEAN, false); // Accepted
acknowledgementPacket.send(Protocol1_16_4To1_17.class);
return;
}
// Plugins expecting a real response will have to handle this accordingly themselves
PacketWrapper pongPacket = wrapper.create(ServerboundPackets1_17.PONG); PacketWrapper pongPacket = wrapper.create(ServerboundPackets1_17.PONG);
pongPacket.write(Type.INT, id); pongPacket.write(Type.INT, id);
pongPacket.sendToServer(Protocol1_16_4To1_17.class); pongPacket.sendToServer(Protocol1_16_4To1_17.class);
@ -233,6 +248,7 @@ public final class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPac
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
addEntityTracker(user, new EntityTrackerBase(user, Entity1_17Types.PLAYER)); addEntityTracker(user, new EntityTrackerBase(user, Entity1_17Types.PLAYER));
user.put(new PingRequests());
} }
@Override @Override

Datei anzeigen

@ -17,11 +17,13 @@
*/ */
package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets; package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.ItemRewriter; import com.viaversion.viabackwards.api.rewriters.ItemRewriter;
import com.viaversion.viabackwards.api.rewriters.MapColorRewriter; import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17; import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.data.MapColorRewrites; import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.data.MapColorRewrites;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PingRequests;
import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@ -34,6 +36,7 @@ import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPac
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type;
import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.BlockRewriter;
@ -92,7 +95,27 @@ public final class BlockItemPackets1_17 extends ItemRewriter<Protocol1_16_4To1_1
}); });
} }
}); });
protocol.cancelServerbound(ServerboundPackets1_16_2.WINDOW_CONFIRMATION); protocol.registerServerbound(ServerboundPackets1_16_2.WINDOW_CONFIRMATION, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
if (!ViaBackwards.getConfig().handlePingsAsInvAcknowledgements()) {
return;
}
// Handle ping packet replacement
short inventoryId = wrapper.read(Type.UNSIGNED_BYTE);
short confirmationId = wrapper.read(Type.SHORT);
boolean accepted = wrapper.read(Type.BOOLEAN);
if (inventoryId == 0 && accepted && wrapper.user().get(PingRequests.class).removeId(confirmationId)) {
PacketWrapper pongPacket = wrapper.create(ServerboundPackets1_17.PONG);
pongPacket.write(Type.INT, (int) confirmationId);
pongPacket.sendToServer(Protocol1_16_4To1_17.class);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.SPAWN_PARTICLE, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_17.SPAWN_PARTICLE, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -0,0 +1,34 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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_16_4to1_17.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
public final class PingRequests implements StorableObject {
private final IntSet ids = new IntOpenHashSet();
public void addId(short id) {
ids.add(id);
}
public boolean removeId(short id) {
return ids.remove(id);
}
}

Datei anzeigen

@ -12,3 +12,7 @@ add-teamcolor-to-prefix: true
# #
# Converts the 1.13 face look-at packet for 1.12- players. Requires a bit of extra caching. # Converts the 1.13 face look-at packet for 1.12- players. Requires a bit of extra caching.
fix-1_13-face-player: false fix-1_13-face-player: false
#
# Sends inventory acknowledgement packets to act as a replacement for ping packets for sub 1.17 clients.
# This only takes effect for ids in the short range. Useful for anticheat compatibility.
handle-pings-as-inv-acknowledgements: false