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("

") + "

".length(); diff --git a/src/main/java/app/updates/UniqueUpdater.java b/src/main/java/app/updates/UniqueUpdater.java index 0b04117..893ba8c 100644 --- a/src/main/java/app/updates/UniqueUpdater.java +++ b/src/main/java/app/updates/UniqueUpdater.java @@ -5,6 +5,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; @@ -23,6 +25,8 @@ public class UniqueUpdater extends BaseUpdater{ private final String query_month = "SELECT DISTINCT `account_id` FROM `%s`.`user_connections` WHERE `connection_type` LIKE \"disconnect\" AND `connect_duration` > 300 AND `timestamp` > CAST(DATE_FORMAT(NOW() ,'%%Y-%%m-01') as DATE) UNION\n"; private final String query_year = "SELECT DISTINCT `account_id` FROM `%s`.`user_connections` WHERE `connection_type` LIKE \"disconnect\" AND `connect_duration` > 300 AND `timestamp` > CAST(DATE_FORMAT(NOW() ,'%%Y-01-01') as DATE) UNION\n"; + private final Logger logger = LoggerFactory.getLogger(UniqueUpdater.class); + @Value("${backend.updates.unique_global}") boolean global_update = false; @Value("${backend.updates.unique_server}") @@ -36,6 +40,7 @@ public class UniqueUpdater extends BaseUpdater{ @PostConstruct public void updateValues() throws InterruptedException { if(global_update) { + logger.warn("Global updater enabled"); Thread.sleep(2000); CreateTaskUpdater(this::UpdateServerUniqueTotal, 24 * 60 * 60 * 1000); CreateTaskUpdater(this::UpdateServerUniqueYear, 24 * 60 * 60 * 1000); @@ -44,6 +49,7 @@ public class UniqueUpdater extends BaseUpdater{ } /////////////////////////////////////////////////////////////////////////////////////// if(server_update) { + logger.warn("Per server updater enabled"); stats.getServers().forEach((server_name, server) -> { CreateTaskUpdater(() -> getServerUnique(server_name, server.getDb()), 5 * 60 * 1000); }); @@ -75,21 +81,25 @@ public class UniqueUpdater extends BaseUpdater{ } public boolean UpdateServerUniqueTotal() { + logger.info("Update >total< servers player unique count"); stats.UpdateUniq("total", getServerUniqueFromQuery(query_total)); return true; } public boolean UpdateServerUniqueYear() { + logger.info("Update >current year< servers player unique count"); stats.UpdateUniq("year", getServerUniqueFromQuery(query_year)); return true; } public boolean UpdateServerUniqueMonth() { + logger.info("Update >current month< servers player unique count"); stats.UpdateUniq("month", getServerUniqueFromQuery(query_month)); return true; } public boolean UpdateServerUniqueDay() { + logger.info("Update >current day< servers player unique count"); stats.UpdateUniq("day", getServerUniqueFromQuery(query_day)); return true; } diff --git a/src/main/java/app/updates/VipCountUpdater.java b/src/main/java/app/updates/VipCountUpdater.java index 0fdf967..dce0f25 100644 --- a/src/main/java/app/updates/VipCountUpdater.java +++ b/src/main/java/app/updates/VipCountUpdater.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; @@ -17,6 +19,8 @@ public class VipCountUpdater extends BaseUpdater{ @PersistenceContext EntityManager entityManager; + private final Logger logger = LoggerFactory.getLogger(VipCountUpdater.class); + @Value("${backend.updates.vip_count}") private boolean update = false; private int timeout = 5 * 60 * 1000; @@ -29,12 +33,14 @@ public class VipCountUpdater extends BaseUpdater{ @PostConstruct public void SetUpdater(){ if (update) { + logger.warn("Updater enabled"); CreateTaskUpdater(this::UpdateVIPCount, timeout); CreateTaskUpdater(this::UpdateFreeVIPCount, timeout); } } public boolean UpdateVIPCount() { + logger.info("Update current active VIP profiles"); stats.setVip_players( (Long) entityManager.createNativeQuery("SELECT COUNT(*) as count FROM `sm_admins` WHERE `status` LIKE 'VIP' AND (`comment` LIKE 'Donate.User' OR `comment` LIKE 'f13bot.User')") .getSingleResult()); @@ -43,6 +49,7 @@ public class VipCountUpdater extends BaseUpdater{ } public boolean UpdateFreeVIPCount() { + logger.info("Update current active FreeVIP profiles"); stats.setFreevip_players( (Long) entityManager.createNativeQuery("SELECT COUNT(*) as count FROM `sm_admins` WHERE `status` LIKE 'VIP' AND `comment` LIKE 'f13bot.FreeVIP'") .getSingleResult());