mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-23 16:51:36 +01:00
Revert changes to channel injection
This commit is contained in:
parent
a748a95197
commit
a1b989cb3a
@ -654,7 +654,7 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
return executorSync;
|
return executorSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Logging
|
// ---- Logging Methods
|
||||||
|
|
||||||
public static void log(Level level, String message, Object... args) {
|
public static void log(Level level, String message, Object... args) {
|
||||||
logger.log(level, MessageFormat.format(message, args));
|
logger.log(level, MessageFormat.format(message, args));
|
||||||
|
@ -14,7 +14,6 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
|||||||
import io.netty.util.concurrent.GenericFutureListener;
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import io.netty.util.internal.TypeParameterMatcher;
|
import io.netty.util.internal.TypeParameterMatcher;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
@ -85,10 +84,9 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
// The factory that created this injector
|
// The factory that created this injector
|
||||||
private InjectionFactory factory;
|
private InjectionFactory factory;
|
||||||
|
|
||||||
// The player
|
// The player, or temporary player
|
||||||
private WeakReference<Player> player;
|
private Player player;
|
||||||
private WeakReference<Player> updated;
|
private Player updated;
|
||||||
private String playerName;
|
|
||||||
|
|
||||||
// The player connection
|
// The player connection
|
||||||
private Object playerConnection;
|
private Object playerConnection;
|
||||||
@ -151,7 +149,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
* @param factory - the factory that created this injector
|
* @param factory - the factory that created this injector
|
||||||
*/
|
*/
|
||||||
public ChannelInjector(Player player, Object networkManager, Channel channel, ChannelListener channelListener, InjectionFactory factory) {
|
public ChannelInjector(Player player, Object networkManager, Channel channel, ChannelListener channelListener, InjectionFactory factory) {
|
||||||
this.player = new WeakReference<Player>(Preconditions.checkNotNull(player, "player cannot be NULL"));
|
this.player = Preconditions.checkNotNull(player, "player cannot be NULL");
|
||||||
this.networkManager = Preconditions.checkNotNull(networkManager, "networkMananger cannot be NULL");
|
this.networkManager = Preconditions.checkNotNull(networkManager, "networkMananger cannot be NULL");
|
||||||
this.originalChannel = Preconditions.checkNotNull(channel, "channel cannot be NULL");
|
this.originalChannel = Preconditions.checkNotNull(channel, "channel cannot be NULL");
|
||||||
this.channelListener = Preconditions.checkNotNull(channelListener, "channelListener cannot be NULL");
|
this.channelListener = Preconditions.checkNotNull(channelListener, "channelListener cannot be NULL");
|
||||||
@ -488,11 +486,6 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
// Reset queue
|
// Reset queue
|
||||||
finishQueue.clear();
|
finishQueue.clear();
|
||||||
|
|
||||||
if (player.get() == null) {
|
|
||||||
ProtocolLibrary.log("Failed to intercept client packet for {0}: Invalid player.", playerName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ListIterator<Object> it = packets.listIterator(); it.hasNext(); ) {
|
for (ListIterator<Object> it = packets.listIterator(); it.hasNext(); ) {
|
||||||
Object input = it.next();
|
Object input = it.next();
|
||||||
Class<?> packetClass = input.getClass();
|
Class<?> packetClass = input.getClass();
|
||||||
@ -505,7 +498,6 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
byteBuffer.resetReaderIndex();
|
byteBuffer.resetReaderIndex();
|
||||||
marker = new NettyNetworkMarker(ConnectionSide.CLIENT_SIDE, getBytes(byteBuffer));
|
marker = new NettyNetworkMarker(ConnectionSide.CLIENT_SIDE, getBytes(byteBuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketEvent output = channelListener.onPacketReceiving(this, input, marker);
|
PacketEvent output = channelListener.onPacketReceiving(this, input, marker);
|
||||||
|
|
||||||
// Handle packet changes
|
// Handle packet changes
|
||||||
@ -600,7 +592,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
*/
|
*/
|
||||||
private void disconnect(String message) {
|
private void disconnect(String message) {
|
||||||
// If we're logging in, we can only close the channel
|
// If we're logging in, we can only close the channel
|
||||||
if (playerConnection == null || player.get() instanceof Factory) {
|
if (playerConnection == null || player instanceof Factory) {
|
||||||
originalChannel.disconnect();
|
originalChannel.disconnect();
|
||||||
} else {
|
} else {
|
||||||
// Call the disconnect method
|
// Call the disconnect method
|
||||||
@ -632,7 +624,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
private void invokeSendPacket(Object packet) {
|
private void invokeSendPacket(Object packet) {
|
||||||
// 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.get() instanceof Factory) {
|
if (player instanceof Factory) {
|
||||||
MinecraftMethods.getNetworkManagerHandleMethod().invoke(networkManager, packet, new GenericFutureListener[0]);
|
MinecraftMethods.getNetworkManagerHandleMethod().invoke(networkManager, packet, new GenericFutureListener[0]);
|
||||||
} else {
|
} else {
|
||||||
MinecraftMethods.getSendPacketMethod().invoke(getPlayerConnection(), packet);
|
MinecraftMethods.getSendPacketMethod().invoke(getPlayerConnection(), packet);
|
||||||
@ -682,7 +674,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
*/
|
*/
|
||||||
private Object getPlayerConnection() {
|
private Object getPlayerConnection() {
|
||||||
if (playerConnection == null) {
|
if (playerConnection == null) {
|
||||||
playerConnection = MinecraftFields.getPlayerConnection(player.get());
|
playerConnection = MinecraftFields.getPlayerConnection(player);
|
||||||
}
|
}
|
||||||
return playerConnection;
|
return playerConnection;
|
||||||
}
|
}
|
||||||
@ -701,7 +693,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player.get();
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -710,7 +702,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
this.player = new WeakReference<Player>(Preconditions.checkNotNull(player, "player cannot be null"));
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -719,7 +711,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setUpdatedPlayer(Player updated) {
|
public void setUpdatedPlayer(Player updated) {
|
||||||
this.updated = new WeakReference<Player>(Preconditions.checkNotNull(updated, "updated cannot be null"));;
|
this.updated = updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -760,7 +752,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
// we end up with a deadlock. The main thread is waiting for the worker thread to process the task, and
|
// we end up with a deadlock. The main thread is waiting for the worker thread to process the task, and
|
||||||
// the worker thread is waiting for the main thread to finish executing PlayerQuitEvent.
|
// the worker thread is waiting for the main thread to finish executing PlayerQuitEvent.
|
||||||
//
|
//
|
||||||
// TLDR: Concurrency is hard.
|
// TLDR: Concurrenty is hard.
|
||||||
executeInChannelThread(new Runnable() {
|
executeInChannelThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -775,14 +767,14 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Clear cache
|
// Clear cache
|
||||||
factory.invalidate(player.get());
|
factory.invalidate(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear player references
|
// dmulloy2 - clear player instances
|
||||||
// Should help fix memory leaks
|
// Should fix memory leaks
|
||||||
player.clear();
|
this.player = null;
|
||||||
updated.clear();
|
this.updated = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -853,12 +845,12 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return injector.player.get();
|
return injector.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getUpdatedPlayer() {
|
public Player getUpdatedPlayer() {
|
||||||
return injector.updated.get();
|
return injector.updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -868,7 +860,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUpdatedPlayer(Player updatedPlayer) {
|
public void setUpdatedPlayer(Player updatedPlayer) {
|
||||||
injector.player = new WeakReference<Player>(updatedPlayer);
|
injector.player = updatedPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelInjector getChannelInjector() {
|
public ChannelInjector getChannelInjector() {
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package com.comphenix.protocol.reflect;
|
package com.comphenix.protocol.reflect;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||||
@ -185,7 +184,7 @@ public class VolatileField {
|
|||||||
currentSet = false;
|
currentSet = false;
|
||||||
} else {
|
} else {
|
||||||
// This can be a bad sign
|
// This can be a bad sign
|
||||||
ProtocolLibrary.log(Level.WARNING, "Unable to switch %s to %s. Expected %s but got %s.",
|
ProtocolLibrary.log("Unable to switch {0} to {1}. Expected {2}, but got {3}.",
|
||||||
getField().toGenericString(), previous, current, getValue());
|
getField().toGenericString(), previous, current, getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,13 @@ package com.comphenix.protocol.reflect.instances;
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import net.sf.cglib.proxy.Enhancer;
|
import net.sf.cglib.proxy.Enhancer;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
@ -281,7 +283,7 @@ public class DefaultInstances implements InstanceProvider {
|
|||||||
|
|
||||||
// Did we break the non-null contract?
|
// Did we break the non-null contract?
|
||||||
if (params[i] == null && nonNull) {
|
if (params[i] == null && nonNull) {
|
||||||
System.out.println("Nonnull contract broken.");
|
ProtocolLibrary.log(Level.WARNING, "Nonnull contract broken.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,8 +330,6 @@ public class DefaultInstances implements InstanceProvider {
|
|||||||
try {
|
try {
|
||||||
return constructor.newInstance(params);
|
return constructor.newInstance(params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// System.out.println("Failed to create instance " + constructor);
|
|
||||||
// e.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
|||||||
// this.secondaryValue = parameters.length > 1 ? Accessors.getFieldAccessor(spigotClass, "value2", true) : null;
|
// this.secondaryValue = parameters.length > 1 ? Accessors.getFieldAccessor(spigotClass, "value2", true) : null;
|
||||||
//
|
//
|
||||||
// } catch (ClassNotFoundException e) {
|
// } catch (ClassNotFoundException e) {
|
||||||
// System.out.println("[ProtocolLib] Unable to find " + className);
|
// ProtocolLibrary.log(Level.WARNING, "Unable to find " + className);
|
||||||
// this.spigotClass = null;
|
// this.spigotClass = null;
|
||||||
// }
|
// }
|
||||||
// this.typeId = typeId;
|
// this.typeId = typeId;
|
||||||
|
Loading…
Reference in New Issue
Block a user