From d21b03ceccddd5b259ad4256b6f37149d90b5298 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 14 Mar 2023 17:59:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D0=B5=D1=81=D1=82=D1=8C=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=B5=D0=BD=D1=8F=D1=8E=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/app/entities/server/Server.java | 8 +++++++- src/main/java/app/entities/steam/SteamData.java | 3 ++- src/main/java/app/services/db/UsertimeService.java | 10 +++++----- src/main/java/app/services/io/ServersReader.java | 9 +++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java index f9f7f5a..8bc923b 100644 --- a/src/main/java/app/entities/server/Server.java +++ b/src/main/java/app/entities/server/Server.java @@ -35,10 +35,16 @@ public class Server extends ExternalValveClient { private String dc; @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private String rcon_password; + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private int grab_maps_limit = 1; @Override public String toString() { - return "Address: %s\nPlayers: %d/%d\nMap: %s".formatted(address, player_count, max_players, map); + return "SERVER> %s | %s\nSTATS > %d/%d | %s\nCONFIG> grab limit: %d".formatted( + name, address, + player_count, max_players, map, + grab_maps_limit + ); } public void UpdateUniq(String key, Long count) { diff --git a/src/main/java/app/entities/steam/SteamData.java b/src/main/java/app/entities/steam/SteamData.java index bb604d6..522069f 100644 --- a/src/main/java/app/entities/steam/SteamData.java +++ b/src/main/java/app/entities/steam/SteamData.java @@ -11,6 +11,7 @@ public class SteamData { public SteamData(JsonNode player){ nickname = player.get("personaname").asText(); - avatar = player.get("avatar").asText(); + if (player.has("avatarfull")) avatar = player.get("avatarfull").asText(); + else avatar = player.get("avatar").asText(); } } diff --git a/src/main/java/app/services/db/UsertimeService.java b/src/main/java/app/services/db/UsertimeService.java index 2cd5d79..4174e26 100644 --- a/src/main/java/app/services/db/UsertimeService.java +++ b/src/main/java/app/services/db/UsertimeService.java @@ -36,7 +36,7 @@ public class UsertimeService { for (Map.Entry stringServerEntry : stats.getServers().entrySet()) { if(last_map) { - maps = getMap(stringServerEntry.getValue().getDb()).orElse(List.of()); + maps = getMap(stringServerEntry.getValue().getDb(), stringServerEntry.getValue().getGrab_maps_limit()).orElse(List.of()); } else { maps = getMaps(stringServerEntry.getValue().getDb()).orElse(List.of()); } @@ -62,7 +62,7 @@ public class UsertimeService { for (Map.Entry stringServerEntry : stats.getServers().entrySet()) { if(last_map) { - maps = getMap(stringServerEntry.getValue().getDb()).orElse(List.of()); + maps = getMap(stringServerEntry.getValue().getDb(), stringServerEntry.getValue().getGrab_maps_limit()).orElse(List.of()); } else { maps = getMaps(stringServerEntry.getValue().getDb()).orElse(List.of()); } @@ -102,9 +102,9 @@ public class UsertimeService { return response.size() > 0 ? response.get(0) : null; } - public Optional getMap(String db) { - return Optional.ofNullable(entityManager.createNativeQuery("select `map` from `"+db+"`.`user_connections` WHERE 1 ORDER BY `user_connections`.`id` DESC LIMIT 1") - //.setParameter(1, db) + public Optional getMap(String db, int limit) { + return Optional.ofNullable(entityManager.createNativeQuery("select distinct `map` from `"+db+"`.`user_connections` WHERE 1 ORDER BY `user_connections`.`id` DESC LIMIT ?1") + .setParameter(1, limit) .getResultList()); } diff --git a/src/main/java/app/services/io/ServersReader.java b/src/main/java/app/services/io/ServersReader.java index 7d9551f..e47cee1 100644 --- a/src/main/java/app/services/io/ServersReader.java +++ b/src/main/java/app/services/io/ServersReader.java @@ -2,8 +2,11 @@ package app.services.io; import app.entities.server.Server; import app.entities.Stats; +import app.updates.PlayersUpdater; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -18,21 +21,23 @@ public class ServersReader { Stats stats; ObjectMapper objectMapper; + private final Logger logger = LoggerFactory.getLogger(ServersReader.class); @Autowired public ServersReader(Stats stats, @Value("${backend.servers_file}") String servers_path) { this.stats = stats; this.objectMapper = new ObjectMapper(); try { - System.out.printf("Read from: %s\n", servers_path); + logger.info("Read from: {}", servers_path); JsonNode node = this.objectMapper.readTree(new File(servers_path)); Iterator> iterator = node.fields(); while (iterator.hasNext()) { Map.Entry server = iterator.next(); stats.getServers().put(server.getKey(), this.objectMapper.treeToValue(server.getValue(), Server.class)); + logger.info("{}\n{}",server.getKey() ,stats.getServers().get(server.getKey())); } } catch (IOException err) { - System.out.printf("Cannot read servers file: %s\n", servers_path); + logger.error("Cannot read servers file: {}", servers_path); } } }