Archiviert
13
0

Moved classes that inject into the server thread to a separate package

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-02-25 20:28:57 +01:00
Ursprung 89d2604ce2
Commit 8c2f6bddd8
12 geänderte Dateien mit 78 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import net.sf.cglib.proxy.Factory;
import org.bukkit.Server; import org.bukkit.Server;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.injector.server.InjectedServerSocket;
import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.ObjectWriter; import com.comphenix.protocol.reflect.ObjectWriter;

Datei anzeigen

@ -25,6 +25,8 @@ import org.bukkit.entity.Player;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.server.InjectedServerSocket;
import com.comphenix.protocol.injector.server.SocketInjector;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;

Datei anzeigen

@ -39,7 +39,7 @@ import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.ListenerInvoker; import com.comphenix.protocol.injector.ListenerInvoker;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
import com.comphenix.protocol.injector.player.TemporaryPlayerFactory.InjectContainer; import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
/** /**
* Injection method that overrides the NetworkHandler itself, and its queue-method. * Injection method that overrides the NetworkHandler itself, and its queue-method.
@ -91,10 +91,8 @@ public class NetworkObjectInjector extends PlayerInjector {
if (tempPlayerFactory == null) if (tempPlayerFactory == null)
tempPlayerFactory = new TemporaryPlayerFactory(); tempPlayerFactory = new TemporaryPlayerFactory();
// Create and associate this fake player with this network injector // Create and associate the fake player with this network injector
Player player = tempPlayerFactory.createTemporaryPlayer(server); return tempPlayerFactory.createTemporaryPlayer(server, this);
((InjectContainer) player).setInjector(this);
return player;
} }
@Override @Override

Datei anzeigen

@ -37,6 +37,7 @@ import com.comphenix.protocol.injector.BukkitUnwrapper;
import com.comphenix.protocol.injector.GamePhase; import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.ListenerInvoker; import com.comphenix.protocol.injector.ListenerInvoker;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
import com.comphenix.protocol.injector.server.SocketInjector;
import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;

Datei anzeigen

@ -36,7 +36,9 @@ import com.comphenix.protocol.injector.GamePhase;
import com.comphenix.protocol.injector.ListenerInvoker; import com.comphenix.protocol.injector.ListenerInvoker;
import com.comphenix.protocol.injector.PlayerLoggedOutException; import com.comphenix.protocol.injector.PlayerLoggedOutException;
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks; import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
import com.comphenix.protocol.injector.player.TemporaryPlayerFactory.InjectContainer; import com.comphenix.protocol.injector.server.InjectedServerSocket;
import com.comphenix.protocol.injector.server.SocketInjector;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -104,7 +106,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
public void postWorldLoaded() { public void postWorldLoaded() {
// This will actually create a socket and a seperate thread ... // This will actually create a socket and a seperate thread ...
if (serverSocket != null) { if (serverSocket != null) {
serverSocket.cycleServerPorts(); serverSocket.postWorldLoaded();
} }
} }
@ -498,16 +500,13 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
if (injector == null) { if (injector == null) {
// Try getting it from the player itself // Try getting it from the player itself
if (player instanceof InjectContainer) { SocketInjector socket = TemporaryPlayerFactory.getInjectorFromPlayer(player);
SocketInjector socket = ((InjectContainer) player).getInjector();
// It may be a player injector too // Only accept it if it's a player injector
if (socket instanceof PlayerInjector) if (!(socket instanceof PlayerInjector)) {
return (PlayerInjector) socket; socket = serverSocket.getSocketInjector(player.getAddress());
} }
SocketInjector socket = serverSocket.getSocketInjector(player.getAddress());
// Ensure that it is a player injector // Ensure that it is a player injector
if (socket instanceof PlayerInjector) if (socket instanceof PlayerInjector)
return (PlayerInjector) socket; return (PlayerInjector) socket;

Datei anzeigen

@ -1,4 +1,4 @@
package com.comphenix.protocol.injector.player; package com.comphenix.protocol.injector.server;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;

Datei anzeigen

@ -1,4 +1,4 @@
package com.comphenix.protocol.injector.player; package com.comphenix.protocol.injector.server;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

Datei anzeigen

@ -1,4 +1,4 @@
package com.comphenix.protocol.injector.player; package com.comphenix.protocol.injector.server;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.Socket; import java.net.Socket;

Datei anzeigen

@ -0,0 +1,19 @@
package com.comphenix.protocol.injector.server;
/**
* Able to store a socket injector.
* <p>
* A necessary hack.
* @author Kristian
*/
class InjectContainer {
private SocketInjector injector;
public SocketInjector getInjector() {
return injector;
}
public void setInjector(SocketInjector injector) {
this.injector = injector;
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package com.comphenix.protocol.injector.player; package com.comphenix.protocol.injector.server;
import java.io.FilterInputStream; import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
@ -23,7 +23,6 @@ import org.bukkit.entity.Player;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.Packets;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.injector.player.TemporaryPlayerFactory.InjectContainer;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
@ -234,12 +233,19 @@ public class InjectedServerSocket {
} }
} }
/**
* Invoked when the world has loaded.
*/
public void postWorldLoaded() {
cycleServerPorts();
}
/** /**
* Invoked when we need to cycle the injected server port. * Invoked when we need to cycle the injected server port.
* <p> * <p>
* This uses a fairly significant hack - we connect to our own server. * This uses a fairly significant hack - we connect to our own server.
*/ */
public void cycleServerPorts() { private void cycleServerPorts() {
final ServerSocket serverSocket = (ServerSocket) injectedServerSocket.getValue(); final ServerSocket serverSocket = (ServerSocket) injectedServerSocket.getValue();
final SocketAddress address = new InetSocketAddress("127.0.0.1", serverSocket.getLocalPort()); final SocketAddress address = new InetSocketAddress("127.0.0.1", serverSocket.getLocalPort());
@ -423,7 +429,7 @@ public class InjectedServerSocket {
injectedServerSocket.revertValue(); injectedServerSocket.revertValue();
// This is going to suck // This is going to suck
//cycleServerPorts(); cycleServerPorts();
} }
} }
} }

Datei anzeigen

@ -1,4 +1,4 @@
package com.comphenix.protocol.injector.player; package com.comphenix.protocol.injector.server;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.Socket; import java.net.Socket;
@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
* *
* @author Kristian * @author Kristian
*/ */
interface SocketInjector { public interface SocketInjector {
/** /**
* Retrieve the associated socket of this player. * Retrieve the associated socket of this player.
* @return The associated socket. * @return The associated socket.

Datei anzeigen

@ -15,7 +15,7 @@
* 02111-1307 USA * 02111-1307 USA
*/ */
package com.comphenix.protocol.injector.player; package com.comphenix.protocol.injector.server;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -36,25 +36,7 @@ import com.comphenix.protocol.reflect.FieldAccessException;
/** /**
* Create fake player instances that represents pre-authenticated clients. * Create fake player instances that represents pre-authenticated clients.
*/ */
class TemporaryPlayerFactory { public class TemporaryPlayerFactory {
/**
* Able to store a socket injector.
* <p>
* A necessary hack.
* @author Kristian
*/
public static class InjectContainer {
private SocketInjector injector;
public SocketInjector getInjector() {
return injector;
}
public void setInjector(SocketInjector injector) {
this.injector = injector;
}
}
// Helpful constructors // Helpful constructors
private final PacketConstructor chatPacket; private final PacketConstructor chatPacket;
@ -65,6 +47,18 @@ class TemporaryPlayerFactory {
chatPacket = PacketConstructor.DEFAULT.withPacket(3, new Object[] { "DEMO" }); chatPacket = PacketConstructor.DEFAULT.withPacket(3, new Object[] { "DEMO" });
} }
/**
* Retrieve the injector from a given player if it contains one.
* @param player - the player that may contain a reference to a player injector.
* @return The referenced player injector, or NULL if none can be found.
*/
public static SocketInjector getInjectorFromPlayer(Player player) {
if (player instanceof InjectContainer) {
return ((InjectContainer) player).getInjector();
}
return null;
}
/** /**
* Construct a temporary player that supports a subset of every player command. * Construct a temporary player that supports a subset of every player command.
* <p> * <p>
@ -164,6 +158,19 @@ class TemporaryPlayerFactory {
return (Player) ex.create(); return (Player) ex.create();
} }
/**
* Construct a temporary player with the given associated socket injector.
* @param server - the parent server.
* @param injector - the referenced socket injector.
* @return The temporary player.
*/
public Player createTemporaryPlayer(Server server, SocketInjector injector) {
Player temporary = createTemporaryPlayer(server);
((InjectContainer) temporary).setInjector(injector);
return temporary;
}
/** /**
* Send a message to the given client. * Send a message to the given client.
* @param injector - the injector representing the client. * @param injector - the injector representing the client.