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

This commit is contained in:
Myles 2016-03-03 19:24:37 +00:00
parent fee986d215
commit 1a90f0eb28
4 changed files with 37 additions and 38 deletions

View File

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

View File

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

View File

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

View File

@ -390,7 +390,7 @@ public class PacketUtil {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
return null;
}
public static long[] readBlockPosition(ByteBuf buf) {
@ -414,4 +414,12 @@ public class PacketUtil {
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;
}
}