diff --git a/ext/python-a2s-rcon-api/docker-compose.yaml b/ext/python-a2s-rcon-api/docker-compose.yaml index bef689a..6fc8379 100644 --- a/ext/python-a2s-rcon-api/docker-compose.yaml +++ b/ext/python-a2s-rcon-api/docker-compose.yaml @@ -2,6 +2,6 @@ services: a2s_backend: build: ./ extra_hosts: - - "tf2.pblr-nyk.pro:192.168.3.3" + - "tf2.pblr-nyk.pro:192.168.3.1" ports: - 8085:8082 \ No newline at end of file diff --git a/ext/python-a2s-rcon-api/service.py b/ext/python-a2s-rcon-api/service.py index 9138e55..af86ff0 100644 --- a/ext/python-a2s-rcon-api/service.py +++ b/ext/python-a2s-rcon-api/service.py @@ -119,6 +119,8 @@ class SourceBackend: continue try: players.append(RCONPlayer(line).__dict__) + except BotPlayer: + pass except: traceback.print_exc() pass diff --git a/src/main/java/app/updates/BanCountUpdater.java b/src/main/java/app/updates/BanCountUpdater.java index c7b6563..7e50174 100644 --- a/src/main/java/app/updates/BanCountUpdater.java +++ b/src/main/java/app/updates/BanCountUpdater.java @@ -4,6 +4,8 @@ import app.entities.Stats; import jakarta.annotation.PostConstruct; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +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,6 +20,8 @@ public class BanCountUpdater extends BaseUpdater{ @PersistenceContext EntityManager entityManager; + private final Logger logger = LoggerFactory.getLogger(BanCountUpdater.class); + @Autowired public BanCountUpdater(Stats stats) { this.stats = stats; @@ -26,11 +30,13 @@ public class BanCountUpdater extends BaseUpdater{ @PostConstruct public void SetUpdater(){ if(update) { + logger.warn("Updater enabled"); CreateTaskUpdater(this::UpdateBanCount, 5 * 60 * 1000); } } public boolean UpdateBanCount(){ + logger.info("Update current ban count"); stats.setBan_count((Long) entityManager.createNativeQuery("SELECT COUNT(*) as count FROM `light_bans` WHERE active = 1").getSingleResult()); stats.getUpdates().merge("ban_count", Instant.now().getEpochSecond(), (x, y) -> y); return true; diff --git a/src/main/java/app/updates/BaseUpdater.java b/src/main/java/app/updates/BaseUpdater.java index f008f95..89e5c13 100644 --- a/src/main/java/app/updates/BaseUpdater.java +++ b/src/main/java/app/updates/BaseUpdater.java @@ -1,11 +1,16 @@ package app.updates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.concurrent.Executors; import java.util.function.Supplier; public abstract class BaseUpdater { + private final Logger logger = LoggerFactory.getLogger(BaseUpdater.class); + public void CreateTaskUpdater(Supplier function, int timeout) { - System.out.printf("Create task: %s, update after %d sec\n", function.toString(), timeout / 1000); + logger.warn("Create task: {}, update every {} seconds", function.toString(), timeout / 1000); Executors.newFixedThreadPool(1).submit(() -> { while (true) { try { diff --git a/src/main/java/app/updates/CountriesUpdater.java b/src/main/java/app/updates/CountriesUpdater.java index 74dbe3d..1efae1f 100644 --- a/src/main/java/app/updates/CountriesUpdater.java +++ b/src/main/java/app/updates/CountriesUpdater.java @@ -7,6 +7,8 @@ import com.maxmind.geoip2.exception.GeoIp2Exception; import jakarta.annotation.PostConstruct; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +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; @@ -22,6 +24,8 @@ public class CountriesUpdater extends BaseUpdater{ @PersistenceContext EntityManager entityManager; + private final Logger logger = LoggerFactory.getLogger(CountriesUpdater.class); + @Value("${backend.updates.countries}") private boolean update; @@ -37,11 +41,13 @@ public class CountriesUpdater extends BaseUpdater{ @PostConstruct public void UpdateCountries(){ if (update) { + logger.warn("Updater enabled"); CreateTaskUpdater(this::UpdateCountriesStatistic, 30 * 60 * 1000); } } public boolean UpdateCountriesStatistic() { + logger.info("Update countries statistic"); stats.getCountries().clear(); String query = ""; diff --git a/src/main/java/app/updates/PlayersUpdater.java b/src/main/java/app/updates/PlayersUpdater.java index 02288e8..2e383dc 100644 --- a/src/main/java/app/updates/PlayersUpdater.java +++ b/src/main/java/app/updates/PlayersUpdater.java @@ -2,6 +2,8 @@ package app.updates; import app.entities.Stats; import jakarta.annotation.PostConstruct; +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.context.ApplicationContext; @@ -18,7 +20,7 @@ public class PlayersUpdater extends BaseUpdater{ @Value("${backend.updates.a2s}") private boolean update = false; private int timeout = 60 * 1000; - + private final Logger logger = LoggerFactory.getLogger(PlayersUpdater.class); @Autowired public PlayersUpdater(Stats stats) { this.stats = stats; @@ -27,8 +29,10 @@ public class PlayersUpdater extends BaseUpdater{ @PostConstruct public void updateValues() { if (update) { + logger.warn("Updater enabled"); stats.getServers().forEach((server_name, server) -> { CreateTaskUpdater(() -> { + logger.info("Update players from: {} server", server_name); server.RefreshServerA2SData(); stats.getUpdates().merge(server_name, Instant.now().getEpochSecond(), (x, y) -> y); return null; diff --git a/src/main/java/app/updates/SocialUpdater.java b/src/main/java/app/updates/SocialUpdater.java index f1b8905..771a917 100644 --- a/src/main/java/app/updates/SocialUpdater.java +++ b/src/main/java/app/updates/SocialUpdater.java @@ -4,6 +4,8 @@ import app.entities.Stats; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.annotation.PostConstruct; +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; @@ -20,6 +22,8 @@ public class SocialUpdater extends BaseUpdater{ ObjectMapper objectMapper; Stats stats; + private final Logger logger = LoggerFactory.getLogger(SocialUpdater.class); + @Value("${backend.social.discord}") private String discord_url = ""; @@ -36,15 +40,18 @@ public class SocialUpdater extends BaseUpdater{ @PostConstruct public void SetUpdater(){ if(!discord_url.isEmpty()) { + logger.warn("Discord count updater enabled"); CreateTaskUpdater(this::UpdateDiscordCount, 5 * 60 * 1000); } if(!vk_url.isEmpty()){ + logger.warn("VK count updater enabled"); CreateTaskUpdater(this::UpdateVKCount, 5 * 60 * 1000); } } public boolean UpdateDiscordCount(){ try { + logger.info("Request discord count users"); stats.setDiscord_users(objectMapper.readTree(new URL(discord_url)).get("approximate_member_count").asInt()); stats.getUpdates().merge("discord_count", Instant.now().getEpochSecond(), (x, y) -> y); } catch (IOException err) {} @@ -52,6 +59,7 @@ public class SocialUpdater extends BaseUpdater{ } public boolean UpdateVKCount() { + logger.info("Request vk group count users"); int count = 0; String response = restTemplate.getForEntity(vk_url, String.class).getBody(); int k_start = response.indexOf("