Skip to content

Commit

Permalink
Add fallback to config option for query on standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jan 5, 2025
1 parent 70a6d43 commit 43472fe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void main(String[] args) throws Exception {

sessionManager = new SessionManager(new FileStorageManager("./cache"), notificationManager, logger);

sessionInfo = config.session().sessionInfo();
sessionInfo = (SessionInfo) config.session().sessionInfo().copy();

PingUtil.setWebPingEnabled(config.session().webQueryFallback());

Expand Down Expand Up @@ -132,7 +132,18 @@ private static void updateSessionInfo(SessionInfo sessionInfo) {
sessionInfo.setPlayers(pong.playerCount());
sessionInfo.setMaxPlayers(pong.maximumPlayerCount());
} catch (InterruptedException | ExecutionException e) {
sessionManager.logger().error("Failed to ping server", e);
if (config.session().configFallback()) {
sessionManager.logger().error("Failed to ping server, falling back to config values", e);

sessionInfo.setHostName(config.session().sessionInfo().getHostName());
sessionInfo.setWorldName(config.session().sessionInfo().getWorldName());
sessionInfo.setVersion(config.session().sessionInfo().getVersion());
sessionInfo.setProtocol(config.session().sessionInfo().getProtocol());
sessionInfo.setPlayers(config.session().sessionInfo().getPlayers());
sessionInfo.setMaxPlayers(config.session().sessionInfo().getMaxPlayers());
} else {
sessionManager.logger().error("Failed to ping server", e);
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions bootstrap/standalone/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ session:
# This can be useful in the case of docker networks or routing problems causing the native ping to fail
web-query-fallback: false

# Fallback to config values if all other server query methods fail
config-fallback: false

# The data to broadcast over xbox live, this is the default if querying is enabled
session-info:
host-name: "Geyser Test Server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ public int getPort() {
public void setPort(int port) {
this.port = port;
}

public SessionInfo copy() {
return new SessionInfo(hostName, worldName, version, protocol, players, maxPlayers, ip, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public record SessionConfig(
@JsonProperty("update-interval") int updateInterval,
@JsonProperty("query-server") boolean queryServer,
@JsonProperty("web-query-fallback") boolean webQueryFallback,
@JsonProperty("config-fallback") boolean configFallback,
@JsonProperty("session-info") SessionInfo sessionInfo) {
}

0 comments on commit 43472fe

Please sign in to comment.