Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 09:00:09 +01:00
Replace inventory ack by using 1.17 ping packets
Dieser Commit ist enthalten in:
Ursprung
703978e227
Commit
fd9dab8aa1
@ -33,6 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata.Metadat
|
|||||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPackets;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPackets;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.RegistryType;
|
import com.viaversion.viaversion.rewriter.RegistryType;
|
||||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||||
@ -204,9 +205,6 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ping
|
|
||||||
cancelServerbound(ServerboundPackets1_17.PONG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -240,6 +238,7 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
@Override
|
@Override
|
||||||
public void init(UserConnection user) {
|
public void init(UserConnection user) {
|
||||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_17Types.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_17Types.PLAYER));
|
||||||
|
user.put(new InventoryAcknowledgements());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,8 +24,10 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
||||||
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.Protocol1_17To1_16_4;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements;
|
||||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||||
|
|
||||||
public class InventoryPackets {
|
public class InventoryPackets {
|
||||||
@ -96,9 +98,35 @@ public class InventoryPackets {
|
|||||||
short confirmationId = wrapper.read(Type.SHORT);
|
short confirmationId = wrapper.read(Type.SHORT);
|
||||||
boolean accepted = wrapper.read(Type.BOOLEAN);
|
boolean accepted = wrapper.read(Type.BOOLEAN);
|
||||||
if (!accepted) {
|
if (!accepted) {
|
||||||
|
// Use the new ping packet to replace the removed acknowledgement, extra bit for fast dismissal
|
||||||
|
// Hope the client actually answers it /shrug
|
||||||
|
int id = (1 << 30) | (inventoryId << 16) | confirmationId;
|
||||||
|
wrapper.user().get(InventoryAcknowledgements.class).addId(id);
|
||||||
|
|
||||||
|
PacketWrapper pingPacket = wrapper.create(ClientboundPackets1_17.PING);
|
||||||
|
pingPacket.write(Type.INT, id);
|
||||||
|
pingPacket.send(Protocol1_17To1_16_4.class, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapper.cancel();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// New pong packet
|
||||||
|
protocol.registerServerbound(ServerboundPackets1_17.PONG, null, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
handler(wrapper -> {
|
||||||
|
int id = wrapper.read(Type.INT);
|
||||||
|
// Check extra bit for fast dismissal
|
||||||
|
if ((id & (1 << 30)) != 0 && wrapper.user().get(InventoryAcknowledgements.class).removeId(id)) {
|
||||||
|
// Decode inventory acknowledgement
|
||||||
|
int inventoryId = (id >> 16) & 0xFF;
|
||||||
|
int confirmationId = id & 0xFFFF;
|
||||||
PacketWrapper packet = wrapper.create(ServerboundPackets1_16_2.WINDOW_CONFIRMATION);
|
PacketWrapper packet = wrapper.create(ServerboundPackets1_16_2.WINDOW_CONFIRMATION);
|
||||||
packet.write(Type.UNSIGNED_BYTE, inventoryId);
|
packet.write(Type.UNSIGNED_BYTE, (short) inventoryId);
|
||||||
packet.write(Type.SHORT, confirmationId);
|
packet.write(Type.SHORT, (short) confirmationId);
|
||||||
packet.write(Type.BYTE, (byte) 1); // Accept
|
packet.write(Type.BYTE, (byte) 1); // Accept
|
||||||
packet.sendToServer(Protocol1_17To1_16_4.class, true, true);
|
packet.sendToServer(Protocol1_17To1_16_4.class, true, true);
|
||||||
}
|
}
|
||||||
|
@ -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.viaversion.protocols.protocol1_17to1_16_4.storage;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
|
|
||||||
|
public final class InventoryAcknowledgements implements StorableObject {
|
||||||
|
private final IntSet ids = new IntOpenHashSet();
|
||||||
|
|
||||||
|
public void addId(int id) {
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeId(int id) {
|
||||||
|
return ids.remove(id);
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren