Search in sources :

Example 6 with ServerStatusResponse

use of net.minecraft.network.ServerStatusResponse in project Magma-1.16.x by magmafoundation.

the class ClientHooks method processForgeListPingData.

@Nullable
public static void processForgeListPingData(ServerStatusResponse 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 == FMLNetworkConstants.FMLNETVERSION;
        boolean channelsMatch = NetworkRegistry.checkListPingCompatibilityForClient(remoteChannels);
        AtomicBoolean result = new AtomicBoolean(true);
        final List<String> extraClientMods = new ArrayList<>();
        ModList.get().forEachModContainer((modid, mc) -> mc.getCustomExtension(ExtensionPoint.DISPLAYTEST).ifPresent(ext -> {
            boolean foundModOnServer = ext.getRight().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(FMLNetworkConstants.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 < FMLNetworkConstants.FMLNETVERSION) {
            extraReason = "fml.menu.multiplayer.serveroutdated";
        }
        if (fmlver > FMLNetworkConstants.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);
    }
}
Also used : java.util(java.util) MultiplayerScreen(net.minecraft.client.gui.screen.MultiplayerScreen) ForgeI18n(net.minecraftforge.fml.ForgeI18n) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashBasedTable(com.google.common.collect.HashBasedTable) NetworkRegistry(net.minecraftforge.fml.network.NetworkRegistry) NetworkManager(net.minecraft.network.NetworkManager) PlayerController(net.minecraft.client.multiplayer.PlayerController) Strings(com.google.common.base.Strings) HashMultimap(com.google.common.collect.HashMultimap) Pair(org.apache.commons.lang3.tuple.Pair) GameData(net.minecraftforge.registries.GameData) Minecraft(net.minecraft.client.Minecraft) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) StringTextComponent(net.minecraft.util.text.StringTextComponent) Marker(org.apache.logging.log4j.Marker) Nullable(javax.annotation.Nullable) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) ServerData(net.minecraft.client.multiplayer.ServerData) FMLNetworkConstants(net.minecraftforge.fml.network.FMLNetworkConstants) ForgeVersion(net.minecraftforge.versions.forge.ForgeVersion) ModList(net.minecraftforge.fml.ModList) MoreObjects(com.google.common.base.MoreObjects) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) ResourcePack(net.minecraft.resources.ResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) File(java.io.File) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) AbstractGui(net.minecraft.client.gui.AbstractGui) MinecraftForge(net.minecraftforge.common.MinecraftForge) MarkerManager(org.apache.logging.log4j.MarkerManager) Logger(org.apache.logging.log4j.Logger) ClientPlayerNetworkEvent(net.minecraftforge.client.event.ClientPlayerNetworkEvent) FallbackResourceManager(net.minecraft.resources.FallbackResourceManager) SimpleReloadableResourceManager(net.minecraft.resources.SimpleReloadableResourceManager) ResourceLocation(net.minecraft.util.ResourceLocation) IResourcePack(net.minecraft.resources.IResourcePack) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Table(com.google.common.collect.Table) LogManager(org.apache.logging.log4j.LogManager) ExtensionPoint(net.minecraftforge.fml.ExtensionPoint) ClientWorld(net.minecraft.client.world.ClientWorld) ExtensionPoint(net.minecraftforge.fml.ExtensionPoint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResourceLocation(net.minecraft.util.ResourceLocation) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 7 with ServerStatusResponse

use of net.minecraft.network.ServerStatusResponse in project LoliServer by Loli-Server.

the class ClientHooks method processForgeListPingData.

@Nullable
public static void processForgeListPingData(ServerStatusResponse 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 == FMLNetworkConstants.FMLNETVERSION;
        boolean channelsMatch = NetworkRegistry.checkListPingCompatibilityForClient(remoteChannels);
        AtomicBoolean result = new AtomicBoolean(true);
        final List<String> extraClientMods = new ArrayList<>();
        ModList.get().forEachModContainer((modid, mc) -> mc.getCustomExtension(ExtensionPoint.DISPLAYTEST).ifPresent(ext -> {
            boolean foundModOnServer = ext.getRight().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(FMLNetworkConstants.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 < FMLNetworkConstants.FMLNETVERSION) {
            extraReason = "fml.menu.multiplayer.serveroutdated";
        }
        if (fmlver > FMLNetworkConstants.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);
    }
}
Also used : java.util(java.util) MultiplayerScreen(net.minecraft.client.gui.screen.MultiplayerScreen) ForgeI18n(net.minecraftforge.fml.ForgeI18n) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashBasedTable(com.google.common.collect.HashBasedTable) NetworkRegistry(net.minecraftforge.fml.network.NetworkRegistry) NetworkManager(net.minecraft.network.NetworkManager) PlayerController(net.minecraft.client.multiplayer.PlayerController) Strings(com.google.common.base.Strings) HashMultimap(com.google.common.collect.HashMultimap) Pair(org.apache.commons.lang3.tuple.Pair) GameData(net.minecraftforge.registries.GameData) Minecraft(net.minecraft.client.Minecraft) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) StringTextComponent(net.minecraft.util.text.StringTextComponent) Marker(org.apache.logging.log4j.Marker) Nullable(javax.annotation.Nullable) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) ServerData(net.minecraft.client.multiplayer.ServerData) FMLNetworkConstants(net.minecraftforge.fml.network.FMLNetworkConstants) ForgeVersion(net.minecraftforge.versions.forge.ForgeVersion) ModList(net.minecraftforge.fml.ModList) MoreObjects(com.google.common.base.MoreObjects) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) ResourcePack(net.minecraft.resources.ResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) File(java.io.File) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) AbstractGui(net.minecraft.client.gui.AbstractGui) MinecraftForge(net.minecraftforge.common.MinecraftForge) MarkerManager(org.apache.logging.log4j.MarkerManager) Logger(org.apache.logging.log4j.Logger) ClientPlayerNetworkEvent(net.minecraftforge.client.event.ClientPlayerNetworkEvent) FallbackResourceManager(net.minecraft.resources.FallbackResourceManager) SimpleReloadableResourceManager(net.minecraft.resources.SimpleReloadableResourceManager) ResourceLocation(net.minecraft.util.ResourceLocation) IResourcePack(net.minecraft.resources.IResourcePack) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Table(com.google.common.collect.Table) LogManager(org.apache.logging.log4j.LogManager) ExtensionPoint(net.minecraftforge.fml.ExtensionPoint) ClientWorld(net.minecraft.client.world.ClientWorld) ExtensionPoint(net.minecraftforge.fml.ExtensionPoint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResourceLocation(net.minecraft.util.ResourceLocation) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 8 with ServerStatusResponse

use of net.minecraft.network.ServerStatusResponse in project TheAPI by TheDevTec.

the class v1_16_R3_Mohist method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    SServerInfoPacket status = (SServerInfoPacket) packet;
    ServerStatusResponse ping;
    try {
        ping = (ServerStatusResponse) field.get(status);
    } catch (Exception e) {
        return false;
    }
    List<PlayerProfile> players = new ArrayList<>();
    for (Player p : Bukkit.getOnlinePlayers()) players.add(new PlayerProfile(p.getName(), p.getUniqueId()));
    ServerListPingEvent event = new ServerListPingEvent(Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers(), players, Bukkit.getMotd(), ping.func_151316_d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.func_151322_c().func_151303_a(), ping.func_151322_c().func_151304_b());
    HandlerList.callEvent(event);
    if (event.isCancelled())
        return true;
    Players playerSample = new Players(event.getMaxPlayers(), event.getOnlinePlayers());
    if (event.getPlayersText() != null) {
        GameProfile[] profiles = new GameProfile[event.getPlayersText().size()];
        int i = -1;
        for (PlayerProfile s : event.getPlayersText()) profiles[++i] = new GameProfile(s.getUUID(), s.getName());
        playerSample.func_151330_a(profiles);
    } else
        playerSample.func_151330_a(new GameProfile[0]);
    ping.func_151319_a(playerSample);
    if (event.getMotd() != null)
        ping.func_151315_a((ITextComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.func_151315_a((ITextComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.func_151321_a(new Version(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.func_151320_a(event.getFalvicon());
    return false;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) Player(org.bukkit.entity.Player) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) GameProfile(com.mojang.authlib.GameProfile) Version(net.minecraft.network.ServerStatusResponse.Version) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent) SServerInfoPacket(net.minecraft.network.status.server.SServerInfoPacket) Players(net.minecraft.network.ServerStatusResponse.Players)

Example 9 with ServerStatusResponse

use of net.minecraft.network.ServerStatusResponse in project SpongeCommon by SpongePowered.

the class MixinNetHandlerStatusServer method processServerQuery.

/**
 * @author Minecrell - January 18th, 2015
 * @reason Post the server status ping event for plugins.
 */
@Overwrite
public void processServerQuery(CPacketServerQuery packetIn) {
    if (this.handled) {
        this.networkManager.closeChannel(EXIT_MESSAGE);
    } else {
        this.handled = true;
        ServerStatusResponse response = SpongeStatusResponse.post(this.server, new SpongeStatusClient(this.networkManager));
        if (response != null) {
            this.networkManager.sendPacket(new SPacketServerInfo(response));
        } else {
            this.networkManager.closeChannel(null);
        }
    }
}
Also used : SpongeStatusClient(org.spongepowered.common.network.status.SpongeStatusClient) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) SPacketServerInfo(net.minecraft.network.status.server.SPacketServerInfo) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 10 with ServerStatusResponse

use of net.minecraft.network.ServerStatusResponse in project SpongeVanilla by SpongePowered.

the class MixinDedicatedServer method onServerInitialize.

@Inject(method = "init()Z", at = @At(value = "INVOKE", target = CONSTRUCT_CONFIG_MANAGER, shift = At.Shift.BEFORE))
private void onServerInitialize(CallbackInfoReturnable<Boolean> ci) {
    if (this.getFolderName() == null) {
        this.setFolderName(this.settings.getStringProperty("level-name", "world"));
    }
    spongeVanilla.initialize();
    ServerStatusResponse statusResponse = getServerStatusResponse();
    statusResponse.setServerDescription(new TextComponentString(this.getMotd()));
    statusResponse.setVersion(new ServerStatusResponse.Version(MINECRAFT_VERSION.getName(), MINECRAFT_VERSION.getProtocol()));
    this.applyServerIconToResponse(statusResponse);
}
Also used : ServerStatusResponse(net.minecraft.network.ServerStatusResponse) TextComponentString(net.minecraft.util.text.TextComponentString) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ServerStatusResponse (net.minecraft.network.ServerStatusResponse)12 GameProfile (com.mojang.authlib.GameProfile)4 NetworkManager (net.minecraft.network.NetworkManager)4 StringTextComponent (net.minecraft.util.text.StringTextComponent)3 TextComponentString (net.minecraft.util.text.TextComponentString)3 MoreObjects (com.google.common.base.MoreObjects)2 Strings (com.google.common.base.Strings)2 HashBasedTable (com.google.common.collect.HashBasedTable)2 HashMultimap (com.google.common.collect.HashMultimap)2 SetMultimap (com.google.common.collect.SetMultimap)2 Sets (com.google.common.collect.Sets)2 Table (com.google.common.collect.Table)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 File (java.io.File)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 Minecraft (net.minecraft.client.Minecraft)2