mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-21 11:35:16 +01:00
Merge pull request #4 from Gerrygames/custom_payload_fix
ignore invalid custom payload identifiers
This commit is contained in:
commit
aad1640f34
@ -24,12 +24,64 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.protocol;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.InvalidIdentifierException;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientSideReference extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
// Plugin Message
|
||||
registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
String channel = wrapper.passthrough(Type.STRING);
|
||||
|
||||
try {
|
||||
new Identifier(channel);
|
||||
} catch (InvalidIdentifierException ex) {
|
||||
Via.getPlatform().getLogger().warning("Ignoring invalid custom payload identifier: " + ex.getMessage());
|
||||
wrapper.set(Type.STRING, 0, "viafabric:invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
|
||||
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
|
||||
|
||||
List<String> filteredChannels = new LinkedList<>();
|
||||
|
||||
for (String c : channels) {
|
||||
try {
|
||||
new Identifier(c);
|
||||
} catch (InvalidIdentifierException ex) {
|
||||
Via.getPlatform().getLogger().warning("Ignoring invalid custom payload identifier in " + channel + ": " + ex.getMessage());
|
||||
continue;
|
||||
}
|
||||
filteredChannels.add(c);
|
||||
}
|
||||
|
||||
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(filteredChannels).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user