diff --git a/pom.xml b/pom.xml
index 33e9e34..8af947e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,5 +92,11 @@
1.9.19
compile
+
+ junit
+ junit
+ 4.13.2
+ test
+
\ No newline at end of file
diff --git a/src/main/java/app/entities/Stats.java b/src/main/java/app/entities/Stats.java
index 6e92473..b8828ec 100644
--- a/src/main/java/app/entities/Stats.java
+++ b/src/main/java/app/entities/Stats.java
@@ -31,9 +31,9 @@ import java.util.concurrent.CompletionException;
public class Stats {
long ban_count = 0;
int discord_users = 0;
- int freevip_players = 0;
+ long freevip_players = 0;
int server_uptime = 0;
- int vip_players = 0;
+ long vip_players = 0;
int vk_users = 0;
HashMap countries = new HashMap<>();
HashMap servers = new HashMap<>();
diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java
index 5c3f38d..57c23bb 100644
--- a/src/main/java/app/entities/server/Server.java
+++ b/src/main/java/app/entities/server/Server.java
@@ -72,7 +72,9 @@ public class Server {
}
public void UpdatePlayersFromRCON(String response) {
- List players_list = Arrays.stream(response.substring(response.indexOf("# userid"), response.length()).split("\n")).toList();
+ int start_index = response.indexOf("# userid");
+ if (start_index == -1) return;
+ List players_list = Arrays.stream(response.substring(start_index, response.length()).split("\n")).toList();
boolean skip_table_header = true;
for(String player_text: players_list) {
if (skip_table_header || player_text.length() < 1) {
diff --git a/src/main/java/app/updates/BanCountUpdater.java b/src/main/java/app/updates/BanCountUpdater.java
index c75c584..a9952a6 100644
--- a/src/main/java/app/updates/BanCountUpdater.java
+++ b/src/main/java/app/updates/BanCountUpdater.java
@@ -36,7 +36,7 @@ public class BanCountUpdater {
}
public void UpdateBanCount(){
- stats.setBan_count((Long) entityManager.createNativeQuery("SELECT COUNT(*) as count FROM `light_bans`").getSingleResult());
+ 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);
}
}
diff --git a/src/main/java/app/updates/SocialUpdater.java b/src/main/java/app/updates/SocialUpdater.java
new file mode 100644
index 0000000..28f1ec1
--- /dev/null
+++ b/src/main/java/app/updates/SocialUpdater.java
@@ -0,0 +1,67 @@
+package app.updates;
+
+import app.entities.Stats;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.annotation.PostConstruct;
+import org.jobrunr.scheduling.JobScheduler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.time.Instant;
+
+@Component
+public class SocialUpdater {
+ RestTemplate restTemplate;
+ ObjectMapper objectMapper;
+ Stats stats;
+ JobScheduler jobScheduler;
+
+ @Value("${backend.social.discord}")
+ private String discord_url = "";
+
+ @Value("${backend.social.vk}")
+ private String vk_url;
+
+ @Autowired
+ public SocialUpdater(Stats stats,
+ JobScheduler jobScheduler) {
+ restTemplate = new RestTemplate();
+ objectMapper = new ObjectMapper();
+ this.stats = stats;
+ this.jobScheduler = jobScheduler;
+ }
+
+ @PostConstruct
+ public void SetUpdater(){
+ if(!discord_url.isEmpty()) {
+ jobScheduler.enqueue(() -> UpdateDiscordCount());
+ jobScheduler.scheduleRecurrently("*/5 * * * *", () -> UpdateDiscordCount());
+ jobScheduler.enqueue(() -> UpdateVKCount());
+ jobScheduler.scheduleRecurrently("*/5 * * * *", () -> UpdateVKCount());
+ }
+ }
+
+ public void UpdateDiscordCount() throws IOException {
+ 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);
+ }
+
+ public void UpdateVKCount() {
+ int count = 0;
+ String response = restTemplate.getForEntity(vk_url, String.class).getBody();
+ int k_start = response.indexOf("