use of net.minecraft.network.protocol.status.ServerStatus in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method processForgeListPingData.
public static void processForgeListPingData(ServerStatus packet, ServerData target) {
if (packet.getForgeData() != null) {
final Map<String, String> mods = packet.getForgeData().getRemoteModData();
final Map<ResourceLocation, Pair<String, Boolean>> remoteChannels = packet.getForgeData().getRemoteChannels();
final int fmlver = packet.getForgeData().getFMLNetworkVersion();
boolean fmlNetMatches = fmlver == NetworkConstants.FMLNETVERSION;
boolean channelsMatch = NetworkRegistry.checkListPingCompatibilityForClient(remoteChannels);
AtomicBoolean result = new AtomicBoolean(true);
final List<String> extraClientMods = new ArrayList<>();
ModList.get().forEachModContainer((modid, mc) -> mc.getCustomExtension(IExtensionPoint.DisplayTest.class).ifPresent(ext -> {
boolean foundModOnServer = ext.remoteVersionTest().test(mods.get(modid), true);
result.compareAndSet(true, foundModOnServer);
if (!foundModOnServer) {
extraClientMods.add(modid);
}
}));
boolean modsMatch = result.get();
final Map<String, String> extraServerMods = mods.entrySet().stream().filter(e -> !Objects.equals(NetworkConstants.IGNORESERVERONLY, e.getValue())).filter(e -> !ModList.get().isLoaded(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
LOGGER.debug(CLIENTHOOKS, "Received FML ping data from server at {}: FMLNETVER={}, mod list is compatible : {}, channel list is compatible: {}, extra server mods: {}", target.ip, fmlver, modsMatch, channelsMatch, extraServerMods);
String extraReason = null;
if (!extraServerMods.isEmpty()) {
extraReason = "fml.menu.multiplayer.extraservermods";
LOGGER.info(CLIENTHOOKS, ForgeI18n.parseMessage(extraReason) + ": {}", extraServerMods.entrySet().stream().map(e -> e.getKey() + "@" + e.getValue()).collect(Collectors.joining(", ")));
}
if (!modsMatch) {
extraReason = "fml.menu.multiplayer.modsincompatible";
LOGGER.info(CLIENTHOOKS, "Client has mods that are missing on server: {}", extraClientMods);
}
if (!channelsMatch) {
extraReason = "fml.menu.multiplayer.networkincompatible";
}
if (fmlver < NetworkConstants.FMLNETVERSION) {
extraReason = "fml.menu.multiplayer.serveroutdated";
}
if (fmlver > NetworkConstants.FMLNETVERSION) {
extraReason = "fml.menu.multiplayer.clientoutdated";
}
target.forgeData = new ExtendedServerListData("FML", extraServerMods.isEmpty() && fmlNetMatches && channelsMatch && modsMatch, mods.size(), extraReason, packet.getForgeData().isTruncated());
} else {
target.forgeData = new ExtendedServerListData("VANILLA", NetworkRegistry.canConnectToVanillaServer(), 0, null);
}
}
Aggregations