From a9e032119cb74fd14d5b384cbf53f9e2060d3a7e Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Wed, 30 Jun 2021 13:19:32 +0200 Subject: [PATCH] Improved some behavior and logging. --- .../aos_server_registry/data/ServerDataPruner.java | 5 ++++- .../aos_server_registry/servlet/ServerInfoServlet.java | 8 ++++++-- .../java/nl/andrewlalis/aos_server/RegistryManager.java | 4 ++-- server/src/main/resources/help.txt | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/data/ServerDataPruner.java b/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/data/ServerDataPruner.java index 8800a96..371434c 100644 --- a/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/data/ServerDataPruner.java +++ b/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/data/ServerDataPruner.java @@ -2,6 +2,7 @@ package nl.andrewlalis.aos_server_registry.data; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.logging.Logger; /** * Scheduled task that runs once in a while and removes servers from the @@ -9,6 +10,8 @@ import java.sql.SQLException; */ public class ServerDataPruner implements Runnable { public static final int INTERVAL_MINUTES = 5; + private static final Logger log = Logger.getLogger(ServerDataPruner.class.getName()); + @Override public void run() { try { @@ -22,7 +25,7 @@ public class ServerDataPruner implements Runnable { int rowCount = stmt.executeUpdate(); stmt.close(); if (rowCount > 0) { - System.out.println("Removed " + rowCount + " servers from registry due to inactivity."); + log.info("Removed " + rowCount + " servers from registry due to inactivity."); } } catch (SQLException e) { e.printStackTrace(); diff --git a/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/servlet/ServerInfoServlet.java b/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/servlet/ServerInfoServlet.java index c1af99c..cc8ea68 100644 --- a/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/servlet/ServerInfoServlet.java +++ b/server-registry/src/main/java/nl/andrewlalis/aos_server_registry/servlet/ServerInfoServlet.java @@ -18,8 +18,11 @@ import java.time.ZoneOffset; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.logging.Logger; public class ServerInfoServlet extends HttpServlet { + private static final Logger log = Logger.getLogger(ServerInfoServlet.class.getName()); + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { int page = Requests.getIntParam(req, "page", 0, i -> i >= 0); @@ -120,7 +123,7 @@ public class ServerInfoServlet extends HttpServlet { int rowCount = createStmt.executeUpdate(); createStmt.close(); if (rowCount != 1) throw new SQLException("Could not insert new server."); - System.out.println("Registered new server " + info.name() + " @ " + info.address()); + log.info("Registered new server " + info.name() + " @ " + info.address()); } else { PreparedStatement updateStmt = con.prepareStatement(""" UPDATE servers SET description = ?, location = ?, max_players = ?, current_players = ? @@ -135,7 +138,7 @@ public class ServerInfoServlet extends HttpServlet { int rowCount = updateStmt.executeUpdate(); updateStmt.close(); if (rowCount != 1) throw new SQLException("Could not update server."); - System.out.println("Updated server information for " + info.name() + " @ " + info.address()); + log.info("Updated server information for " + info.name() + " @ " + info.address()); } } @@ -155,6 +158,7 @@ public class ServerInfoServlet extends HttpServlet { Responses.notFound(resp); } else { Responses.ok(resp); + log.info("Status updated for " + status.name() + " @ " + status.address()); } } catch (SQLException e) { e.printStackTrace(); diff --git a/server/src/main/java/nl/andrewlalis/aos_server/RegistryManager.java b/server/src/main/java/nl/andrewlalis/aos_server/RegistryManager.java index 68669fa..021999a 100644 --- a/server/src/main/java/nl/andrewlalis/aos_server/RegistryManager.java +++ b/server/src/main/java/nl/andrewlalis/aos_server/RegistryManager.java @@ -73,8 +73,8 @@ public class RegistryManager { .header("Content-Type", "application/json") .build(); this.httpClient.sendAsync(request, responseInfo -> { - if (responseInfo.statusCode() == 404) { - System.out.println("Received 404 when sending registry update. Re-sending registry info..."); + if (responseInfo.statusCode() != 200) { + System.out.println("Received non-OK status when sending registry update. Re-sending registry info..."); this.sendInfo(); } return null; diff --git a/server/src/main/resources/help.txt b/server/src/main/resources/help.txt index e9a7d52..e285b43 100644 --- a/server/src/main/resources/help.txt +++ b/server/src/main/resources/help.txt @@ -14,3 +14,4 @@ help Shows this help message. list Show a list of all connected players. kick

Kick a player with the given id or name. If more than one player exists with a given name, you need to use their unique id. +guns Lists all available guns that players may use in this server.