Fix some ClassCastExceptions incorrectly being logged in FML handshake. (#4972)

This commit is contained in:
Ben Staddon 2018-06-27 20:56:46 +01:00 committed by LexManos
parent 19de6cf97e
commit 80724a52d3
2 changed files with 17 additions and 17 deletions

View File

@ -129,7 +129,7 @@ enum FMLHandshakeClientState implements IHandshakeState<FMLHandshakeClientState>
WAITINGSERVERCOMPLETE WAITINGSERVERCOMPLETE
{ {
@Override @Override
public void accept(final ChannelHandlerContext ctx, final FMLHandshakeMessage msg, final Consumer<? super FMLHandshakeClientState> cons) public void accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg, Consumer<? super FMLHandshakeClientState> cons)
{ {
FMLHandshakeMessage.RegistryData pkt = (FMLHandshakeMessage.RegistryData)msg; FMLHandshakeMessage.RegistryData pkt = (FMLHandshakeMessage.RegistryData)msg;
Map<ResourceLocation, ForgeRegistry.Snapshot> snap = ctx.channel().attr(NetworkDispatcher.FML_GAMEDATA_SNAPSHOT).get(); Map<ResourceLocation, ForgeRegistry.Snapshot> snap = ctx.channel().attr(NetworkDispatcher.FML_GAMEDATA_SNAPSHOT).get();
@ -156,9 +156,7 @@ enum FMLHandshakeClientState implements IHandshakeState<FMLHandshakeClientState>
//Do the remapping on the Client's thread in case things are reset while the client is running. We stall the network thread until this is finished which can cause the IO thread to time out... Not sure if we can do anything about that. //Do the remapping on the Client's thread in case things are reset while the client is running. We stall the network thread until this is finished which can cause the IO thread to time out... Not sure if we can do anything about that.
final Map<ResourceLocation, ForgeRegistry.Snapshot> snap_f = snap; final Map<ResourceLocation, ForgeRegistry.Snapshot> snap_f = snap;
Futures.getUnchecked(Minecraft.getMinecraft().addScheduledTask(() -> Multimap<ResourceLocation, ResourceLocation> locallyMissing = Futures.getUnchecked(Minecraft.getMinecraft().addScheduledTask(() -> GameData.injectSnapshot(snap_f, false, false)));
{
Multimap<ResourceLocation, ResourceLocation> locallyMissing = GameData.injectSnapshot(snap_f, false, false);
if (!locallyMissing.isEmpty()) if (!locallyMissing.isEmpty())
{ {
cons.accept(ERROR); cons.accept(ERROR);
@ -170,7 +168,6 @@ enum FMLHandshakeClientState implements IHandshakeState<FMLHandshakeClientState>
} }
cons.accept(PENDINGCOMPLETE); cons.accept(PENDINGCOMPLETE);
ctx.writeAndFlush(new FMLHandshakeMessage.HandshakeAck(ordinal())).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); ctx.writeAndFlush(new FMLHandshakeMessage.HandshakeAck(ordinal())).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}));
} }
}, },
PENDINGCOMPLETE PENDINGCOMPLETE

View File

@ -28,14 +28,16 @@ import io.netty.util.AttributeKey;
public class HandshakeMessageHandler<S extends Enum<S> & IHandshakeState<S>> extends SimpleChannelInboundHandler<FMLHandshakeMessage> { public class HandshakeMessageHandler<S extends Enum<S> & IHandshakeState<S>> extends SimpleChannelInboundHandler<FMLHandshakeMessage> {
private static final AttributeKey<IHandshakeState<?>> STATE = AttributeKey.valueOf("fml:handshake-state"); private static final AttributeKey<IHandshakeState<?>> STATE = AttributeKey.valueOf("fml:handshake-state");
private final AttributeKey<S> fmlHandshakeState; private final AttributeKey<S> fmlHandshakeState;
private S initialState; private final S initialState;
private Class<S> stateType; private final S errorState;
private final Class<S> stateType;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public HandshakeMessageHandler(Class<S> stateType) public HandshakeMessageHandler(Class<S> stateType)
{ {
fmlHandshakeState = (AttributeKey<S>) ((Object)STATE); fmlHandshakeState = (AttributeKey<S>) ((Object)STATE);
initialState = Enum.valueOf(stateType, "START"); initialState = Enum.valueOf(stateType, "START");
errorState = Enum.valueOf(stateType, "ERROR");
this.stateType = stateType; this.stateType = stateType;
} }
@Override @Override
@ -71,6 +73,7 @@ public class HandshakeMessageHandler<S extends Enum<S> & IHandshakeState<S>> ext
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{ {
FMLLog.log.error("HandshakeMessageHandler exception", cause); FMLLog.log.error("HandshakeMessageHandler exception", cause);
ctx.channel().attr(fmlHandshakeState).set(errorState);
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
} }
} }