mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-02-27 01:41:50 +01:00
Store a current player injection hook for each game phase.
That way, one failing the other won't cause any problems.
This commit is contained in:
parent
3a8a4d15cf
commit
fee9a32e4b
@ -73,15 +73,6 @@
|
|||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>findbugs-maven-plugin</artifactId>
|
|
||||||
<version>2.5.2</version>
|
|
||||||
<configuration>
|
|
||||||
<threshold>High</threshold>
|
|
||||||
<effort>Default</effort>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<profiles>
|
<profiles>
|
||||||
@ -156,6 +147,19 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>findbugs-maven-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
<configuration>
|
||||||
|
<threshold>High</threshold>
|
||||||
|
<effort>Default</effort>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>comphenix-releases</id>
|
<id>comphenix-releases</id>
|
||||||
|
@ -88,7 +88,7 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
|
|
||||||
// Player login and logout events
|
// Player login and logout events
|
||||||
protocolManager.registerEvents(manager, this);
|
protocolManager.registerEvents(manager, this);
|
||||||
|
|
||||||
// Worker that ensures that async packets are eventually sent
|
// Worker that ensures that async packets are eventually sent
|
||||||
createAsyncTask(server);
|
createAsyncTask(server);
|
||||||
//toggleDebugListener();
|
//toggleDebugListener();
|
||||||
|
@ -104,9 +104,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
// Packet injection
|
// Packet injection
|
||||||
private PacketInjector packetInjector;
|
private PacketInjector packetInjector;
|
||||||
|
|
||||||
// Player injection
|
// Different injection types per game phase
|
||||||
private PlayerInjectionHandler playerInjection;
|
private PlayerInjectionHandler playerInjection;
|
||||||
|
|
||||||
// The two listener containers
|
// The two listener containers
|
||||||
private SortedPacketListenerList recievedListeners = new SortedPacketListenerList();
|
private SortedPacketListenerList recievedListeners = new SortedPacketListenerList();
|
||||||
private SortedPacketListenerList sendingListeners = new SortedPacketListenerList();
|
private SortedPacketListenerList sendingListeners = new SortedPacketListenerList();
|
||||||
|
@ -98,7 +98,7 @@ class NetworkObjectInjector extends PlayerInjector {
|
|||||||
public void injectManager() {
|
public void injectManager() {
|
||||||
|
|
||||||
if (networkManager != null) {
|
if (networkManager != null) {
|
||||||
final Class<?> networkInterface = networkManagerField.getType();
|
final Class<?> networkInterface = networkManagerRef.getField().getType();
|
||||||
final Object networkDelegate = networkManagerRef.getOldValue();
|
final Object networkDelegate = networkManagerRef.getOldValue();
|
||||||
|
|
||||||
if (!networkInterface.isInterface()) {
|
if (!networkInterface.isInterface()) {
|
||||||
|
@ -23,7 +23,6 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -65,10 +64,11 @@ public class PlayerInjectionHandler {
|
|||||||
// Player injection
|
// Player injection
|
||||||
private Map<SocketAddress, PlayerInjector> addressLookup = Maps.newConcurrentMap();
|
private Map<SocketAddress, PlayerInjector> addressLookup = Maps.newConcurrentMap();
|
||||||
private Map<DataInputStream, PlayerInjector> dataInputLookup = Maps.newConcurrentMap();
|
private Map<DataInputStream, PlayerInjector> dataInputLookup = Maps.newConcurrentMap();
|
||||||
private Map<Player, PlayerInjector> playerInjection = new HashMap<Player, PlayerInjector>();
|
private Map<Player, PlayerInjector> playerInjection = Maps.newConcurrentMap();
|
||||||
|
|
||||||
// Player injection type
|
// Player injection types
|
||||||
private PlayerInjectHooks playerHook = PlayerInjectHooks.NETWORK_SERVER_OBJECT;
|
private volatile PlayerInjectHooks loginPlayerHook = PlayerInjectHooks.NETWORK_SERVER_OBJECT;
|
||||||
|
private volatile PlayerInjectHooks playingPlayerHook = PlayerInjectHooks.NETWORK_SERVER_OBJECT;
|
||||||
|
|
||||||
// Error logger
|
// Error logger
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
@ -105,9 +105,45 @@ public class PlayerInjectionHandler {
|
|||||||
* @return Injection method for reading server packets.
|
* @return Injection method for reading server packets.
|
||||||
*/
|
*/
|
||||||
public PlayerInjectHooks getPlayerHook() {
|
public PlayerInjectHooks getPlayerHook() {
|
||||||
return playerHook;
|
return getPlayerHook(GamePhase.PLAYING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves how the server packets are read.
|
||||||
|
* @param phase - the current game phase.
|
||||||
|
* @return Injection method for reading server packets.
|
||||||
|
*/
|
||||||
|
public PlayerInjectHooks getPlayerHook(GamePhase phase) {
|
||||||
|
switch (phase) {
|
||||||
|
case LOGIN:
|
||||||
|
return loginPlayerHook;
|
||||||
|
case PLAYING:
|
||||||
|
return playingPlayerHook;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Cannot retrieve injection hook for both phases at the same time.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets how the server packets are read.
|
||||||
|
* @param playerHook - the new injection method for reading server packets.
|
||||||
|
*/
|
||||||
|
public void setPlayerHook(PlayerInjectHooks playerHook) {
|
||||||
|
setPlayerHook(GamePhase.PLAYING, playerHook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets how the server packets are read.
|
||||||
|
* @param phase - the current game phase.
|
||||||
|
* @param playerHook - the new injection method for reading server packets.
|
||||||
|
*/
|
||||||
|
public void setPlayerHook(GamePhase phase, PlayerInjectHooks playerHook) {
|
||||||
|
if (phase.hasLogin())
|
||||||
|
loginPlayerHook = playerHook;
|
||||||
|
if (phase.hasPlaying())
|
||||||
|
playingPlayerHook = playerHook;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an underlying packet handler of the given ID.
|
* Add an underlying packet handler of the given ID.
|
||||||
* @param packetID - packet ID to register.
|
* @param packetID - packet ID to register.
|
||||||
@ -123,15 +159,7 @@ public class PlayerInjectionHandler {
|
|||||||
public void removePacketHandler(int packetID) {
|
public void removePacketHandler(int packetID) {
|
||||||
sendingFilters.remove(packetID);
|
sendingFilters.remove(packetID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets how the server packets are read.
|
|
||||||
* @param playerHook - the new injection method for reading server packets.
|
|
||||||
*/
|
|
||||||
public void setPlayerHook(PlayerInjectHooks playerHook) {
|
|
||||||
this.playerHook = playerHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to construct a player hook.
|
* Used to construct a player hook.
|
||||||
* @param player - the player to hook.
|
* @param player - the player to hook.
|
||||||
@ -214,9 +242,17 @@ public class PlayerInjectionHandler {
|
|||||||
* @return The resulting player injector, or NULL if the injection failed.
|
* @return The resulting player injector, or NULL if the injection failed.
|
||||||
*/
|
*/
|
||||||
PlayerInjector injectPlayer(Player player, Object injectionPoint, GamePhase phase) {
|
PlayerInjector injectPlayer(Player player, Object injectionPoint, GamePhase phase) {
|
||||||
|
// Unfortunately, due to NetLoginHandler, multiple threads may potentially call this method.
|
||||||
|
synchronized (player) {
|
||||||
|
return injectPlayerInternal(player, injectionPoint, phase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unsafe variant of the above
|
||||||
|
private PlayerInjector injectPlayerInternal(Player player, Object injectionPoint, GamePhase phase) {
|
||||||
|
|
||||||
PlayerInjector injector = playerInjection.get(player);
|
PlayerInjector injector = playerInjection.get(player);
|
||||||
PlayerInjectHooks tempHook = playerHook;
|
PlayerInjectHooks tempHook = getPlayerHook(phase);
|
||||||
PlayerInjectHooks permanentHook = tempHook;
|
PlayerInjectHooks permanentHook = tempHook;
|
||||||
|
|
||||||
// The given player object may be fake, so be careful!
|
// The given player object may be fake, so be careful!
|
||||||
@ -299,8 +335,8 @@ public class PlayerInjectionHandler {
|
|||||||
// Update values
|
// Update values
|
||||||
if (injector != null)
|
if (injector != null)
|
||||||
lastSuccessfulHook = injector;
|
lastSuccessfulHook = injector;
|
||||||
if (permanentHook != playerHook)
|
if (permanentHook != getPlayerHook(phase))
|
||||||
setPlayerHook(tempHook);
|
setPlayerHook(phase, tempHook);
|
||||||
|
|
||||||
// Save last injector
|
// Save last injector
|
||||||
playerInjection.put(player, injector);
|
playerInjection.put(player, injector);
|
||||||
@ -326,14 +362,13 @@ public class PlayerInjectionHandler {
|
|||||||
public void uninjectPlayer(Player player) {
|
public void uninjectPlayer(Player player) {
|
||||||
if (!hasClosed && player != null) {
|
if (!hasClosed && player != null) {
|
||||||
|
|
||||||
PlayerInjector injector = playerInjection.get(player);
|
PlayerInjector injector = playerInjection.remove(player);
|
||||||
|
|
||||||
if (injector != null) {
|
if (injector != null) {
|
||||||
DataInputStream input = injector.getInputStream(true);
|
DataInputStream input = injector.getInputStream(true);
|
||||||
InetSocketAddress address = player.getAddress();
|
InetSocketAddress address = player.getAddress();
|
||||||
injector.cleanupAll();
|
injector.cleanupAll();
|
||||||
|
|
||||||
playerInjection.remove(player);
|
|
||||||
dataInputLookup.remove(input);
|
dataInputLookup.remove(input);
|
||||||
|
|
||||||
if (address != null)
|
if (address != null)
|
||||||
|
Loading…
Reference in New Issue
Block a user