From 8ccd9854bafa19fc6ab3b2e7c38576c7ddb602f6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 23 Nov 2017 22:12:45 +0200 Subject: [PATCH] Network page parsing, Fixed error pages in WebAPI mode --- .../plan/database/tables/UserInfoTable.java | 28 +++++++ .../info/parsing/NetworkPageParser.java | 2 +- .../systems/webserver/APIResponseHandler.java | 4 + .../webserver/response/DebugPageResponse.java | 5 +- .../plan/utilities/html/HtmlStructure.java | 82 +++++++++++++++---- .../web/js/charts/playerGraphNoNav.js | 37 +++++++++ .../main/resources/web/network - Example.html | 10 +-- Plan/src/main/resources/web/network.html | 13 +-- .../plan/database/DatabaseTest.java | 1 + 9 files changed, 145 insertions(+), 37 deletions(-) create mode 100644 Plan/src/main/resources/web/js/charts/playerGraphNoNav.js diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java index 7dfa1323d..77d5a89df 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java @@ -4,6 +4,7 @@ */ package main.java.com.djrapitops.plan.database.tables; +import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException; @@ -314,4 +315,31 @@ public class UserInfoTable extends UserIDTable { } }); } + + public int getServerUserCount(UUID serverUUID) { + try { + String sql = "SELECT " + + " COUNT(" + columnRegistered + ") as c" + + " FROM " + tableName + + " WHERE " + columnServerID + "=" + serverTable.statementSelectServerID; + + return query(new QueryStatement(sql, 20000) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, serverUUID.toString()); + } + + @Override + public Integer processResults(ResultSet set) throws SQLException { + if (set.next()) { + return set.getInt("c"); + } + return 0; + } + }); + } catch (SQLException e) { + Log.toLog(this.getClass().getName(), e); + return 0; + } + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java index 13d7ac840..5cd5c1c8c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java @@ -56,7 +56,7 @@ public class NetworkPageParser extends PageParser { addValue("playersNewWeek", AnalysisUtils.getNewPlayers(registerDates, TimeAmount.WEEK.ms(), now)); Map networkPageContents = ((BungeeInformationManager) plugin.getInfoManager()).getNetworkPageContent(); - addValue("contentServers", HtmlStructure.createNetworkPageContent(networkPageContents)); + addValue("tabContentServers", HtmlStructure.createNetworkPageContent(networkPageContents)); return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/network.html"), placeHolders); } catch (Exception e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java index 1695489e7..295a8d657 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java @@ -48,6 +48,10 @@ public class APIResponseHandler { return PageCache.loadPage(target + "css", () -> new CSSResponse(target)); } + if (target.endsWith(".js")) { + return PageCache.loadPage(target + "js", () -> new JavaScriptResponse(target)); + } + if (args.length < 2 || !"api".equals(args[1])) { String address = MiscUtils.getIPlan().getInfoManager().getWebServerAddress() + target; String link = Html.LINK.parse(address, address); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java index 5ad64dfe8..8c8919f2d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/DebugPageResponse.java @@ -106,12 +106,11 @@ public class DebugPageResponse extends ErrorResponse { Collection bukkitServers = serverInfoManager.getBukkitServers(); if (!bukkitServers.isEmpty()) { - content.append("

If your issue is about Bungee-Bukkit connection relations, please include the following debug information of available servers as well: "); + content.append("

If your issue is about Bungee-Bukkit connection relations, please include the following debug information of available servers as well:

"); for (ServerInfo info : bukkitServers) { String link = Html.LINK.parse(info.getWebAddress() + "/debug", info.getWebAddress() + "/debug"); - content.append(link).append("
"); + content.append("

").append(link).append("

"); } - content.append("

"); } content.append("
### Bungee Configuration
"); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java index d022d5f4d..41e542a80 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java @@ -4,20 +4,25 @@ */ package main.java.com.djrapitops.plan.utilities.html; +import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.ServerVariableHolder; import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.PluginData; +import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; +import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator; import main.java.com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator; import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import org.apache.commons.lang3.text.StrSubstitutor; import java.io.Serializable; +import java.sql.SQLException; import java.util.*; /** @@ -312,16 +317,12 @@ public class HtmlStructure { List values = new ArrayList<>(networkPageContents.values()); Collections.sort(values); int size = values.size(); - int extra = size % 3; - for (int j = 0; j < extra; j++) { - values.add("
"); - } for (String server : values) { - if (i % 3 == 0) { - b.append("
"); + if (i % 2 == 0) { + b.append("
"); } b.append(server); - if ((i + 1) % 3 == 0 || i + 1 == size) { + if ((i + 1) % 2 == 0 || i + 1 == size) { b.append("
"); } i++; @@ -330,23 +331,72 @@ public class HtmlStructure { } public static String createServerContainer(Plan plugin) { - int maxPlayers = plugin.getVariable().getMaxPlayers(); + ServerVariableHolder variable = plugin.getVariable(); + int maxPlayers = variable.getMaxPlayers(); int online = plugin.getServer().getOnlinePlayers().size(); Optional analysisRefreshDate = ((BukkitInformationManager) plugin.getInfoManager()).getAnalysisRefreshDate(); String refresh = analysisRefreshDate.map(FormatUtils::formatTimeStamp).orElse("-"); String serverName = plugin.getServerInfoManager().getServerName(); + String serverType = variable.getVersion(); String address = "../server/" + serverName; - return "
" + "

" + - serverName + - "

" + - "

" + online + "/" + maxPlayers + - " Players Online

" + - "

Last Refresh: " + refresh + "

" + - "Analysis" + - "
"; + Database db = plugin.getDB(); + UUID serverUUID = plugin.getServerUuid(); + String id = serverUUID.toString().replace("-", ""); + + int playerCount = db.getUserInfoTable().getServerUserCount(serverUUID); + String playerData = "[]"; + try { + playerData = PlayerActivityGraphCreator.buildSeriesDataString(db.getTpsTable().getTPSData(serverUUID)); + } catch (SQLException e) { + Log.toLog(HtmlStructure.class.getClass().getName(), e); + } + + return "
" + + "
" + + "
" + + "
" + + "
" + + "

" + serverName + "

" + + "
" + + "
" + + "
" + + "
" + + "
" + + "
" + + "
" + + "
" + + "
" + + "

Registered Players " + + "" + playerCount + "

" + + "

Players Online " + + "" + online + " / " + maxPlayers + "

" + + "

Type " + + "" + serverType + "

" + + "
" + + "

Last Refresh" + + "" + refresh + "

" + + "
" + + "
" + + "" + + ""; } public static String parseOfflineServerContainer(String oldContent) { diff --git a/Plan/src/main/resources/web/js/charts/playerGraphNoNav.js b/Plan/src/main/resources/web/js/charts/playerGraphNoNav.js new file mode 100644 index 000000000..cb1914b3a --- /dev/null +++ b/Plan/src/main/resources/web/js/charts/playerGraphNoNav.js @@ -0,0 +1,37 @@ +function playersChartNoNav(id, playersOnlineSeries) { + Highcharts.stockChart(id, { + rangeSelector: { + selected: 3, + buttons: [{ + type: 'hour', + count: 12, + text: '12h' + }, { + type: 'hour', + count: 24, + text: '24h' + }, { + type: 'day', + count: 7, + text: '7d' + }, { + type: 'month', + count: 1, + text: '30d' + }, { + type: 'all', + text: 'All' + }] + }, + navigator: { + enabled: false + }, + title: {text: ''}, + plotOptions: { + areaspline: { + fillOpacity: 0.4 + } + }, + series: [playersOnlineSeries] + }); +} \ No newline at end of file diff --git a/Plan/src/main/resources/web/network - Example.html b/Plan/src/main/resources/web/network - Example.html index 64c29e53d..a4cdc4581 100644 --- a/Plan/src/main/resources/web/network - Example.html +++ b/Plan/src/main/resources/web/network - Example.html @@ -233,14 +233,8 @@ ${playersTotal}
  • - Unique Players / Day - (AVG.) - ${playersAverage} -
  • -
  • - New Players / Day - (AVG.) - ${playersNewAverage} + Players Online + ${playersOnline}
  • Last Peak: ${lastPeakTime} +
    @@ -233,14 +234,8 @@ ${playersTotal}
  • - Unique Players / Day - (AVG.) - ${playersAverage} -
  • -
  • - New Players / Day - (AVG.) - ${playersNewAverage} + Players Online + ${playersOnline}
  • Last Peak: ${lastPeakTime} - +