mirror of
https://github.com/ViaVersion/ViaLegacy.git
synced 2024-12-31 18:08:06 +01:00
Implemented custom payload fail-safe handling
This commit is contained in:
parent
4d2161d5f1
commit
a3af7ef5bf
@ -18,6 +18,7 @@
|
||||
package net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
@ -273,18 +274,26 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol<ClientboundPackets
|
||||
final String channel = wrapper.read(Types1_6_4.STRING); // channel
|
||||
short length = wrapper.read(Type.SHORT); // length
|
||||
|
||||
if (channel.equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // window Id
|
||||
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
||||
for (int i = 0; i < count; i++) {
|
||||
wrapper.passthrough(Types1_7_6.ITEM); // item 1
|
||||
wrapper.passthrough(Types1_7_6.ITEM); // item 3
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) { // has 3 items
|
||||
wrapper.passthrough(Types1_7_6.ITEM); // item 2
|
||||
try {
|
||||
if (channel.equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // window Id
|
||||
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
||||
for (int i = 0; i < count; i++) {
|
||||
wrapper.passthrough(Types1_7_6.ITEM); // item 1
|
||||
wrapper.passthrough(Types1_7_6.ITEM); // item 3
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) { // has 3 items
|
||||
wrapper.passthrough(Types1_7_6.ITEM); // item 2
|
||||
}
|
||||
wrapper.write(Type.BOOLEAN, false); // unavailable
|
||||
}
|
||||
wrapper.write(Type.BOOLEAN, false); // unavailable
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
}
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.resetReader();
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
@ -43,6 +44,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_5_2, ClientboundPackets1_6_1, ServerboundPackets1_5_2, ServerboundPackets1_6_4> {
|
||||
|
||||
@ -302,18 +304,26 @@ public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_
|
||||
String channel = wrapper.read(Types1_6_4.STRING); // channel
|
||||
short length = wrapper.read(Type.SHORT); // length
|
||||
|
||||
if (channel.equals("MC|TPack")) {
|
||||
channel = "MC|RPack";
|
||||
final String[] data = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); // data
|
||||
final String url = data[0];
|
||||
final String resolution = data[1];
|
||||
if (!resolution.equals("16")) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (channel.equals("MC|TPack")) {
|
||||
channel = "MC|RPack";
|
||||
final String[] data = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); // data
|
||||
final String url = data[0];
|
||||
final String resolution = data[1];
|
||||
if (!resolution.equals("16")) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.write(Type.REMAINING_BYTES, url.getBytes(StandardCharsets.UTF_8));
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
wrapper.write(Type.REMAINING_BYTES, url.getBytes(StandardCharsets.UTF_8));
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.resetReader();
|
||||
|
@ -749,18 +749,26 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol<Clientbo
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel.equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // window id
|
||||
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
||||
for (int i = 0; i < count; i++) {
|
||||
itemRewriter.handleItemToClient(wrapper.passthrough(Types1_7_6.ITEM)); // item 1
|
||||
itemRewriter.handleItemToClient(wrapper.passthrough(Types1_7_6.ITEM)); // item 3
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) { // has 3 items
|
||||
itemRewriter.handleItemToClient(wrapper.passthrough(Types1_7_6.ITEM)); // item 2
|
||||
try {
|
||||
if (channel.equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // window id
|
||||
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
||||
for (int i = 0; i < count; i++) {
|
||||
itemRewriter.handleItemToClient(wrapper.passthrough(Types1_7_6.ITEM)); // item 1
|
||||
itemRewriter.handleItemToClient(wrapper.passthrough(Types1_7_6.ITEM)); // item 3
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) { // has 3 items
|
||||
itemRewriter.handleItemToClient(wrapper.passthrough(Types1_7_6.ITEM)); // item 2
|
||||
}
|
||||
wrapper.passthrough(Type.BOOLEAN); // unavailable
|
||||
}
|
||||
wrapper.passthrough(Type.BOOLEAN); // unavailable
|
||||
length = PacketUtil.calculateLength(wrapper);
|
||||
}
|
||||
length = PacketUtil.calculateLength(wrapper);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.resetReader();
|
||||
@ -1058,25 +1066,33 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol<Clientbo
|
||||
final String channel = wrapper.read(Type.STRING); // channel
|
||||
short length = wrapper.read(Type.SHORT); // length
|
||||
|
||||
switch (channel) {
|
||||
case "MC|BEdit":
|
||||
case "MC|BSign":
|
||||
itemRewriter.handleItemToServer(wrapper.passthrough(Types1_7_6.ITEM));
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
break;
|
||||
case "MC|AdvCdm":
|
||||
final byte type = wrapper.read(Type.BYTE); // command block type
|
||||
if (type == 0) {
|
||||
wrapper.passthrough(Type.INT); // x
|
||||
wrapper.passthrough(Type.INT); // y
|
||||
wrapper.passthrough(Type.INT); // z
|
||||
wrapper.passthrough(Type.STRING); // command
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
break;
|
||||
try {
|
||||
switch (channel) {
|
||||
case "MC|BEdit":
|
||||
case "MC|BSign":
|
||||
itemRewriter.handleItemToServer(wrapper.passthrough(Types1_7_6.ITEM));
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
break;
|
||||
case "MC|AdvCdm":
|
||||
final byte type = wrapper.read(Type.BYTE); // command block type
|
||||
if (type == 0) {
|
||||
wrapper.passthrough(Type.INT); // x
|
||||
wrapper.passthrough(Type.INT); // y
|
||||
wrapper.passthrough(Type.INT); // z
|
||||
wrapper.passthrough(Type.STRING); // command
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
length = (short) PacketUtil.calculateLength(wrapper);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.resetReader();
|
||||
|
@ -67,6 +67,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_7_2, ClientboundPackets1_8, ServerboundPackets1_7_2, ServerboundPackets1_8> {
|
||||
|
||||
@ -1108,10 +1109,10 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
||||
this.registerClientbound(ClientboundPackets1_7_2.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final String channel = wrapper.passthrough(Type.STRING); // channel
|
||||
wrapper.read(Type.UNSIGNED_SHORT); // length
|
||||
|
||||
map(Type.STRING); // channel
|
||||
read(Type.UNSIGNED_SHORT); // length
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Type.STRING, 0);
|
||||
switch (channel) {
|
||||
case "MC|Brand": {
|
||||
wrapper.write(Type.STRING, new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8)); // brand
|
||||
@ -1375,59 +1376,67 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
||||
return;
|
||||
}
|
||||
|
||||
switch (channel) {
|
||||
case "MC|BEdit":
|
||||
case "MC|BSign":
|
||||
final Item item = wrapper.read(Type.ITEM1_8); // book
|
||||
itemRewriter.handleItemToServer(item);
|
||||
wrapper.write(Types1_7_6.ITEM, item); // book
|
||||
break;
|
||||
case "MC|Brand":
|
||||
case "MC|ItemName":
|
||||
final String content = wrapper.read(Type.STRING); // client brand or item name
|
||||
wrapper.write(Type.REMAINING_BYTES, content.getBytes(StandardCharsets.UTF_8)); // client brand or item name
|
||||
break;
|
||||
case "MC|AdvCdm":
|
||||
final byte type = wrapper.passthrough(Type.BYTE); // command block type (0 = Block, 1 = Minecart)
|
||||
if (type == 0) {
|
||||
wrapper.passthrough(Type.INT); // x
|
||||
wrapper.passthrough(Type.INT); // y
|
||||
wrapper.passthrough(Type.INT); // z
|
||||
} else if (type == 1) {
|
||||
wrapper.passthrough(Type.INT); // entity id
|
||||
} else {
|
||||
ViaLegacy.getPlatform().getLogger().warning("Unknown 1.8 command block type: " + type);
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
wrapper.passthrough(Type.STRING); // command
|
||||
wrapper.read(Type.BOOLEAN); // track output
|
||||
break;
|
||||
case "REGISTER":
|
||||
case "UNREGISTER":
|
||||
byte[] channels = wrapper.read(Type.REMAINING_BYTES);
|
||||
|
||||
if (ViaLegacy.getConfig().isIgnoreLong1_8ChannelNames()) {
|
||||
final String[] registeredChannels = new String(channels, StandardCharsets.UTF_8).split("\0");
|
||||
final List<String> validChannels = new ArrayList<>(registeredChannels.length);
|
||||
for (String registeredChannel : registeredChannels) {
|
||||
if (registeredChannel.length() > 16) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaLegacy.getPlatform().getLogger().warning("Ignoring incoming plugin channel register of '" + registeredChannel + "', as it is longer than 16 characters");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
validChannels.add(registeredChannel);
|
||||
}
|
||||
if (validChannels.isEmpty()) {
|
||||
try {
|
||||
switch (channel) {
|
||||
case "MC|BEdit":
|
||||
case "MC|BSign":
|
||||
final Item item = wrapper.read(Type.ITEM1_8); // book
|
||||
itemRewriter.handleItemToServer(item);
|
||||
wrapper.write(Types1_7_6.ITEM, item); // book
|
||||
break;
|
||||
case "MC|Brand":
|
||||
case "MC|ItemName":
|
||||
final String content = wrapper.read(Type.STRING); // client brand or item name
|
||||
wrapper.write(Type.REMAINING_BYTES, content.getBytes(StandardCharsets.UTF_8)); // client brand or item name
|
||||
break;
|
||||
case "MC|AdvCdm":
|
||||
final byte type = wrapper.passthrough(Type.BYTE); // command block type (0 = Block, 1 = Minecart)
|
||||
if (type == 0) {
|
||||
wrapper.passthrough(Type.INT); // x
|
||||
wrapper.passthrough(Type.INT); // y
|
||||
wrapper.passthrough(Type.INT); // z
|
||||
} else if (type == 1) {
|
||||
wrapper.passthrough(Type.INT); // entity id
|
||||
} else {
|
||||
ViaLegacy.getPlatform().getLogger().warning("Unknown 1.8 command block type: " + type);
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
channels = Joiner.on('\0').join(validChannels).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
wrapper.passthrough(Type.STRING); // command
|
||||
wrapper.read(Type.BOOLEAN); // track output
|
||||
break;
|
||||
case "REGISTER":
|
||||
case "UNREGISTER":
|
||||
byte[] channels = wrapper.read(Type.REMAINING_BYTES);
|
||||
|
||||
wrapper.write(Type.REMAINING_BYTES, channels); // data
|
||||
break;
|
||||
if (ViaLegacy.getConfig().isIgnoreLong1_8ChannelNames()) {
|
||||
final String[] registeredChannels = new String(channels, StandardCharsets.UTF_8).split("\0");
|
||||
final List<String> validChannels = new ArrayList<>(registeredChannels.length);
|
||||
for (String registeredChannel : registeredChannels) {
|
||||
if (registeredChannel.length() > 16) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaLegacy.getPlatform().getLogger().warning("Ignoring incoming plugin channel register of '" + registeredChannel + "', as it is longer than 16 characters");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
validChannels.add(registeredChannel);
|
||||
}
|
||||
if (validChannels.isEmpty()) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
channels = Joiner.on('\0').join(validChannels).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
wrapper.write(Type.REMAINING_BYTES, channels); // data
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
final short length = (short) PacketUtil.calculateLength(wrapper);
|
||||
|
Loading…
Reference in New Issue
Block a user