Browse Source

проблема есть карты меняются

master
gsd 2 years ago
parent
commit
d21b03cecc
  1. 8
      src/main/java/app/entities/server/Server.java
  2. 3
      src/main/java/app/entities/steam/SteamData.java
  3. 10
      src/main/java/app/services/db/UsertimeService.java
  4. 9
      src/main/java/app/services/io/ServersReader.java

8
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) {

3
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();
}
}

10
src/main/java/app/services/db/UsertimeService.java

@ -36,7 +36,7 @@ public class UsertimeService {
for (Map.Entry<String, Server> 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<String, Server> 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<List> 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<List> 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());
}

9
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<Map.Entry<String, JsonNode>> iterator = node.fields();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> 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);
}
}
}

Loading…
Cancel
Save