Player Hostname PieChart Added (#1679 #1786)

Affects issues:
- Close #783

Co-authored-by: Arnold Hamstra <youtube@minecraftercity.com>
Co-authored-by: Arnold <a_hamstra@hotmail.com>
This commit is contained in:
Risto Lahtela 2021-03-09 10:01:09 +02:00 committed by GitHub
parent d61c85962f
commit 4da7497d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 334 additions and 75 deletions

View File

@ -177,8 +177,9 @@ public abstract class BukkitImporter implements Importer {
long registered = userImportData.getRegistered();
boolean op = userImportData.isOp();
boolean banned = userImportData.isBanned();
String hostname = userImportData.getHostname();
return new UserInfo(uuid, serverUUID.get(), registered, op, banned);
return new UserInfo(uuid, serverUUID.get(), registered, op, hostname, banned);
}
private Session toSession(UserImportData userImportData) {

View File

@ -155,6 +155,7 @@ public class PlayerOnlineListener implements Listener {
String world = player.getWorld().getName();
String gm = player.getGameMode().name();
String hostname = player.getAddress().getHostName();
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
@ -171,7 +172,9 @@ public class PlayerOnlineListener implements Listener {
);
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID));
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID,
player::getFirstPlayed, playerName, serverUUID, hostname));
Session session = new Session(playerUUID, serverUUID, time, world, gm);
session.putRawData(SessionKeys.NAME, playerName);
session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());

View File

@ -125,6 +125,7 @@ public class NetworkPageExporter extends FileExporter {
"graph?type=uniqueAndNew",
"graph?type=hourlyUniqueAndNew",
"graph?type=serverPie",
"graph?type=hostnamePie",
"graph?type=activity",
"graph?type=geolocation",
"graph?type=uniqueAndNew",

View File

@ -71,6 +71,7 @@ public class Contributors {
new Contributor("galexrt", LANG),
new Contributor("QuakyCZ", LANG),
new Contributor("MrFriggo", LANG),
new Contributor("vacoup", CODE),
};
private Contributors() {

View File

@ -405,4 +405,14 @@ public class GraphJSONCreator {
.put("server_pie_series_30d", graphs.pie().serverPreferencePie(playtimePerServer).getSlices())
.build();
}
public Map<String, Object> playerHostnamePieJSONAsMap() {
String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
Map<String, Integer> hostnameResults = dbSystem.getDatabase().query(UserInfoQueries.hostnameTotals());
return Maps.builder(String.class, Object.class)
.put("hostname_pie_colors", pieColors)
.put("hostname_pie_slices", graphs.pie().HostnamePie(hostnameResults).getSlices())
.build();
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.delivery.rendering.json.graphs.pie;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class HostnamePie extends Pie {
HostnamePie(Map<String, Integer> hostnames) {
super(turnToSlices(hostnames));
}
private static List<PieSlice> turnToSlices(Map<String, Integer> hostnames) {
List<PieSlice> slices = new ArrayList<>();
for (Map.Entry<String, Integer> server : hostnames.entrySet()) {
String hostname = server.getKey();
Integer total = server.getValue();
slices.add(new PieSlice(hostname, total));
}
return slices;
}
}

View File

@ -68,6 +68,10 @@ public class PieGraphFactory {
return new ServerPreferencePie(serverPlaytimes);
}
public Pie HostnamePie(Map<String, Integer> hostname) {
return new HostnamePie(hostname);
}
public WorldPie worldPie(WorldTimes worldTimes) {
WorldAliasSettings worldAliasSettings = config.getWorldAliasSettings();
Map<String, Long> playtimePerAlias = worldAliasSettings.getPlaytimePerAlias(worldTimes);

View File

@ -40,6 +40,7 @@ public enum DataID {
GRAPH_ACTIVITY,
GRAPH_PING,
GRAPH_SERVER_PIE,
GRAPH_HOSTNAME_PIE,
GRAPH_PUNCHCARD,
SERVER_OVERVIEW,
ONLINE_OVERVIEW,

View File

@ -131,6 +131,8 @@ public class GraphsJSONResolver implements Resolver {
return DataID.GRAPH_PUNCHCARD;
case "serverPie":
return DataID.GRAPH_SERVER_PIE;
case "hostnamePie":
return DataID.GRAPH_HOSTNAME_PIE;
default:
throw new BadRequestException("unknown 'type' parameter.");
}
@ -175,6 +177,8 @@ public class GraphsJSONResolver implements Resolver {
return graphJSON.hourlyUniqueAndNewGraphJSON();
case GRAPH_SERVER_PIE:
return graphJSON.serverPreferencePieJSONAsMap();
case GRAPH_HOSTNAME_PIE:
return graphJSON.playerHostnamePieJSONAsMap();
case GRAPH_WORLD_MAP:
return graphJSON.geolocationGraphsJSONAsMap();
default:

View File

@ -34,13 +34,15 @@ public class UserInfo {
private final long registered;
private final boolean banned;
private final boolean opped;
private final String hostname;
public UserInfo(UUID playerUUID, UUID serverUUID, long registered, boolean opped, boolean banned) {
public UserInfo(UUID playerUUID, UUID serverUUID, long registered, boolean opped, String hostname, boolean banned) {
this.playerUUID = playerUUID;
this.serverUUID = serverUUID;
this.registered = registered;
this.opped = opped;
this.banned = banned;
this.hostname = hostname;
}
public UUID getPlayerUuid() {
@ -51,6 +53,10 @@ public class UserInfo {
return serverUUID;
}
public String getHostname() {
return hostname;
}
public long getRegistered() {
return registered;
}
@ -77,7 +83,7 @@ public class UserInfo {
@Override
public int hashCode() {
return Objects.hash(playerUUID, serverUUID, registered, banned, opped);
return Objects.hash(playerUUID, serverUUID, registered, banned, hostname, opped);
}
@Override
@ -88,6 +94,7 @@ public class UserInfo {
", registered=" + registered +
", banned=" + banned +
", opped=" + opped +
", hostname=" + hostname +
'}';
}
}

View File

@ -44,7 +44,11 @@ public class UserImportData {
private int mobKills;
private int deaths;
private UserImportData(String name, UUID uuid, List<Nickname> nicknames, long registered, boolean op, boolean banned, int timesKicked, List<String> ips, Map<String, GMTimes> worldTimes, List<PlayerKill> kills, int mobKills, int deaths) {
private String hostname;
private UserImportData(String name, UUID uuid, List<Nickname> nicknames, long registered, boolean op,
boolean banned, int timesKicked, List<String> ips, Map<String, GMTimes> worldTimes, List<PlayerKill> kills,
int mobKills, int deaths, String hostname) {
this.name = name;
this.uuid = uuid;
this.nicknames = nicknames;
@ -57,6 +61,7 @@ public class UserImportData {
this.kills = kills;
this.mobKills = mobKills;
this.deaths = deaths;
this.hostname = hostname;
}
public static UserImportDataBuilder builder(UUID serverUUID) {
@ -111,6 +116,14 @@ public class UserImportData {
this.banned = banned;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public String getHostname() {
return hostname;
}
public int getTimesKicked() {
return timesKicked;
}
@ -174,6 +187,7 @@ public class UserImportData {
private int timesKicked;
private int mobKills;
private int deaths;
private String hostname;
private UserImportDataBuilder(UUID serverUUID) {
this.serverUUID = serverUUID;
@ -284,7 +298,8 @@ public class UserImportData {
}
public UserImportData build() {
return new UserImportData(name, uuid, nicknames, registered, op, banned, timesKicked, ips, worldTimes, kills, mobKills, deaths);
return new UserImportData(name, uuid, nicknames, registered, op, banned, timesKicked, ips,
worldTimes, kills, mobKills, deaths, hostname);
}
}
@ -299,6 +314,7 @@ public class UserImportData {
timesKicked == that.timesKicked &&
mobKills == that.mobKills &&
deaths == that.deaths &&
hostname.equals(that.hostname) &&
Objects.equals(name, that.name) &&
Objects.equals(uuid, that.uuid) &&
Objects.equals(nicknames, that.nicknames) &&
@ -309,6 +325,7 @@ public class UserImportData {
@Override
public int hashCode() {
return Objects.hash(name, uuid, nicknames, registered, op, banned, timesKicked, ips, worldTimes, kills, mobKills, deaths);
return Objects.hash(name, uuid, nicknames, registered, op, banned, timesKicked, ips,
worldTimes, kills, mobKills, deaths, hostname);
}
}

View File

@ -174,6 +174,7 @@ public abstract class SQLDB extends AbstractDatabase {
new LinkedToSecurityTablePatch(),
new LinkUsersToPlayersSecurityTablePatch(),
new LitebansTableHeaderPatch(),
new UserInfoHostnamePatch(),
new ServerIsProxyPatch()
};
}

View File

@ -190,7 +190,7 @@ public class DataStoreQueries {
* @param serverUUID UUID of the Plan server.
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable registerUserInfo(UUID playerUUID, long registered, UUID serverUUID) {
public static Executable registerUserInfo(UUID playerUUID, long registered, UUID serverUUID, String hostname) {
return new ExecStatement(UserInfoTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
@ -198,7 +198,8 @@ public class DataStoreQueries {
statement.setLong(2, registered);
statement.setString(3, serverUUID.toString());
statement.setBoolean(4, false); // Banned
statement.setBoolean(5, false); // Operator
statement.setString(5, hostname); // Hostname
statement.setBoolean(6, false); // Operator
}
};
}

View File

@ -227,7 +227,8 @@ public class LargeStoreQueries {
statement.setLong(2, user.getRegistered());
statement.setString(3, serverUUID.toString());
statement.setBoolean(4, user.isBanned());
statement.setBoolean(5, user.isOperator());
statement.setString(5, user.getHostname());
statement.setBoolean(6, user.isOperator());
statement.addBatch();
}
}

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.gathering.domain.UserInfo;
import com.djrapitops.plan.storage.database.queries.Query;
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
import com.djrapitops.plan.storage.database.queries.QueryStatement;
import com.djrapitops.plan.storage.database.sql.tables.ServerTable;
import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable;
import com.djrapitops.plan.utilities.java.Lists;
@ -54,7 +55,8 @@ public class UserInfoQueries {
UserInfoTable.BANNED + ',' +
UserInfoTable.OP + ',' +
UserInfoTable.USER_UUID + ',' +
UserInfoTable.SERVER_UUID +
UserInfoTable.SERVER_UUID + ',' +
UserInfoTable.HOSTNAME +
FROM + UserInfoTable.TABLE_NAME;
return new QueryAllStatement<Map<UUID, List<UserInfo>>>(sql, 50000) {
@ -70,8 +72,9 @@ public class UserInfoQueries {
long registered = set.getLong(UserInfoTable.REGISTERED);
boolean banned = set.getBoolean(UserInfoTable.BANNED);
boolean op = set.getBoolean(UserInfoTable.OP);
String hostname = set.getString(UserInfoTable.HOSTNAME);
userInfos.add(new UserInfo(uuid, serverUUID, registered, op, banned));
userInfos.add(new UserInfo(uuid, serverUUID, registered, op, hostname, banned));
}
return serverMap;
}
@ -89,7 +92,8 @@ public class UserInfoQueries {
UserInfoTable.TABLE_NAME + '.' + UserInfoTable.REGISTERED + ',' +
UserInfoTable.BANNED + ',' +
UserInfoTable.OP + ',' +
UserInfoTable.SERVER_UUID +
UserInfoTable.SERVER_UUID + ',' +
UserInfoTable.HOSTNAME +
FROM + UserInfoTable.TABLE_NAME +
WHERE + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + "=?";
@ -107,7 +111,9 @@ public class UserInfoQueries {
boolean op = set.getBoolean(UserInfoTable.OP);
boolean banned = set.getBoolean(UserInfoTable.BANNED);
UUID serverUUID = UUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
userInformation.add(new UserInfo(playerUUID, serverUUID, registered, op, banned));
String hostname = set.getString(UserInfoTable.HOSTNAME);
userInformation.add(new UserInfo(playerUUID, serverUUID, registered, op, hostname, banned));
}
return userInformation;
}
@ -124,11 +130,13 @@ public class UserInfoQueries {
String sql = SELECT +
UserInfoTable.REGISTERED + ',' +
UserInfoTable.BANNED + ',' +
UserInfoTable.HOSTNAME + ',' +
UserInfoTable.OP + ',' +
UserInfoTable.USER_UUID + ',' +
UserInfoTable.SERVER_UUID +
FROM + UserInfoTable.TABLE_NAME +
WHERE + UserInfoTable.SERVER_UUID + "=?";
return new QueryStatement<Map<UUID, UserInfo>>(sql, 1000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
@ -146,7 +154,9 @@ public class UserInfoQueries {
boolean banned = set.getBoolean(UserInfoTable.BANNED);
boolean op = set.getBoolean(UserInfoTable.OP);
userInformation.put(uuid, new UserInfo(uuid, serverUUID, registered, op, banned));
String hostname = set.getString(UserInfoTable.HOSTNAME);
userInformation.put(uuid, new UserInfo(uuid, serverUUID, registered, op, hostname, banned));
}
return userInformation;
}
@ -184,6 +194,28 @@ public class UserInfoQueries {
};
}
public static Query<Map<String, Integer>> hostnameTotals() {
String sql = SELECT +
"COUNT(hostname) as total," +
UserInfoTable.HOSTNAME +
FROM + UserInfoTable.TABLE_NAME +
GROUP_BY + UserInfoTable.HOSTNAME;
return new QueryStatement<Map<String, Integer>>(sql, 100) {
@Override
public void prepare(PreparedStatement statement) {}
@Override
public Map<String, Integer> processResults(ResultSet set) throws SQLException {
Map<String, Integer> hostnames = new HashMap<>();
while (set.next()) {
hostnames.put(set.getString(UserInfoTable.HOSTNAME), set.getInt("total"));
}
return hostnames;
}
};
}
public static Query<Set<UUID>> uuidsOfOperators() {
return getUUIDsForBooleanGroup(UserInfoTable.OP, true);
}

View File

@ -42,14 +42,16 @@ public class UserInfoTable {
public static final String REGISTERED = "registered";
public static final String OP = "opped";
public static final String BANNED = "banned";
public static final String HOSTNAME = "hostname";
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" +
USER_UUID + ',' +
REGISTERED + ',' +
SERVER_UUID + ',' +
BANNED + ',' +
HOSTNAME + ',' +
OP +
") VALUES (?, ?, ?, ?, ?)";
") VALUES (?, ?, ?, ?, ?, ?)";
private UserInfoTable() {
/* Static information class */
@ -60,6 +62,7 @@ public class UserInfoTable {
.column(ID, Sql.INT).primaryKey()
.column(USER_UUID, Sql.varchar(36)).notNull()
.column(SERVER_UUID, Sql.varchar(36)).notNull()
.column(HOSTNAME, Sql.varchar(255)).notNull().defaultValue("'Unknown'")
.column(REGISTERED, Sql.LONG).notNull()
.column(OP, Sql.BOOL).notNull().defaultValue(false)
.column(BANNED, Sql.BOOL).notNull().defaultValue(false)

View File

@ -31,10 +31,13 @@ import java.util.function.LongSupplier;
public class PlayerServerRegisterTransaction extends PlayerRegisterTransaction {
private final UUID serverUUID;
private final String hostname;
public PlayerServerRegisterTransaction(UUID playerUUID, LongSupplier registered, String playerName, UUID serverUUID) {
public PlayerServerRegisterTransaction(UUID playerUUID, LongSupplier registered,
String playerName, UUID serverUUID, String hostname) {
super(playerUUID, registered, playerName);
this.serverUUID = serverUUID;
this.hostname = hostname;
}
@Override
@ -42,7 +45,7 @@ public class PlayerServerRegisterTransaction extends PlayerRegisterTransaction {
super.performOperations();
long registerDate = registered.getAsLong();
if (Boolean.FALSE.equals(query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID)))) {
execute(DataStoreQueries.registerUserInfo(playerUUID, registerDate, serverUUID));
execute(DataStoreQueries.registerUserInfo(playerUUID, registerDate, serverUUID, hostname));
}
// Updates register date to smallest possible value.

View File

@ -0,0 +1,39 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.storage.database.transactions.patches;
import com.djrapitops.plan.storage.database.sql.building.Sql;
import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable;
/**
* Patch to add 'hostname' to 'plan_user_info'
*
* @author vacoup95
*/
public class UserInfoHostnamePatch extends Patch {
@Override
public boolean hasBeenApplied() {
return hasColumn(UserInfoTable.TABLE_NAME, UserInfoTable.HOSTNAME);
}
@Override
protected void applyPatch() {
addColumn(UserInfoTable.TABLE_NAME, UserInfoTable.HOSTNAME + ' '
+ Sql.varchar(255) + " NOT NULL DEFAULT 'Unknown'");
}
}

View File

@ -418,6 +418,34 @@ function serverPie(id, serverSeries) {
}));
}
function hostnamePie(id, hostnameTotals) {
graphs.push(Highcharts.chart(id, {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {text: ''},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
tooltip: {
formatter: function () {
return '<b>' + this.point.name + ':</b> ' + this.y + ' (' + this.percentage.toFixed(2) + '%)';
}
},
series: [hostnameTotals]
}));
}
function formatTimeAmount(ms) {
let out = "";

View File

@ -415,4 +415,18 @@ function loadGeolocationGraph(json, error) {
document.getElementById('worldMap').innerText = errorMessage;
document.getElementById('countryBarChart').innerText = errorMessage;
}
}
function loadHostnamePie(json, error) {
if (json) {
hostnamePieSeries = {
name: 'Used IP Addresses',
colorByPoint: true,
colors: json.hostname_pie_colors,
data: json.hostname_pie_slices
};
hostnamePie('hostnamePie', hostnamePieSeries);
} else if (error) {
document.getElementById('hostnamePie').innerText = `Failed to load graph data: ${error}`;
}
}

View File

@ -505,6 +505,7 @@
</div>
<div class="row">
<!-- Trends for 30 days -->
<div class="col-lg-8 mb-8 col-sm-12">
<div class="card shadow mb-4">
@ -582,29 +583,43 @@
</table>
</div>
</div> <!-- Trends for 30 days-->
<!-- Insights -->
<div class="col-lg-4 mb-4 col-sm-12">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold col-black"><i
class="far fa-fw fa-life-ring col-red"></i>
Insights for 30 days</h6>
<div class="col-lg-4 col-sm-12">
<div class="mb-4 col-lg-12 col-sm-12">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold col-black"><i
class="far fa-fw fa-life-ring col-red"></i>
Insights for 30 days</h6>
</div>
<div class="card-body" id="data_insights">
<p><i class="fa fa-fw fa-user col-light-green"></i> New <i
class="fa fa-fw fa-long-arrow-alt-right"></i> <i
class="fa fa-fw fa-user col-lime"></i> Regular<span
class="float-right"><b><span
id="data_new_to_regular"></span></b></span></p>
<p><i class="fa fa-fw fa-user col-lime"></i> Regular <i
class="fa fa-fw fa-long-arrow-alt-right"></i> <i
class="fa fa-fw fa-user col-blue-grey"></i> Inactive<span
class="float-right"><b><span
id="data_regular_to_inactive"></span></b></span></p>
<p class="float-right"><i class="text-success fa fa-caret-up"></i><i
class="text-danger fa fa-caret-down"></i>
<small>Comparing 30d ago to Now</small>
</p>
</div>
</div>
<div class="card-body" id="data_insights">
<p><i class="fa fa-fw fa-user col-light-green"></i> New <i
class="fa fa-fw fa-long-arrow-alt-right"></i> <i
class="fa fa-fw fa-user col-lime"></i> Regular<span
class="float-right"><b><span
id="data_new_to_regular"></span></b></span></p>
<p><i class="fa fa-fw fa-user col-lime"></i> Regular <i
class="fa fa-fw fa-long-arrow-alt-right"></i> <i
class="fa fa-fw fa-user col-blue-grey"></i> Inactive<span
class="float-right"><b><span
id="data_regular_to_inactive"></span></b></span></p>
<p class="float-right"><i class="text-success fa fa-caret-up"></i><i
class="text-danger fa fa-caret-down"></i>
<small>Comparing 30d ago to Now</small>
</p>
<!-- Hostname Analytics -->
<div class="card shadow mb-4">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold col-black">
<i class="fa fa-fw fa-users col-amber"></i>
Used hostnames
</h6>
</div>
<div class="chart-area" id="hostnamePie"></div>
</div>
</div>
</div>
@ -902,6 +917,7 @@
refreshingJsonRequest("./v1/graph?type=uniqueAndNew", loadUniqueAndNewGraph, 'network-overview');
refreshingJsonRequest("./v1/graph?type=hourlyUniqueAndNew", loadHourlyUniqueAndNewGraph, 'network-overview');
refreshingJsonRequest("./v1/graph?type=serverPie", loadServerPie, 'sessions-overview');
refreshingJsonRequest("./v1/graph?type=hostnamePie", loadHostnamePie, 'playerbase-overview');
refreshingJsonRequest("./v1/graph?type=activity", loadActivityGraphs, 'playerbase-overview');
refreshingJsonRequest("./v1/graph?type=geolocation", loadGeolocationGraph, 'geolocations');

View File

@ -67,7 +67,8 @@ import static org.junit.jupiter.api.Assertions.*;
public interface DatabaseTest extends DatabaseTestPreparer {
default void saveUserOne() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new KickStoreTransaction(playerUUID));
}
@ -93,7 +94,8 @@ public interface DatabaseTest extends DatabaseTestPreparer {
default void testRemovalSingleUser() {
saveUserTwo();
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
saveTwoWorlds();
Session session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
@ -271,7 +273,8 @@ public interface DatabaseTest extends DatabaseTestPreparer {
@Test
default void registerDateIsMinimized() {
executeTransactions(
new PlayerServerRegisterTransaction(playerUUID, () -> 1000, TestConstants.PLAYER_ONE_NAME, serverUUID())
new PlayerServerRegisterTransaction(playerUUID, () -> 1000,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME)
, new Transaction() {
@Override
protected void performOperations() {
@ -299,8 +302,10 @@ public interface DatabaseTest extends DatabaseTestPreparer {
default void serverTablePlayersQueryQueriesAtLeastOnePlayer() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime,
TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID)));
List<TablePlayer> result = db().query(new ServerTablePlayersQuery(serverUUID(), System.currentTimeMillis(), 10L, 1));
@ -312,8 +317,10 @@ public interface DatabaseTest extends DatabaseTestPreparer {
default void networkTablePlayersQueryQueriesAtLeastOnePlayer() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime,
TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID)));
List<TablePlayer> result = db().query(new NetworkTablePlayersQuery(System.currentTimeMillis(), 10L, 1));

View File

@ -51,8 +51,10 @@ import static org.junit.jupiter.api.Assertions.*;
public interface ActivityIndexQueriesTest extends DatabaseTestPreparer {
default void storeSessions(Predicate<Session> save) {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime,
TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
for (String world : worlds) {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), world));
}

View File

@ -47,8 +47,10 @@ public interface DatabaseBackupTest extends DatabaseTestPreparer {
default void saveDataForBackup() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime,
TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
Session session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
execute(DataStoreQueries.storeSession(session));
@ -94,6 +96,7 @@ public interface DatabaseBackupTest extends DatabaseTestPreparer {
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData());
assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation());
assertQueryResultIsEqual(db(), backup, WebUserQueries.fetchAllUsers());
} finally {
backup.close();
}

View File

@ -40,7 +40,8 @@ public interface GeolocationQueriesTest extends DatabaseTestPreparer {
@Test
default void geoInformationIsStored() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
List<GeoInfo> expected = RandomData.randomGeoInfo();
for (GeoInfo geoInfo : expected) {
@ -102,7 +103,8 @@ public interface GeolocationQueriesTest extends DatabaseTestPreparer {
Database db = db();
for (UUID uuid : uuids) {
db.executeTransaction(new PlayerServerRegisterTransaction(uuid, () -> 0L, "", serverUUID()));
db.executeTransaction(new PlayerServerRegisterTransaction(uuid, () -> 0L, "", serverUUID(),
TestConstants.PLAYER_HOSTNAME));
}
save(firstUuid, new GeoInfo("Norway", 0));

View File

@ -37,7 +37,8 @@ public interface NicknameQueriesTest extends DatabaseTestPreparer {
@Test
default void allNicknamesAreSaved() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
List<Nickname> saved = RandomData.randomNicknames(serverUUID());
for (Nickname nickname : saved) {

View File

@ -76,8 +76,10 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
default void prepareForSessionSave() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime,
TestConstants.PLAYER_ONE_NAME, serverUUID(),TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime,
TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
}
@Test

View File

@ -42,41 +42,44 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
@Test
default void userInfoTableStoresCorrectUserInformation() {
assertFalse(db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).isPresent());
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, false));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.PLAYER_HOSTNAME, false));
assertEquals(expected, userInfo);
}
@Test
default void userInfoTableUpdatesBanStatus() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new BanStatusTransaction(playerUUID, () -> true));
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, true));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.PLAYER_HOSTNAME, true));
assertEquals(expected, userInfo);
}
@Test
default void userInfoTableUpdatesOperatorStatus() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
db().executeTransaction(new OperatorStatusTransaction(playerUUID, true));
List<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, true, false));
List<UserInfo> expected = Collections.singletonList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, true, TestConstants.PLAYER_HOSTNAME, false));
assertEquals(expected, userInfo);
}
@Test
default void playerNameIsUpdatedWhenPlayerLogsIn() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
OptionalAssert.equals(playerUUID, db().query(UserIdentifierQueries.fetchPlayerUUIDOf(TestConstants.PLAYER_ONE_NAME)));
@ -149,7 +152,8 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
default void playerIsRegisteredToBothTables() {
assertFalse(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
assertFalse(db().query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID())));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME,
TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.PLAYER_HOSTNAME));
assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
assertTrue(db().query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID())));
}
@ -175,9 +179,12 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
db().executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(DataStoreQueries.registerUserInfo(playerUUID, 0L, serverUUID()));
execute(DataStoreQueries.registerUserInfo(playerUUID, 0L, serverUUID()));
execute(DataStoreQueries.registerUserInfo(player2UUID, 0L, serverUUID()));
execute(DataStoreQueries.registerUserInfo(playerUUID, 0L,
serverUUID(), TestConstants.PLAYER_HOSTNAME));
execute(DataStoreQueries.registerUserInfo(playerUUID, 0L,
serverUUID(), TestConstants.PLAYER_HOSTNAME));
execute(DataStoreQueries.registerUserInfo(player2UUID, 0L,
serverUUID(), TestConstants.PLAYER_HOSTNAME));
}
}).get();
@ -185,13 +192,13 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
List<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
assertEquals(
Collections.singletonList(new UserInfo(playerUUID, serverUUID(), 0, false, false)),
Collections.singletonList(new UserInfo(playerUUID, serverUUID(), 0, false, TestConstants.PLAYER_HOSTNAME, false)),
found
);
List<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
assertEquals(
Collections.singletonList(new UserInfo(player2UUID, serverUUID(), 0, false, false)),
Collections.singletonList(new UserInfo(player2UUID, serverUUID(), 0, false, TestConstants.PLAYER_HOSTNAME,false)),
found2
);
}

View File

@ -41,6 +41,8 @@ public class TestConstants {
public static final String PLAYER_TWO_NAME = "Test_Player_two";
public static final String PLAYER_THREE_NAME = RandomData.randomString(16);
public static final String PLAYER_HOSTNAME = "play.example.com";
public static final String WORLD_ONE_NAME = "World One";
public static final Long REGISTER_TIME = RandomData.randomTime();

View File

@ -115,8 +115,10 @@ public class TestData {
new Transaction() {
@Override
protected void performOperations() {
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName, serverUUID));
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerSecondJoin, playerName, server2UUID));
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerFirstJoin,
playerName, serverUUID, TestConstants.PLAYER_HOSTNAME));
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerSecondJoin,
playerName, server2UUID, TestConstants.PLAYER_HOSTNAME));
for (GeoInfo geoInfo : playerGeoInfo) {
executeOther(new GeoInfoStoreTransaction(playerUUID, geoInfo));
@ -136,8 +138,10 @@ public class TestData {
new Transaction() {
@Override
protected void performOperations() {
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name, serverUUID));
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerSecondJoin, player2Name, server2UUID));
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerFirstJoin,
player2Name, serverUUID, TestConstants.PLAYER_HOSTNAME));
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerSecondJoin,
player2Name, server2UUID, TestConstants.PLAYER_HOSTNAME));
for (GeoInfo geoInfo : playerGeoInfo) {
executeOther(new GeoInfoStoreTransaction(player2UUID, geoInfo));

View File

@ -1,5 +1,5 @@
#Tue Mar 10 21:27:56 EET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists

View File

@ -153,6 +153,7 @@ public class PlayerOnlineListener implements Listener {
String world = player.getLevel().getName();
String gm = GMTimes.magicNumberToGMName(player.getGamemode());
String hostname = player.getAddress();
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
@ -170,7 +171,8 @@ public class PlayerOnlineListener implements Listener {
}
long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate, playerName, serverUUID));
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate,
playerName, serverUUID, hostname));
Session session = new Session(playerUUID, serverUUID, time, world, gm);
session.putRawData(SessionKeys.NAME, playerName);
session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());

View File

@ -158,6 +158,7 @@ public class PlayerOnlineListener {
String world = player.getWorld().getName();
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
String gm = gameMode.map(mode -> mode.getName().toUpperCase()).orElse("ADVENTURE");
String hostname = player.getConnection().getVirtualHost().getHostString();
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
@ -174,7 +175,8 @@ public class PlayerOnlineListener {
);
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID));
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time,
playerName, serverUUID, hostname));
Session session = new Session(playerUUID, serverUUID, time, world, gm);
session.putRawData(SessionKeys.NAME, playerName);
session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());