Skip to content
Permalink
Browse files

Experimental: Correct a possible race condition with Spigot.

  • Loading branch information
aadnk committed Sep 28, 2013
1 parent 1b1f36c commit 75f6cff5a5ceac421523fd0aeeaa3acddeb0e987
@@ -262,6 +262,14 @@ public Object getNetworkManager() {
return networkManagerRef.getValue();
}

/**
* Retrieve the current server handler (PlayerConnection).
* @return Current server handler.
*/
public Object getServerHandler() {
return serverHandlerRef.getValue();
}

/**
* Set the current network manager.
* @param value - new network manager.
@@ -16,6 +16,7 @@
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.proxy.NoOp;
@@ -293,10 +294,32 @@ public PacketInjector getPacketInjector() {
/**
* Retrieve the currently registered injector for the given player.
* @param player - injected player.
* @param createNew - whether or not to create a new injector if the current is missing.
* @return The injector.
*/
NetworkObjectInjector getInjector(Player player) {
return playerInjector.get(player);
NetworkObjectInjector getInjector(Player player, boolean createNew) {
NetworkObjectInjector injector = playerInjector.get(player);

if (injector == null && createNew) {
// Check for temporary players ..
if ((player instanceof Factory))
throw new IllegalArgumentException("Cannot inject tempoary player " + player);

try {
NetworkObjectInjector created = new NetworkObjectInjector(
classLoader, filterImpossibleWarnings(reporter), null, invoker, null);

created.initializePlayer(player);

if (created.getNetworkManager() == null)
throw new PlayerLoggedOutException("Player " + player + " has logged out.");
injector = saveInjector(created.getNetworkManager(), created);

} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot create dummy injector.", e);
}
}
return injector;
}

/**
@@ -490,7 +513,7 @@ void injectPlayer(Player player) {
* @param player - the player to uninject.
*/
void uninjectPlayer(Player player) {
final NetworkObjectInjector injector = getInjector(player);
final NetworkObjectInjector injector = getInjector(player, false);

if (player != null && injector != null) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@@ -513,18 +536,15 @@ public void run() {
* @throws InvocationTargetException If anything went wrong.
*/
void sendServerPacket(Player reciever, PacketContainer packet, NetworkMarker marker, boolean filters) throws InvocationTargetException {
NetworkObjectInjector networkObject = getInjector(reciever);
NetworkObjectInjector networkObject = getInjector(reciever, true);

// If TRUE, process this packet like any other
if (filters)
ignoredPackets.remove(packet.getHandle());
else
ignoredPackets.add(packet.getHandle());

if (networkObject != null)
networkObject.sendServerPacket(packet.getHandle(), marker, filters);
else
throw new PlayerLoggedOutException("Player " + reciever + " has logged out");
networkObject.sendServerPacket(packet.getHandle(), marker, filters);
}

/**
@@ -535,15 +555,11 @@ void sendServerPacket(Player reciever, PacketContainer packet, NetworkMarker mar
* @throws InvocationTargetException Minecraft threw an exception.
*/
void processPacket(Player player, Object mcPacket) throws IllegalAccessException, InvocationTargetException {
NetworkObjectInjector networkObject = getInjector(player);
NetworkObjectInjector networkObject = getInjector(player, true);

// We will always ignore this packet
ignoredPackets.add(mcPacket);

if (networkObject != null)
networkObject.processPacket(mcPacket);
else
throw new PlayerLoggedOutException("Player " + player + " has logged out");
networkObject.processPacket(mcPacket);
}

/**

0 comments on commit 75f6cff

Please sign in to comment.
You can’t perform that action at this time.