From b99047d69637a0d178420698bedaafe146082bea Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 9 Jul 2021 11:15:48 +0200 Subject: [PATCH] Added public testing server registry ip. --- .../servers/PublicServerListModel.java | 6 ++-- .../aos_server_registry/ServerRegistry.java | 30 ++++++++++++------- .../aos_server_registry/defaults.properties | 2 +- .../src/main/resources/default_settings.yaml | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java b/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java index 0b0264e..268dff3 100644 --- a/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java +++ b/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java @@ -28,6 +28,8 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; public class PublicServerListModel extends AbstractListModel { + public static final String REGISTRY_URL = "http://37.97.207.39:25566/serverInfo"; + private final List currentPageItems; private boolean firstPage; private boolean lastPage; @@ -77,11 +79,10 @@ public class PublicServerListModel extends AbstractListModel { } public void fetchPage(int page, String query, String order, String orderDir) { - System.out.println("Fetching..."); if (this.pageFetchFuture != null && !this.pageFetchFuture.isDone()) { this.pageFetchFuture.cancel(false); } - String uri = "http://localhost:8567/serverInfo?page=" + page + "&size=" + this.pageSize; + String uri = REGISTRY_URL + "?page=" + page + "&size=" + this.pageSize; if (query != null && !query.isBlank()) { uri += "&q=" + URLEncoder.encode(query, StandardCharsets.UTF_8); } @@ -91,6 +92,7 @@ public class PublicServerListModel extends AbstractListModel { if (orderDir != null && !orderDir.isBlank()) { uri += "&dir=" + URLEncoder.encode(orderDir, StandardCharsets.UTF_8); } + System.out.println("Fetching from " + uri); HttpRequest request; try { request = HttpRequest.newBuilder().GET().uri(new URI(uri)).header("Accept", "application/json").build(); diff --git a/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/ServerRegistry.java b/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/ServerRegistry.java index 3fa5517..98c584d 100644 --- a/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/ServerRegistry.java +++ b/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/ServerRegistry.java @@ -23,15 +23,7 @@ public class ServerRegistry { public static final ObjectMapper mapper = new ObjectMapper(); public static void main(String[] args) throws ServletException, IOException { - Properties props = new Properties(); - props.load(ServerRegistry.class.getResourceAsStream("/nl/andrewlalis/aos_server_registry/defaults.properties")); - Path settingsPath = Path.of(SETTINGS_FILE); - if (Files.exists(settingsPath)) { - props.load(Files.newBufferedReader(settingsPath)); - } else { - System.out.println("Using built-in default settings. Create a settings.properties file to configure."); - } - + var props = loadProperties(); startServer(Integer.parseInt(props.getProperty("port"))); // Every few minutes, prune all stale servers from the registry. @@ -48,6 +40,7 @@ public class ServerRegistry { * @throws ServletException If the server could not be started. */ private static void startServer(int port) throws ServletException { + System.out.println("Starting server on port " + port + "."); DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(ServerRegistry.class.getClassLoader()) .setContextPath("/") @@ -60,9 +53,26 @@ public class ServerRegistry { manager.deploy(); HttpHandler servletHandler = manager.start(); Undertow server = Undertow.builder() - .addHttpListener(port, "localhost") + .addHttpListener(port, "0.0.0.0") .setHandler(servletHandler) .build(); server.start(); } + + /** + * Loads properties from all necessary locations. + * @return The properties that were loaded. + * @throws IOException If an error occurs while reading properties. + */ + private static Properties loadProperties() throws IOException { + Properties props = new Properties(); + props.load(ServerRegistry.class.getResourceAsStream("/nl/andrewlalis/aos_server_registry/defaults.properties")); + Path settingsPath = Path.of(SETTINGS_FILE); + if (Files.exists(settingsPath)) { + props.load(Files.newBufferedReader(settingsPath)); + } else { + System.out.println("Using built-in default settings. Create a settings.properties file to configure."); + } + return props; + } } diff --git a/server-registry/src/main/resources/nl/andrewlalis/aos_server_registry/defaults.properties b/server-registry/src/main/resources/nl/andrewlalis/aos_server_registry/defaults.properties index 32fbaf4..a06a634 100644 --- a/server-registry/src/main/resources/nl/andrewlalis/aos_server_registry/defaults.properties +++ b/server-registry/src/main/resources/nl/andrewlalis/aos_server_registry/defaults.properties @@ -1,5 +1,5 @@ # Default properties for the AOS Server Registry -port=8567 +port=25566 prune-delay=60 prune-threshold-minutes=5 diff --git a/server/src/main/resources/default_settings.yaml b/server/src/main/resources/default_settings.yaml index 2cb42a8..96fa788 100644 --- a/server/src/main/resources/default_settings.yaml +++ b/server/src/main/resources/default_settings.yaml @@ -17,7 +17,7 @@ registry-settings: # Set this to true to allow other players to see this server and join it. discoverable: false # The URI which points to the registry server. This is only used if discoverable is true. - registry-uri: "http://localhost:8567" + registry-uri: "http://37.97.207.39:25566" # How often to send status updates to the registry server, in seconds. update-interval: 30 # The name of this server.