Archiviert
13
0

Account for new network manager send packet method

Fixes #497
Dieser Commit ist enthalten in:
Dan Mulloy 2018-08-03 22:18:32 -04:00
Ursprung 9df0dd48e4
Commit cf5d9dfc7d
3 geänderte Dateien mit 23 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -1,23 +1,22 @@
package com.comphenix.protocol.utility; package com.comphenix.protocol.utility;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.GenericFutureListener;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.GenericFutureListener;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
/** /**
* Static methods for accessing Minecraft methods. * Static methods for accessing Minecraft methods.
* *
@ -103,10 +102,12 @@ public class MinecraftMethods {
*/ */
public static Method getNetworkManagerHandleMethod() { public static Method getNetworkManagerHandleMethod() {
if (networkManagerHandle == null) { if (networkManagerHandle == null) {
networkManagerHandle = FuzzyReflection.fromClass(MinecraftReflection.getNetworkManagerClass(), true). networkManagerHandle = FuzzyReflection
getMethodByParameters("handle", MinecraftReflection.getPacketClass(), GenericFutureListener[].class); .fromClass(MinecraftReflection.getNetworkManagerClass(), true)
.getMethodByParameters("handle", MinecraftReflection.getPacketClass());
networkManagerHandle.setAccessible(true); networkManagerHandle.setAccessible(true);
} }
return networkManagerHandle; return networkManagerHandle;
} }
@ -170,15 +171,16 @@ public class MinecraftMethods {
// This object will allow us to detect which methods were called // This object will allow us to detect which methods were called
Enhancer enhancer = EnhancerFactory.getInstance().createEnhancer(); Enhancer enhancer = EnhancerFactory.getInstance().createEnhancer();
enhancer.setSuperclass(MinecraftReflection.getPacketDataSerializerClass()); enhancer.setSuperclass(MinecraftReflection.getPacketDataSerializerClass());
enhancer.setCallback(new MethodInterceptor() { enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
@Override if (method.getName().contains("read")) {
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
if (method.getName().contains("read"))
throw new ReadMethodException(); throw new ReadMethodException();
if (method.getName().contains("write"))
throw new WriteMethodException();
return proxy.invokeSuper(obj, args);
} }
if (method.getName().contains("write")) {
throw new WriteMethodException();
}
return proxy.invokeSuper(obj, args);
}); });
// Create our proxy object // Create our proxy object

Datei anzeigen

@ -647,7 +647,7 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
// Attempt to send the packet with NetworkMarker.handle(), or the PlayerConnection if its active // Attempt to send the packet with NetworkMarker.handle(), or the PlayerConnection if its active
try { try {
if (player instanceof Factory) { if (player instanceof Factory) {
MinecraftMethods.getNetworkManagerHandleMethod().invoke(networkManager, packet, new GenericFutureListener[0]); MinecraftMethods.getNetworkManagerHandleMethod().invoke(networkManager, packet);
} else { } else {
MinecraftMethods.getSendPacketMethod().invoke(getPlayerConnection(), packet); MinecraftMethods.getSendPacketMethod().invoke(getPlayerConnection(), packet);
} }

Datei anzeigen

@ -15,7 +15,8 @@ public class MinecraftMethodsTest {
} }
@Test @Test
public void testSendPacketMethod() { public void testSendPacketMethods() {
assertNotNull(MinecraftMethods.getSendPacketMethod()); assertNotNull(MinecraftMethods.getSendPacketMethod());
assertNotNull(MinecraftMethods.getNetworkManagerHandleMethod());
} }
} }