mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-28 05:35:28 +01:00
Moved classes that inject into the server thread to a separate package
This commit is contained in:
parent
89d2604ce2
commit
8c2f6bddd8
@ -27,6 +27,7 @@ import net.sf.cglib.proxy.Factory;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.injector.server.InjectedServerSocket;
|
||||
import com.comphenix.protocol.reflect.FieldUtils;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.ObjectWriter;
|
||||
|
@ -25,6 +25,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
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.utility.MinecraftReflection;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -39,7 +39,7 @@ import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.GamePhase;
|
||||
import com.comphenix.protocol.injector.ListenerInvoker;
|
||||
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.
|
||||
@ -91,10 +91,8 @@ public class NetworkObjectInjector extends PlayerInjector {
|
||||
if (tempPlayerFactory == null)
|
||||
tempPlayerFactory = new TemporaryPlayerFactory();
|
||||
|
||||
// Create and associate this fake player with this network injector
|
||||
Player player = tempPlayerFactory.createTemporaryPlayer(server);
|
||||
((InjectContainer) player).setInjector(this);
|
||||
return player;
|
||||
// Create and associate the fake player with this network injector
|
||||
return tempPlayerFactory.createTemporaryPlayer(server, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,6 +37,7 @@ import com.comphenix.protocol.injector.BukkitUnwrapper;
|
||||
import com.comphenix.protocol.injector.GamePhase;
|
||||
import com.comphenix.protocol.injector.ListenerInvoker;
|
||||
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.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
@ -36,7 +36,9 @@ import com.comphenix.protocol.injector.GamePhase;
|
||||
import com.comphenix.protocol.injector.ListenerInvoker;
|
||||
import com.comphenix.protocol.injector.PlayerLoggedOutException;
|
||||
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.collect.Maps;
|
||||
|
||||
@ -104,7 +106,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
public void postWorldLoaded() {
|
||||
// This will actually create a socket and a seperate thread ...
|
||||
if (serverSocket != null) {
|
||||
serverSocket.cycleServerPorts();
|
||||
serverSocket.postWorldLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
@ -498,16 +500,13 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
|
||||
if (injector == null) {
|
||||
// Try getting it from the player itself
|
||||
if (player instanceof InjectContainer) {
|
||||
SocketInjector socket = ((InjectContainer) player).getInjector();
|
||||
|
||||
// It may be a player injector too
|
||||
if (socket instanceof PlayerInjector)
|
||||
return (PlayerInjector) socket;
|
||||
SocketInjector socket = TemporaryPlayerFactory.getInjectorFromPlayer(player);
|
||||
|
||||
// Only accept it if it's a player injector
|
||||
if (!(socket instanceof PlayerInjector)) {
|
||||
socket = serverSocket.getSocketInjector(player.getAddress());
|
||||
}
|
||||
|
||||
SocketInjector socket = serverSocket.getSocketInjector(player.getAddress());
|
||||
|
||||
|
||||
// Ensure that it is a player injector
|
||||
if (socket instanceof PlayerInjector)
|
||||
return (PlayerInjector) socket;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.comphenix.protocol.injector.player;
|
||||
package com.comphenix.protocol.injector.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
@ -1,4 +1,4 @@
|
||||
package com.comphenix.protocol.injector.player;
|
||||
package com.comphenix.protocol.injector.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
@ -1,4 +1,4 @@
|
||||
package com.comphenix.protocol.injector.player;
|
||||
package com.comphenix.protocol.injector.server;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.Socket;
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.comphenix.protocol.injector.player;
|
||||
package com.comphenix.protocol.injector.server;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
@ -23,7 +23,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
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.FieldUtils;
|
||||
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.
|
||||
* <p>
|
||||
* 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 SocketAddress address = new InetSocketAddress("127.0.0.1", serverSocket.getLocalPort());
|
||||
|
||||
@ -423,7 +429,7 @@ public class InjectedServerSocket {
|
||||
injectedServerSocket.revertValue();
|
||||
|
||||
// This is going to suck
|
||||
//cycleServerPorts();
|
||||
cycleServerPorts();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.comphenix.protocol.injector.player;
|
||||
package com.comphenix.protocol.injector.server;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.Socket;
|
||||
@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
interface SocketInjector {
|
||||
public interface SocketInjector {
|
||||
/**
|
||||
* Retrieve the associated socket of this player.
|
||||
* @return The associated socket.
|
@ -15,7 +15,7 @@
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.comphenix.protocol.injector.player;
|
||||
package com.comphenix.protocol.injector.server;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -36,25 +36,7 @@ import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
/**
|
||||
* Create fake player instances that represents pre-authenticated clients.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public class TemporaryPlayerFactory {
|
||||
// Helpful constructors
|
||||
private final PacketConstructor chatPacket;
|
||||
|
||||
@ -65,6 +47,18 @@ class TemporaryPlayerFactory {
|
||||
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.
|
||||
* <p>
|
||||
@ -164,6 +158,19 @@ class TemporaryPlayerFactory {
|
||||
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.
|
||||
* @param injector - the injector representing the client.
|
Loading…
Reference in New Issue
Block a user