Fix a race condition we created while fixing another race condition.
They're everywhere.
Dieser Commit ist enthalten in:
Ursprung
b52ea72903
Commit
a6f4aaa09a
@ -21,6 +21,8 @@ import net.minecraft.util.io.netty.channel.ChannelInitializer;
|
|||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||||
import com.comphenix.protocol.error.ErrorReporter;
|
import com.comphenix.protocol.error.ErrorReporter;
|
||||||
|
import com.comphenix.protocol.error.Report;
|
||||||
|
import com.comphenix.protocol.error.ReportType;
|
||||||
import com.comphenix.protocol.events.ConnectionSide;
|
import com.comphenix.protocol.events.ConnectionSide;
|
||||||
import com.comphenix.protocol.events.ListenerOptions;
|
import com.comphenix.protocol.events.ListenerOptions;
|
||||||
import com.comphenix.protocol.events.NetworkMarker;
|
import com.comphenix.protocol.events.NetworkMarker;
|
||||||
@ -39,13 +41,17 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
public class NettyProtocolInjector implements ChannelListener {
|
public class NettyProtocolInjector implements ChannelListener {
|
||||||
|
public static final ReportType REPORT_CANNOT_INJECT_INCOMING_CHANNEL = new ReportType("Unable to to inject incoming channel %s.");
|
||||||
|
|
||||||
private volatile boolean injected;
|
private volatile boolean injected;
|
||||||
private volatile boolean closed;
|
private volatile boolean closed;
|
||||||
|
|
||||||
// The temporary player factory
|
// The temporary player factory
|
||||||
private TemporaryPlayerFactory playerFactory = new TemporaryPlayerFactory();
|
private TemporaryPlayerFactory playerFactory = new TemporaryPlayerFactory();
|
||||||
private List<VolatileField> bootstrapFields = Lists.newArrayList();
|
private List<VolatileField> bootstrapFields = Lists.newArrayList();
|
||||||
private List<Object> networkManagers;
|
|
||||||
|
// List of network managers
|
||||||
|
private volatile List<Object> networkManagers;
|
||||||
|
|
||||||
// Different sending filters
|
// Different sending filters
|
||||||
private PacketTypeSet sendingFilters = new PacketTypeSet();
|
private PacketTypeSet sendingFilters = new PacketTypeSet();
|
||||||
@ -85,16 +91,21 @@ public class NettyProtocolInjector implements ChannelListener {
|
|||||||
final ChannelInboundHandler initProtocol = new ChannelInitializer<Channel>() {
|
final ChannelInboundHandler initProtocol = new ChannelInitializer<Channel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel channel) throws Exception {
|
protected void initChannel(Channel channel) throws Exception {
|
||||||
// Check and see if the injector has closed
|
try {
|
||||||
synchronized (this) {
|
// Check and see if the injector has closed
|
||||||
if (closed)
|
synchronized (this) {
|
||||||
return;
|
if (closed)
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// This can take a while, so we need to stop the main thread from interfering
|
// This can take a while, so we need to stop the main thread from interfering
|
||||||
synchronized (networkManagers) {
|
synchronized (networkManagers) {
|
||||||
ChannelInjector.fromChannel(channel, NettyProtocolInjector.this, playerFactory).inject();
|
ChannelInjector.fromChannel(channel, NettyProtocolInjector.this, playerFactory).inject();
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL).
|
||||||
|
messageParam(channel).error(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -111,7 +122,7 @@ public class NettyProtocolInjector implements ChannelListener {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get the current NetworkMananger list
|
// Get the current NetworkMananger list
|
||||||
Object networkManagerList = FuzzyReflection.fromObject(serverConnection, true).
|
networkManagers = (List<Object>) FuzzyReflection.fromObject(serverConnection, true).
|
||||||
invokeMethod(null, "getNetworkManagers", List.class, serverConnection);
|
invokeMethod(null, "getNetworkManagers", List.class, serverConnection);
|
||||||
|
|
||||||
// Insert ProtocolLib's connection interceptor
|
// Insert ProtocolLib's connection interceptor
|
||||||
@ -121,9 +132,7 @@ public class NettyProtocolInjector implements ChannelListener {
|
|||||||
final List<Object> list = (List<Object>) field.getValue();
|
final List<Object> list = (List<Object>) field.getValue();
|
||||||
|
|
||||||
// We don't have to override this list
|
// We don't have to override this list
|
||||||
if (list == networkManagerList) {
|
if (list == networkManagers) {
|
||||||
// Save it for later
|
|
||||||
networkManagers = list;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren