3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Use new method for finding cause, might need updating with disconnect. Can't replicate disconnect spam on any version on my machine. Also move to JSON for all because older versions don't have GSON :( in main package

Dieser Commit ist enthalten in:
Myles 2016-03-03 19:24:37 +00:00
Ursprung fee986d215
Commit 1a90f0eb28
4 geänderte Dateien mit 37 neuen und 38 gelöschten Zeilen

Datei anzeigen

@ -44,13 +44,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (!(cause.getCause().getCause() instanceof CancelException)) { if (PacketUtil.containsCause(cause, CancelException.class)) return;
if (!(cause.getCause() instanceof CancelException)) { super.exceptionCaught(ctx, cause);
if (!(cause instanceof CancelException)) {
super.exceptionCaught(ctx, cause);
}
}
}
} }
} }

Datei anzeigen

@ -72,12 +72,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (!(cause.getCause().getCause() instanceof CancelException)) { if (PacketUtil.containsCause(cause, CancelException.class)) return;
if (!(cause.getCause() instanceof CancelException)) { super.exceptionCaught(ctx, cause);
if (!(cause instanceof CancelException)) {
super.exceptionCaught(ctx, cause);
}
}
}
} }
} }

Datei anzeigen

@ -1,15 +1,12 @@
package us.myles.ViaVersion.transformers; package us.myles.ViaVersion.transformers;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.spacehq.mc.protocol.data.game.chunk.Column; import org.spacehq.mc.protocol.data.game.chunk.Column;
import org.spacehq.mc.protocol.util.NetUtil; import org.spacehq.mc.protocol.util.NetUtil;
import us.myles.ViaVersion.CancelException; import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.ConnectionInfo; import us.myles.ViaVersion.ConnectionInfo;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
@ -28,7 +25,8 @@ import java.util.*;
import static us.myles.ViaVersion.util.PacketUtil.*; import static us.myles.ViaVersion.util.PacketUtil.*;
public class OutgoingTransformer { public class OutgoingTransformer {
private static Gson gson = new Gson(); private static JSONParser parser = new JSONParser();
private final ConnectionInfo info; private final ConnectionInfo info;
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance(); private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
private boolean cancel = false; private boolean cancel = false;
@ -65,11 +63,11 @@ public class OutgoingTransformer {
int catid = 0; int catid = 0;
String newname = name; String newname = name;
if (effect != null) { if (effect != null) {
if(effect.isBreakPlaceSound()) { if (effect.isBreakPlaceSound()) {
input.readBytes(input.readableBytes()); input.readBytes(input.readableBytes());
output.clear(); output.clear();
return; return;
} }
catid = effect.getCategory().getId(); catid = effect.getCategory().getId();
newname = effect.getNewName(); newname = effect.getNewName();
} }
@ -88,12 +86,12 @@ public class OutgoingTransformer {
if (!vehicleMap.containsKey(passenger)) if (!vehicleMap.containsKey(passenger))
throw new CancelException(); throw new CancelException();
vehicle = vehicleMap.remove(passenger); vehicle = vehicleMap.remove(passenger);
writeVarInt(vehicle,output); writeVarInt(vehicle, output);
writeVarIntArray(Collections.<Integer>emptyList(), output); writeVarIntArray(Collections.<Integer>emptyList(), output);
} else{ } else {
writeVarInt(vehicle, output); writeVarInt(vehicle, output);
writeVarIntArray(Collections.singletonList(passenger), output); writeVarIntArray(Collections.singletonList(passenger), output);
vehicleMap.put(passenger,vehicle); vehicleMap.put(passenger, vehicle);
} }
return; return;
} }
@ -193,9 +191,14 @@ public class OutgoingTransformer {
if (packet == PacketType.STATUS_RESPONSE) { if (packet == PacketType.STATUS_RESPONSE) {
String original = PacketUtil.readString(input); String original = PacketUtil.readString(input);
JsonObject object = gson.fromJson(original, JsonObject.class); try {
object.get("version").getAsJsonObject().addProperty("protocol", info.getProtocol()); JSONObject json = (JSONObject) parser.parse(original);
PacketUtil.writeString(gson.toJson(object), output); JSONObject version = (JSONObject) json.get("version");
version.put("protocol", info.getProtocol());
PacketUtil.writeString(json.toJSONString(), output);
} catch (ParseException e) {
e.printStackTrace();
}
return; return;
} }
if (packet == PacketType.LOGIN_SUCCESS) { if (packet == PacketType.LOGIN_SUCCESS) {
@ -522,11 +525,10 @@ public class OutgoingTransformer {
line = "{\"text\":" + line + "}"; line = "{\"text\":" + line + "}";
} }
try { try {
new JSONParser().parse(line); parser.parse(line);
} } catch (org.json.simple.parser.ParseException e) {
catch (org.json.simple.parser.ParseException e) { System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github!");
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github!"); return "{\"text\":\"\"}";
return "{\"text\":\"\"}";
} }
return line; return line;
} }

Datei anzeigen

@ -390,7 +390,7 @@ public class PacketUtil {
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
public static long[] readBlockPosition(ByteBuf buf) { public static long[] readBlockPosition(ByteBuf buf) {
@ -414,4 +414,12 @@ public class PacketUtil {
return data; return data;
} }
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
while (t != null) {
t = t.getCause();
if (c.isAssignableFrom(t.getClass())) return true;
}
return false;
}
} }