mirror of
https://github.com/ViaVersion/ViaLegacy.git
synced 2025-03-11 13:22:57 +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;
|
package net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
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.ProtocolInfo;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||||
@ -273,6 +274,7 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol<ClientboundPackets
|
|||||||
final String channel = wrapper.read(Types1_6_4.STRING); // channel
|
final String channel = wrapper.read(Types1_6_4.STRING); // channel
|
||||||
short length = wrapper.read(Type.SHORT); // length
|
short length = wrapper.read(Type.SHORT); // length
|
||||||
|
|
||||||
|
try {
|
||||||
if (channel.equals("MC|TrList")) {
|
if (channel.equals("MC|TrList")) {
|
||||||
wrapper.passthrough(Type.INT); // window Id
|
wrapper.passthrough(Type.INT); // window Id
|
||||||
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
||||||
@ -286,6 +288,13 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol<ClientboundPackets
|
|||||||
}
|
}
|
||||||
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();
|
wrapper.resetReader();
|
||||||
wrapper.write(Types1_6_4.STRING, channel); // channel
|
wrapper.write(Types1_6_4.STRING, channel); // channel
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2;
|
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.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
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.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
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> {
|
public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_5_2, ClientboundPackets1_6_1, ServerboundPackets1_5_2, ServerboundPackets1_6_4> {
|
||||||
|
|
||||||
@ -302,6 +304,7 @@ public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_
|
|||||||
String channel = wrapper.read(Types1_6_4.STRING); // channel
|
String channel = wrapper.read(Types1_6_4.STRING); // channel
|
||||||
short length = wrapper.read(Type.SHORT); // length
|
short length = wrapper.read(Type.SHORT); // length
|
||||||
|
|
||||||
|
try {
|
||||||
if (channel.equals("MC|TPack")) {
|
if (channel.equals("MC|TPack")) {
|
||||||
channel = "MC|RPack";
|
channel = "MC|RPack";
|
||||||
final String[] data = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); // data
|
final String[] data = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); // data
|
||||||
@ -315,6 +318,13 @@ public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_
|
|||||||
wrapper.write(Type.REMAINING_BYTES, url.getBytes(StandardCharsets.UTF_8));
|
wrapper.write(Type.REMAINING_BYTES, url.getBytes(StandardCharsets.UTF_8));
|
||||||
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();
|
wrapper.resetReader();
|
||||||
wrapper.write(Types1_6_4.STRING, channel); // channel
|
wrapper.write(Types1_6_4.STRING, channel); // channel
|
||||||
|
@ -749,6 +749,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol<Clientbo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (channel.equals("MC|TrList")) {
|
if (channel.equals("MC|TrList")) {
|
||||||
wrapper.passthrough(Type.INT); // window id
|
wrapper.passthrough(Type.INT); // window id
|
||||||
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
final int count = wrapper.passthrough(Type.UNSIGNED_BYTE); // count
|
||||||
@ -762,6 +763,13 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol<Clientbo
|
|||||||
}
|
}
|
||||||
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();
|
wrapper.resetReader();
|
||||||
wrapper.write(Type.STRING, channel); // channel
|
wrapper.write(Type.STRING, channel); // channel
|
||||||
@ -1058,6 +1066,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol<Clientbo
|
|||||||
final String channel = wrapper.read(Type.STRING); // channel
|
final String channel = wrapper.read(Type.STRING); // channel
|
||||||
short length = wrapper.read(Type.SHORT); // length
|
short length = wrapper.read(Type.SHORT); // length
|
||||||
|
|
||||||
|
try {
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case "MC|BEdit":
|
case "MC|BEdit":
|
||||||
case "MC|BSign":
|
case "MC|BSign":
|
||||||
@ -1078,6 +1087,13 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol<Clientbo
|
|||||||
length = (short) PacketUtil.calculateLength(wrapper);
|
length = (short) PacketUtil.calculateLength(wrapper);
|
||||||
break;
|
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();
|
wrapper.resetReader();
|
||||||
wrapper.write(Types1_6_4.STRING, channel); // channel
|
wrapper.write(Types1_6_4.STRING, channel); // channel
|
||||||
|
@ -67,6 +67,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types
|
|||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
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> {
|
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() {
|
this.registerClientbound(ClientboundPackets1_7_2.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
handler(wrapper -> {
|
map(Type.STRING); // channel
|
||||||
final String channel = wrapper.passthrough(Type.STRING); // channel
|
read(Type.UNSIGNED_SHORT); // length
|
||||||
wrapper.read(Type.UNSIGNED_SHORT); // length
|
handlerSoftFail(wrapper -> {
|
||||||
|
final String channel = wrapper.get(Type.STRING, 0);
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case "MC|Brand": {
|
case "MC|Brand": {
|
||||||
wrapper.write(Type.STRING, new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8)); // brand
|
wrapper.write(Type.STRING, new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8)); // brand
|
||||||
@ -1375,6 +1376,7 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case "MC|BEdit":
|
case "MC|BEdit":
|
||||||
case "MC|BSign":
|
case "MC|BSign":
|
||||||
@ -1429,6 +1431,13 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
wrapper.write(Type.REMAINING_BYTES, channels); // data
|
wrapper.write(Type.REMAINING_BYTES, channels); // data
|
||||||
break;
|
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);
|
final short length = (short) PacketUtil.calculateLength(wrapper);
|
||||||
wrapper.resetReader();
|
wrapper.resetReader();
|
||||||
|
Loading…
Reference in New Issue
Block a user