Add more data to servers
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m30s

This commit is contained in:
Braydon 2024-04-10 09:27:09 -04:00
parent 501d315c96
commit 20adfaeaad
5 changed files with 240 additions and 18 deletions

@ -24,6 +24,7 @@
package me.braydon.mc.common; package me.braydon.mc.common;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.ToString; import lombok.ToString;
@ -109,6 +110,8 @@ public enum JavaMinecraftVersion {
public static final JavaMinecraftVersion THE_COMBAT_UPDATE = JavaMinecraftVersion.V1_9; public static final JavaMinecraftVersion THE_COMBAT_UPDATE = JavaMinecraftVersion.V1_9;
public static final JavaMinecraftVersion BOUNTIFUL_UPDATE = JavaMinecraftVersion.V1_8; public static final JavaMinecraftVersion BOUNTIFUL_UPDATE = JavaMinecraftVersion.V1_8;
private static final JavaMinecraftVersion[] VALUES = JavaMinecraftVersion.values();
/** /**
* The protocol number of this version. * The protocol number of this version.
*/ */
@ -144,6 +147,16 @@ public enum JavaMinecraftVersion {
return this.name; return this.name;
} }
/**
* Get the minimum Minecraft version.
*
* @return the minimum version
*/
@NonNull
public static JavaMinecraftVersion getMinimumVersion() {
return VALUES[VALUES.length - 2];
}
/** /**
* Get the version from the given protocol. * Get the version from the given protocol.
* *

@ -25,11 +25,14 @@ package me.braydon.mc.model;
import lombok.*; import lombok.*;
import me.braydon.mc.common.ColorUtils; import me.braydon.mc.common.ColorUtils;
import me.braydon.mc.model.token.JavaServerStatusToken;
import me.braydon.mc.service.pinger.MinecraftServerPinger; import me.braydon.mc.service.pinger.MinecraftServerPinger;
import me.braydon.mc.service.pinger.impl.BedrockMinecraftServerPinger; import me.braydon.mc.service.pinger.impl.BedrockMinecraftServerPinger;
import me.braydon.mc.service.pinger.impl.JavaMinecraftServerPinger; import me.braydon.mc.service.pinger.impl.JavaMinecraftServerPinger;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
@ -84,6 +87,24 @@ public class MinecraftServer {
*/ */
private final Sample[] sample; private final Sample[] sample;
/**
* Create new player count data from a token.
*
* @param token the token to create from
* @return the player count data
*/
@NonNull
public static Players create(@NonNull JavaServerStatusToken.Players token) {
List<Sample> samples = null;
if (token.getSample() != null) {
samples = new ArrayList<>(); // The player samples
for (JavaServerStatusToken.Players.Sample sample : token.getSample()) {
samples.add(new Sample(sample.getId(), Sample.Name.create(sample.getName())));
}
}
return new Players(token.getOnline(), token.getMax(), samples != null ? samples.toArray(new Sample[0]) : null);
}
/** /**
* A sample player. * A sample player.
*/ */
@ -97,7 +118,39 @@ public class MinecraftServer {
/** /**
* The name of this player. * The name of this player.
*/ */
@NonNull private final String name; @NonNull private final Name name;
/**
* The name of a sample player.
*/
@AllArgsConstructor @Getter @ToString
public static class Name {
/**
* The raw name.
*/
@NonNull private final String raw;
/**
* The clean name (no color codes).
*/
@NonNull private final String clean;
/**
* The HTML name.
*/
@NonNull private final String html;
/**
* Create a new name from a raw string.
*
* @param raw the raw name string
* @return the new name
*/
@NonNull
public static Name create(@NonNull String raw) {
return new Name(raw, ColorUtils.stripColor(raw), ColorUtils.toHTML(raw));
}
}
} }
} }

@ -52,9 +52,27 @@ public final class JavaMinecraftServer extends MinecraftServer {
/** /**
* The Forge mod information for this server, null if none. * The Forge mod information for this server, null if none.
* <p>
* This is for servers on 1.12 or below.
* </p>
*/ */
private final ModInfo modInfo; private final ModInfo modInfo;
/**
* The Forge mod information for this server, null if none.
* <p>
* This is for servers on 1.13 and above.
* </p>
*/
private final ForgeData forgeData;
/**
* Does this server preview chat?
*
* @see <a href="https://www.minecraft.net/es-mx/article/minecraft-snapshot-22w19a">This for more</a>
*/
private final boolean previewsChat;
/** /**
* Does this server enforce secure chat? * Does this server enforce secure chat?
*/ */
@ -80,11 +98,13 @@ public final class JavaMinecraftServer extends MinecraftServer {
private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Version version, private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Version version,
@NonNull Players players, @NonNull MOTD motd, Favicon favicon, ModInfo modInfo, @NonNull Players players, @NonNull MOTD motd, Favicon favicon, ModInfo modInfo,
boolean enforcesSecureChat, boolean preventsChatReports, boolean mojangBanned) { ForgeData forgeData, boolean previewsChat, boolean enforcesSecureChat, boolean preventsChatReports, boolean mojangBanned) {
super(hostname, ip, port, players, motd); super(hostname, ip, port, players, motd);
this.version = version; this.version = version;
this.favicon = favicon; this.favicon = favicon;
this.modInfo = modInfo; this.modInfo = modInfo;
this.forgeData = forgeData;
this.previewsChat = previewsChat;
this.enforcesSecureChat = enforcesSecureChat; this.enforcesSecureChat = enforcesSecureChat;
this.preventsChatReports = preventsChatReports; this.preventsChatReports = preventsChatReports;
this.mojangBanned = mojangBanned; this.mojangBanned = mojangBanned;
@ -105,9 +125,9 @@ public final class JavaMinecraftServer extends MinecraftServer {
if (motdString == null) { // Not a string motd, convert from Json if (motdString == null) { // Not a string motd, convert from Json
motdString = new TextComponent(ComponentSerializer.parse(AppConfig.GSON.toJson(token.getDescription()))).toLegacyText(); motdString = new TextComponent(ComponentSerializer.parse(AppConfig.GSON.toJson(token.getDescription()))).toLegacyText();
} }
return new JavaMinecraftServer(hostname, ip, port, token.getVersion().detailedCopy(), token.getPlayers(), return new JavaMinecraftServer(hostname, ip, port, token.getVersion().detailedCopy(), Players.create(token.getPlayers()),
MOTD.create(motdString), Favicon.create(token.getFavicon(), hostname), token.getModInfo(), MOTD.create(motdString), Favicon.create(token.getFavicon(), hostname), token.getModInfo(), token.getForgeData(),
token.isEnforcesSecureChat(), token.isPreventsChatReports(), false token.isPreviewsChat(), token.isEnforcesSecureChat(), token.isPreventsChatReports(), false
); );
} }
@ -131,6 +151,11 @@ public final class JavaMinecraftServer extends MinecraftServer {
*/ */
private final int protocol; private final int protocol;
/**
* A list of versions supported by this server.
*/
private final int[] supportedVersions;
/** /**
* The name of the version for the protocol, null if unknown. * The name of the version for the protocol, null if unknown.
*/ */
@ -152,7 +177,7 @@ public final class JavaMinecraftServer extends MinecraftServer {
} }
} }
JavaMinecraftVersion minecraftVersion = JavaMinecraftVersion.byProtocol(protocol); JavaMinecraftVersion minecraftVersion = JavaMinecraftVersion.byProtocol(protocol);
return new Version(name, platform, protocol, minecraftVersion == null ? null : minecraftVersion.getName()); return new Version(name, platform, protocol, supportedVersions, minecraftVersion == null ? null : minecraftVersion.getName());
} }
} }
@ -191,6 +216,9 @@ public final class JavaMinecraftServer extends MinecraftServer {
/** /**
* Forge mod information for a server. * Forge mod information for a server.
* <p>
* This is for servers on 1.12 or below.
* </p>
*/ */
@AllArgsConstructor @Getter @ToString @AllArgsConstructor @Getter @ToString
public static class ModInfo { public static class ModInfo {
@ -202,14 +230,13 @@ public final class JavaMinecraftServer extends MinecraftServer {
/** /**
* The list of mods on this server, null or empty if none. * The list of mods on this server, null or empty if none.
*/ */
private final ForgeMod[] modList; @SerializedName("modList") private final Mod[] mods;
}
/** /**
* A forge mod for a server. * A Forge mod for a server.
*/ */
@AllArgsConstructor @Getter @ToString @AllArgsConstructor @Getter @ToString
private static class ForgeMod { private static class Mod {
/** /**
* The id of this mod. * The id of this mod.
*/ */
@ -220,4 +247,75 @@ public final class JavaMinecraftServer extends MinecraftServer {
*/ */
private final String version; private final String version;
} }
}
/**
* Forge information for a server.
* <p>
* This is for servers on 1.13 and above.
* </p>
*/
@AllArgsConstructor @Getter @ToString
public static class ForgeData {
/**
* The list of channels on this server, null or empty if none.
*/
private final Channel[] channels;
/**
* The list of mods on this server, null or empty if none.
*/
private final Mod[] mods;
/**
* The version of the FML network.
*/
private final int fmlNetworkVersion;
/**
* Are the channel and mod lists truncated?
* <p>
* Legacy versions see truncated lists, modern
* versions ignore this truncated flag.
* </p>
*/
private final boolean truncated;
/**
* A Forge channel for a server.
*/
@AllArgsConstructor @Getter @ToString
private static class Channel {
/**
* The name of this channel.
*/
@NonNull @SerializedName("res") private final String name;
/**
* The version of this channel.
*/
@NonNull private final String version;
/**
* Whether this channel is required.
*/
private final boolean required;
}
/**
* A Forge mod for a server.
*/
@AllArgsConstructor @Getter @ToString
private static class Mod {
/**
* The id of this mod.
*/
@NonNull @SerializedName("modId") private final String name;
/**
* The marker for this mod.
*/
@NonNull @SerializedName("modmarker") private final String marker;
}
}
} }

@ -28,9 +28,10 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.ToString; import lombok.ToString;
import me.braydon.mc.model.MinecraftServer;
import me.braydon.mc.model.server.JavaMinecraftServer; import me.braydon.mc.model.server.JavaMinecraftServer;
import java.util.UUID;
/** /**
* A token representing the response from * A token representing the response from
* pinging a {@link JavaMinecraftServer}. * pinging a {@link JavaMinecraftServer}.
@ -60,13 +61,31 @@ public final class JavaServerStatusToken {
/** /**
* The player counts of this server. * The player counts of this server.
*/ */
@NonNull private final MinecraftServer.Players players; @NonNull private final Players players;
/** /**
* The Forge mod information for this server, null if none. * The Forge mod information for this server, null if none.
* <p>
* This is for servers on 1.12 or below.
* </p>
*/ */
@SerializedName("modinfo") private final JavaMinecraftServer.ModInfo modInfo; @SerializedName("modinfo") private final JavaMinecraftServer.ModInfo modInfo;
/**
* The Forge mod information for this server, null if none.
* <p>
* This is for servers on 1.13 and above.
* </p>
*/
private final JavaMinecraftServer.ForgeData forgeData;
/**
* Does this server preview chat?
*
* @see <a href="https://www.minecraft.net/es-mx/article/minecraft-snapshot-22w19a">This for more</a>
*/
private final boolean previewsChat;
/** /**
* Does this server enforce secure chat? * Does this server enforce secure chat?
*/ */
@ -76,4 +95,41 @@ public final class JavaServerStatusToken {
* Is this server preventing chat reports? * Is this server preventing chat reports?
*/ */
private final boolean preventsChatReports; private final boolean preventsChatReports;
/**
* Player count data for a server.
*/
@AllArgsConstructor @Getter @ToString
public static class Players {
/**
* The online players on this server.
*/
private final int online;
/**
* The maximum allowed players on this server.
*/
private final int max;
/**
* A sample of players on this server, null or empty if no sample.
*/
private final Sample[] sample;
/**
* A sample player.
*/
@AllArgsConstructor @Getter @ToString
public static class Sample {
/**
* The unique id of this player.
*/
@NonNull private final UUID id;
/**
* The name of this player.
*/
@NonNull private final String name;
}
}
} }

@ -26,6 +26,7 @@ package me.braydon.mc.service.pinger.impl;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import me.braydon.mc.common.DNSUtils; import me.braydon.mc.common.DNSUtils;
import me.braydon.mc.common.JavaMinecraftVersion;
import me.braydon.mc.common.packet.impl.java.JavaPacketHandshakingInSetProtocol; import me.braydon.mc.common.packet.impl.java.JavaPacketHandshakingInSetProtocol;
import me.braydon.mc.common.packet.impl.java.JavaPacketStatusInStart; import me.braydon.mc.common.packet.impl.java.JavaPacketStatusInStart;
import me.braydon.mc.config.AppConfig; import me.braydon.mc.config.AppConfig;
@ -81,7 +82,8 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger<Ja
try (DataInputStream inputStream = new DataInputStream(socket.getInputStream()); try (DataInputStream inputStream = new DataInputStream(socket.getInputStream());
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream())) { DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream())) {
// Begin handshaking with the server // Begin handshaking with the server
new JavaPacketHandshakingInSetProtocol(hostname, port, 47).process(inputStream, outputStream); new JavaPacketHandshakingInSetProtocol(hostname, port, JavaMinecraftVersion.getMinimumVersion().getProtocol())
.process(inputStream, outputStream);
// Send the status request to the server, and await back the response // Send the status request to the server, and await back the response
JavaPacketStatusInStart packetStatusInStart = new JavaPacketStatusInStart(); JavaPacketStatusInStart packetStatusInStart = new JavaPacketStatusInStart();