Merge pull request #4 from Gerrygames/custom_payload_fix

ignore invalid custom payload identifiers
This commit is contained in:
creeper123123321 2019-04-11 14:47:32 -03:00 committed by GitHub
commit aad1640f34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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