Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public class ViaProxyConfig {
@Description("Custom MOTD to send when clients ping the proxy. Leave empty to use the target server's MOTD.")
private String customMotd = "";

@Option("custom-players")
@Description({
"Custom Players to send when clients ping the proxy. Leave empty to use the target server's players.",
"For 1 player on a 8 player server with no sample players: 1/8",
"For 2 players on a 10 player server with 2 sample players: 2/10/player1/player2"
})
private String customPlayers = "";

@Option("custom-favicon-path")
@Description("Relative file path to a custom favicon to send when clients ping the proxy. Leave empty to use the target server's favicon.")
private String customFaviconPath = "";
Expand Down Expand Up @@ -504,6 +512,10 @@ public void setCustomMotd(final String customMotd) {
this.save();
}

public String getCustomPlayers() {
return this.customPlayers;
}

public String getCustomFaviconPath() {
return this.customFaviconPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ public boolean handleP2S(Packet packet, List<ChannelFutureListener> listeners) {
obj.addProperty("favicon", FAVICON_BASE_64);
}
}
String customPlayers = ViaProxy.getConfig().getCustomPlayers();
if (!customPlayers.isBlank()) {
String[] parts = customPlayers.split("/");
JsonObject players = new JsonObject();
players.addProperty("online", Integer.parseInt(parts[0]));
players.addProperty("max", Integer.parseInt(parts[1]));
if (parts.length > 2) {
var sampleArray = new com.google.gson.JsonArray();
for (int i = 2; i < parts.length; i++) {
JsonObject samplePlayer = new JsonObject();
samplePlayer.addProperty("name", parts[i]);
samplePlayer.addProperty("id", "00000000-0000-0000-0000-000000000000");
sampleArray.add(samplePlayer);
}
players.add("sample", sampleArray);
}
obj.add("players", players);
}
statusResponsePacket.statusJson = obj.toString();
} catch (Throwable ignored) {
}
Expand Down