Fixed a bug introduced in #218 causing packet loops. FIXES 202.

In 659f01cc63, I attempted to 
execute packet listeners for receiveClientPacket() on the channel
thread, inadvertently causing them to be executed regardless if 
filtered was FALSE, and twice if it is TRUE.

Since asynchronous packet listeners use this feature to take out
packets from the packet stream, they wound up causing an infinite 
packet loop. This prevented them from ever being received by the
server.
This commit is contained in:
Kristian S. Stangeland 2014-03-15 03:59:28 +01:00
parent 75a5efcaa1
commit ad060b10af
4 changed files with 7 additions and 14 deletions

View File

@ -485,20 +485,15 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
}
@Override
public void recieveClientPacket(final Object packet, final NetworkMarker marker, final boolean filtered) {
public void recieveClientPacket(final Object packet) {
// TODO: Ensure the packet listeners are executed in the channel thread.
// Execute this in the channel thread
Runnable action = new Runnable() {
@Override
public void run() {
PacketEvent event = filtered ? channelListener.onPacketReceiving(ChannelInjector.this, packet, marker) : null;
Object result = event != null ? event.getPacket().getHandle() : packet;
// See if the packet has been cancelled
if (event != null && event.isCancelled())
return;
try {
MinecraftMethods.getNetworkManagerReadPacketMethod().invoke(networkManager, null, result);
MinecraftMethods.getNetworkManagerReadPacketMethod().invoke(networkManager, null, packet);
} catch (Exception e) {
// Inform the user
ProtocolLibrary.getErrorReporter().reportMinimal(factory.getPlugin(), "recieveClientPacket", e);

View File

@ -36,7 +36,7 @@ class ClosedInjector implements Injector {
}
@Override
public void recieveClientPacket(Object packet, NetworkMarker marker, boolean filtered) {
public void recieveClientPacket(Object packet) {
// Do nothing
}

View File

@ -34,10 +34,8 @@ interface Injector {
/**
* Recieve a packet on the server.
* @param packet - the (NMS) packet to send.
* @param marker - the network marker.
* @param filtered - whether or not the packet is filtered.
*/
public abstract void recieveClientPacket(Object packet, NetworkMarker marker, boolean filtered);
public abstract void recieveClientPacket(Object packet);
/**
* Retrieve the current protocol state.

View File

@ -331,7 +331,7 @@ public class NettyProtocolInjector implements ChannelListener {
@Override
public void recieveClientPacket(Player player, Object mcPacket) throws IllegalAccessException, InvocationTargetException {
injectionFactory.fromPlayer(player, listener).
recieveClientPacket(mcPacket, null, true);
recieveClientPacket(mcPacket);
}
@Override