From 813abd040a73689eb127d8bfa7618d09e66f59e9 Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sat, 3 Sep 2022 12:15:54 +0300 Subject: [PATCH] Add 'Data_gathering.Preserve_join_address_case' setting (default false) - Allows preserving case information of gathered join addresses - Only affects future data --- .../domain/datatransfer/ServerDto.java | 23 ++++++++++++++++++- .../events/PlayerJoinEventConsumer.java | 4 +++- .../config/paths/DataGatheringSettings.java | 1 + .../database/queries/LargeStoreQueries.java | 2 +- .../queries/objects/JoinAddressQueries.java | 4 +--- .../database/sql/tables/JoinAddressTable.java | 4 ++-- .../events/StoreJoinAddressTransaction.java | 2 +- .../patches/SessionJoinAddressPatch.java | 6 ++--- .../resources/assets/plan/bungeeconfig.yml | 2 ++ .../src/main/resources/assets/plan/config.yml | 2 ++ Plan/react/dashboard/package.json | 2 +- 11 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/datatransfer/ServerDto.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/datatransfer/ServerDto.java index 0c5944051..38cd401f2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/datatransfer/ServerDto.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/datatransfer/ServerDto.java @@ -17,11 +17,14 @@ package com.djrapitops.plan.delivery.domain.datatransfer; import com.djrapitops.plan.identification.Server; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; /** * Represents outgoing server information json. */ -public class ServerDto { +public class ServerDto implements Comparable { private final String serverUUID; private final String serverName; @@ -49,6 +52,24 @@ public class ServerDto { return proxy; } + @Override + public int compareTo(@NotNull ServerDto other) { + return String.CASE_INSENSITIVE_ORDER.compare(this.serverName, other.serverName); + } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + ServerDto serverDto = (ServerDto) other; + return isProxy() == serverDto.isProxy() && Objects.equals(getServerUUID(), serverDto.getServerUUID()) && Objects.equals(getServerName(), serverDto.getServerName()); + } + + @Override + public int hashCode() { + return Objects.hash(getServerUUID(), getServerName(), isProxy()); + } + @Override public String toString() { return "ServerDto{" + diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java index 3120b01aa..794c79e40 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java @@ -38,6 +38,7 @@ import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable; import com.djrapitops.plan.storage.database.transactions.Transaction; import com.djrapitops.plan.storage.database.transactions.events.*; +import org.apache.commons.lang3.StringUtils; import javax.inject.Inject; import javax.inject.Singleton; @@ -109,6 +110,7 @@ public class PlayerJoinEventConsumer { private void storeJoinAddress(PlayerJoin join) { join.getPlayer().getJoinAddress() + .map(joinAddress -> config.isTrue(DataGatheringSettings.PRESERVE_JOIN_ADDRESS_CASE) ? joinAddress : StringUtils.lowerCase(joinAddress)) .map(StoreJoinAddressTransaction::new) .ifPresent(dbSystem.getDatabase()::executeTransaction); } @@ -165,7 +167,7 @@ public class PlayerJoinEventConsumer { join.getPlayer().getCurrentGameMode().orElse(null)); session.getExtraData().put(PlayerName.class, new PlayerName(join.getPlayer().getName())); session.getExtraData().put(ServerName.class, new ServerName(join.getServer().isProxy() ? join.getServer().getName() : "Proxy Server")); - session.getExtraData().put(JoinAddress.class, new JoinAddress(join.getJoinAddress())); + session.getExtraData().put(JoinAddress.class, new JoinAddress(config.isTrue(DataGatheringSettings.PRESERVE_JOIN_ADDRESS_CASE) ? join.getJoinAddress() : StringUtils.lowerCase(join.getJoinAddress()))); return session; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/config/paths/DataGatheringSettings.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/config/paths/DataGatheringSettings.java index f0fa90207..f662d4e7b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/config/paths/DataGatheringSettings.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/config/paths/DataGatheringSettings.java @@ -32,6 +32,7 @@ public class DataGatheringSettings { public static final Setting DISK_SPACE = new BooleanSetting("Data_gathering.Disk_space"); public static final Setting LOG_UNKNOWN_COMMANDS = new BooleanSetting("Data_gathering.Commands.Log_unknown"); public static final Setting COMBINE_COMMAND_ALIASES = new BooleanSetting("Data_gathering.Commands.Log_aliases_as_main_command"); + public static final Setting PRESERVE_JOIN_ADDRESS_CASE = new BooleanSetting("Data_gathering.Preserve_join_address_case"); private DataGatheringSettings() { /* static variable class */ diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java index 75adb79c3..31a9b4987 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java @@ -318,7 +318,7 @@ public class LargeStoreQueries { .filter(Optional::isPresent) .map(Optional::get) .map(JoinAddress::getAddress) - .map(String::toLowerCase) +// .map(String::toLowerCase) .filter(address -> !existingJoinAddresses.contains(address)) .distinct() .forEach(address -> { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/JoinAddressQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/JoinAddressQueries.java index 9fc34a50d..48428040f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/JoinAddressQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/JoinAddressQueries.java @@ -108,8 +108,6 @@ public class JoinAddressQueries { new TextStringBuilder().appendWithSeparators(joinAddresses.stream().map(item -> '?').iterator(), ",") + ')'; // Don't append addresses directly, SQL injection hazard - return db -> db.querySet(sql, RowExtractors.getInt(SessionsTable.USER_ID), joinAddresses - .stream().map(String::toLowerCase) - .toArray()); + return db -> db.querySet(sql, RowExtractors.getInt(SessionsTable.USER_ID), joinAddresses.toArray()); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java index 6556efa70..c9f82b80b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java @@ -29,9 +29,9 @@ public class JoinAddressTable { public static final String JOIN_ADDRESS = "join_address"; public static final int JOIN_ADDRESS_MAX_LENGTH = 191; - public static final String SELECT_ID = '(' + SELECT + ID + FROM + TABLE_NAME + WHERE + JOIN_ADDRESS + "=LOWER(?))"; + public static final String SELECT_ID = '(' + SELECT + ID + FROM + TABLE_NAME + WHERE + JOIN_ADDRESS + "=?)"; public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + - " (" + JOIN_ADDRESS + ") VALUES (LOWER(?))"; + " (" + JOIN_ADDRESS + ") VALUES (?)"; public static final String DEFAULT_VALUE_FOR_LOOKUP = "unknown"; private JoinAddressTable() {} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java index 78869e524..c1227d411 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java @@ -61,7 +61,7 @@ public class StoreJoinAddressTransaction extends Transaction { } private String getAddress() { - return StringUtils.truncate(joinAddress.get().toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH); + return StringUtils.truncate(joinAddress.get(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH); } @Override diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java index f9af6428e..63b90869c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java @@ -44,7 +44,7 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.*; public class SessionJoinAddressPatch extends Patch { public static Query> uniqueJoinAddressesOld() { - String sql = SELECT + DISTINCT + "LOWER(COALESCE(" + UserInfoTable.JOIN_ADDRESS + ", ?)) as address" + + String sql = SELECT + DISTINCT + "COALESCE(" + UserInfoTable.JOIN_ADDRESS + ", ?) as address" + FROM + UserInfoTable.TABLE_NAME + ORDER_BY + "address ASC"; return new QueryStatement<>(sql, 100) { @@ -79,7 +79,7 @@ public class SessionJoinAddressPatch extends Patch { private Integer getDefaultAddressId() { return query(new QueryStatement<>(SELECT + ID + FROM + JoinAddressTable.TABLE_NAME + - WHERE + JoinAddressTable.JOIN_ADDRESS + "=LOWER(?)") { + WHERE + JoinAddressTable.JOIN_ADDRESS + "=?") { @Override public void prepare(PreparedStatement statement) throws SQLException { statement.setString(1, JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP); @@ -99,7 +99,7 @@ public class SessionJoinAddressPatch extends Patch { @Override public void prepare(PreparedStatement statement) throws SQLException { for (String joinAddress : joinAddresses) { - statement.setString(1, StringUtils.truncate(joinAddress.toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH)); + statement.setString(1, StringUtils.truncate(joinAddress, JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH)); statement.addBatch(); } } diff --git a/Plan/common/src/main/resources/assets/plan/bungeeconfig.yml b/Plan/common/src/main/resources/assets/plan/bungeeconfig.yml index f1132043f..997f86b3f 100644 --- a/Plan/common/src/main/resources/assets/plan/bungeeconfig.yml +++ b/Plan/common/src/main/resources/assets/plan/bungeeconfig.yml @@ -96,6 +96,8 @@ Data_gathering: Accept_GeoLite2_EULA: false Ping: true Disk_space: true + # Does not affect already gathered data + Preserve_join_address_case: false # ----------------------------------------------------- # Supported time units: MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS # ----------------------------------------------------- diff --git a/Plan/common/src/main/resources/assets/plan/config.yml b/Plan/common/src/main/resources/assets/plan/config.yml index a90b355cf..12794f214 100644 --- a/Plan/common/src/main/resources/assets/plan/config.yml +++ b/Plan/common/src/main/resources/assets/plan/config.yml @@ -101,6 +101,8 @@ Data_gathering: Commands: Log_unknown: false Log_aliases_as_main_command: true + # Does not affect already gathered data + Preserve_join_address_case: false # ----------------------------------------------------- # Supported time units: MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS # ----------------------------------------------------- diff --git a/Plan/react/dashboard/package.json b/Plan/react/dashboard/package.json index b1efa5c56..06b225dc1 100644 --- a/Plan/react/dashboard/package.json +++ b/Plan/react/dashboard/package.json @@ -3,7 +3,7 @@ "name": "dashboard", "version": "0.1.0", "private": true, - "proxy": "https://localhost:8804", + "proxy": "http://localhost:8800", "dependencies": { "@fortawesome/fontawesome-free": "^6.2.0", "@fortawesome/fontawesome-svg-core": "^6.2.0",