Improve error message on server when a vanilla client connects (#4691)

This commit is contained in:
mezz 2018-01-21 16:07:54 -08:00 committed by GitHub
parent 6e731ca3e4
commit 4ae6e4a295
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View file

@ -26,6 +26,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -635,8 +636,9 @@ public class FMLCommonHandler
if (packet.getRequestedState() == EnumConnectionState.LOGIN && (!NetworkRegistry.INSTANCE.isVanillaAccepted(Side.CLIENT) && !packet.hasFMLMarker()))
{
manager.setConnectionState(EnumConnectionState.LOGIN);
TextComponentString text = new TextComponentString("This server requires FML/Forge to be installed. Contact your server admin for more details.");
FMLLog.log.info("Disconnecting Player: {}", text.getUnformattedText());
TextComponentString text = new TextComponentString("This server has mods that require FML/Forge to be installed on the client. Contact your server admin for more details.");
Collection<String> modNames = NetworkRegistry.INSTANCE.getRequiredMods(Side.CLIENT);
FMLLog.log.info("Disconnecting Player: This server has mods that require FML/Forge to be installed on the client: {}", modNames);
manager.sendPacket(new SPacketDisconnect(text));
manager.closeChannel(text);
return false;

View file

@ -24,10 +24,12 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.util.AttributeKey;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Level;
@ -304,13 +306,19 @@ public enum NetworkRegistry
public boolean isVanillaAccepted(Side from)
{
boolean result = true;
for (Entry<ModContainer, NetworkModHolder> e : registry.entrySet())
{
result &= e.getValue().acceptsVanilla(from);
}
return result;
return registry.values().stream()
.allMatch(mod -> mod.acceptsVanilla(from));
}
public Collection<String> getRequiredMods(Side from)
{
return registry.values().stream()
.filter(mod -> !mod.acceptsVanilla(from))
.map(mod -> mod.getContainer().getName())
.sorted()
.collect(Collectors.toList());
}
public Map<ModContainer,NetworkModHolder> registry()
{
return ImmutableMap.copyOf(registry);