mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-20 07:02:21 +01:00
Encoded player & server names in URLs
This commit is contained in:
parent
56dae4c829
commit
de33cb1b4f
@ -19,6 +19,7 @@ package com.djrapitops.plan.api;
|
||||
import com.djrapitops.plan.api.data.PlayerContainer;
|
||||
import com.djrapitops.plan.api.data.ServerContainer;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.identification.UUIDUtility;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
@ -80,7 +81,7 @@ public class CommonAPI implements PlanAPI {
|
||||
|
||||
@Override
|
||||
public String getPlayerInspectPageLink(String playerName) {
|
||||
return "../player/" + playerName;
|
||||
return "../player/" + Html.encodeToURL(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.export.Exporter;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.exceptions.ExportException;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
@ -108,7 +109,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
}
|
||||
|
||||
private void sendLink(Server server, Sender sender) {
|
||||
String target = "/server/" + server.getName();
|
||||
String target = "/server/" + Html.encodeToURL(server.getName());
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String url = address + target;
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.identification.UUIDUtility;
|
||||
@ -132,7 +133,7 @@ public class InspectCommand extends CommandNode {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String url = address + "/player/" + playerName;
|
||||
String url = address + "/player/" + Html.encodeToURL(playerName);
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.commands.subcommands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
@ -69,7 +70,7 @@ public class ManageRawDataCommand extends CommandNode {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
// Link
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String url = address + "/player/" + playerName + "/raw";
|
||||
String url = address + "/player/" + Html.encodeToURL(playerName) + "/raw";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
|
@ -283,7 +283,9 @@ public class SessionsMutator {
|
||||
return sessions.stream().map(session -> {
|
||||
Map<String, Object> sessionMap = new HashMap<>();
|
||||
sessionMap.put("player_name", session.getValue(SessionKeys.NAME).orElse(session.getUnsafe(SessionKeys.UUID).toString()));
|
||||
sessionMap.put("player_uuid", session.getUnsafe(SessionKeys.UUID).toString());
|
||||
sessionMap.put("server_name", session.getValue(SessionKeys.SERVER_NAME).orElse(session.getUnsafe(SessionKeys.SERVER_UUID).toString()));
|
||||
sessionMap.put("server_uuid", session.getUnsafe(SessionKeys.SERVER_UUID).toString());
|
||||
sessionMap.put("name", nameFunction.apply(sessionMap));
|
||||
sessionMap.put("start", session.getValue(SessionKeys.START).map(formatters.yearLong()).orElse("-") +
|
||||
(session.supports(SessionKeys.END) ? "" : " (Online)"));
|
||||
|
@ -20,6 +20,8 @@ import org.apache.commons.text.StringSubstitutor;
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -169,4 +171,12 @@ public enum Html {
|
||||
sub.setEnableSubstitutionInVariables(false);
|
||||
return sub.replace(html);
|
||||
}
|
||||
|
||||
public static String encodeToURL(String string) {
|
||||
try {
|
||||
return URLEncoder.encode(string, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public class PlayersTableJSONParser {
|
||||
|
||||
private void appendPlayerData(StringBuilder dataJSON, TablePlayer player) {
|
||||
String name = player.getName().orElse(player.getPlayerUUID().toString());
|
||||
String url = "../player/" + name;
|
||||
String url = "../player/" + Html.encodeToURL(name);
|
||||
|
||||
int loginTimes = player.getSessionCount().orElse(0);
|
||||
long playtime = player.getPlaytime().orElse(-1L);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.delivery.webserver.pages;
|
||||
|
||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.Request;
|
||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
@ -68,7 +69,7 @@ public class RootPageHandler implements PageHandler {
|
||||
case 1:
|
||||
return new RedirectResponse("/players");
|
||||
case 2:
|
||||
return new RedirectResponse("/player/" + webUser.getName());
|
||||
return new RedirectResponse("/player/" + Html.encodeToURL(webUser.getName()));
|
||||
default:
|
||||
return responseFactory.forbidden403();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class ExtensionStringData implements DescribedExtensionData {
|
||||
|
||||
public String getFormattedValue() {
|
||||
String withColors = Html.swapColorCodesToSpan(value);
|
||||
return !playerName ? withColors : Html.LINK.parse("../player/" + value, withColors);
|
||||
return !playerName ? withColors : Html.LINK.parse("../player/" + Html.encodeToURL(value), withColors);
|
||||
}
|
||||
|
||||
ExtensionStringData concatenate(ExtensionStringData other) {
|
||||
|
@ -88,8 +88,8 @@ function createAccordionBody(i, session) {
|
||||
createKillsTable(session.player_kills) +
|
||||
'</div><div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">' +
|
||||
'<div id="worldpie_' + i + '" class="chart-pie"></div>' +
|
||||
'<a href="/player/' + session.player_name + '" class="float-right btn bg-blue"><i class="fa fa-user"></i><span> Player Page</span></a>' +
|
||||
(session.network_server ? '<a href="/server/' + session.server_name + '" class="float-right btn bg-light-green mr-2"><i class="fa fa-server"></i><span> Server Analysis</span></a>' : '') +
|
||||
'<a href="/player/' + session.player_uuid + '" class="float-right btn bg-blue"><i class="fa fa-user"></i><span> Player Page</span></a>' +
|
||||
(session.network_server ? '<a href="/server/' + session.server_uuid + '" class="float-right btn bg-light-green mr-2"><i class="fa fa-server"></i><span> Server Analysis</span></a>' : '') +
|
||||
'</div>' +
|
||||
'</div></td></tr>'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user