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);
}
}
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);
}
}
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;
}
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);
}
}
}
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);
}
Aggregations