Browse Source

update 228

master
gsd 5 months ago
parent
commit
5d8bb3a910
  1. 14
      src/main/java/app/entities/Stats.java
  2. 2
      src/main/java/app/services/StatsService.java
  3. 4
      src/main/java/app/services/db/web/CollectStatisticService.java
  4. 10
      src/main/java/app/services/io/readers/GeoIP.java
  5. 1
      src/main/java/app/updates/BaseUpdater.java
  6. 8
      src/main/java/app/updates/CountriesUpdater.java

14
src/main/java/app/entities/Stats.java

@ -8,14 +8,14 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Data
@Component
@Scope(value = "singleton")
public class Stats {
private static final List<String> WHITELIST = List.of("United States", "Israel", "Ukraine", "Belarus", "Russia", "Kazakhstan");
long ban_count = 0;
int discord_users = 0;
long freevip_players = 0;
@ -96,9 +96,17 @@ public class Stats {
return new HashMap<>() {{
countries.forEach((name, count) -> {
if (name != null && count != null && count > 0) {
put(name, count);
if (WHITELIST.contains(name))
put(name, count);
else
merge("Other world", count, Integer::sum);
}
});
}};
}
@JsonIgnore
public HashMap<String, Integer> getCountriesWriter() {
return countries;
}
}

2
src/main/java/app/services/StatsService.java

@ -37,7 +37,7 @@ public class StatsService {
player.getId(),
cryptedCookie.Hashed(player.getIp()),
player.getName(),
geoIP.GetCountry(player.getIp().split(":", 2)[0], "Unknown"));
geoIP.GetCountry(player.getIp().split(":", 2)[0]));
}
return null;
}

4
src/main/java/app/services/db/web/CollectStatisticService.java

@ -45,14 +45,10 @@ public class CollectStatisticService extends BaseUpdater {
if (!collectableStatistic.isStatsRequests())
logger.info(collectableStatistic.toString());
UUID rnd = UUID.randomUUID();
Long cur = Instant.now().getEpochSecond();
logger.info("[~] Stats " + rnd.toString());
jdbcTemplate.update("INSERT INTO web_statistic (steam64, client_ip, method, path, query, useragent) VALUES (?, ?, ?, ?, ?, ?)",
collectableStatistic.getSteam64(), collectableStatistic.getClient_ip(),
collectableStatistic.getMethod(), collectableStatistic.getPath(),
collectableStatistic.getQuery(), collectableStatistic.getUseragent());
logger.info("[+] Stats " + rnd.toString() + " ts: " + (Instant.now().getEpochSecond() - cur) + "s");
} catch (Exception err) {
logger.error("Ignoring add stats");
}

10
src/main/java/app/services/io/readers/GeoIP.java

@ -26,15 +26,11 @@ public class GeoIP extends BaseReader {
}
}
public String GetCountry(String ip) throws UnknownHostException, GeoIp2Exception, IOException {
return databaseReader.country(InetAddress.getByName(ip)).getCountry().getName();
}
public String GetCountry(String ip, String replace) {
public String GetCountry(String ip) {
try {
return this.GetCountry(ip);
return databaseReader.country(InetAddress.getByName(ip)).getCountry().getName();
} catch (GeoIp2Exception | IOException e) {
return replace;
return "Unknown";
}
}

1
src/main/java/app/updates/BaseUpdater.java

@ -20,6 +20,7 @@ public abstract class BaseUpdater {
public void CreateTaskUpdater(Supplier function, int timeout, String name) {
logger.warn("Create task: {}, update every {} seconds", name, timeout / 1000);
Executors.newFixedThreadPool(1).submit(() -> {
Thread.currentThread().setName(name);
while (true) {
try {
//System.out.printf("Call: %s\n", function.toString());

8
src/main/java/app/updates/CountriesUpdater.java

@ -52,14 +52,10 @@ public class CountriesUpdater extends BaseUpdater{
public boolean UpdateCountriesStatistic() {
logger.info("Update countries statistic");
stats.getCountries().clear();
stats.getCountriesWriter().clear();
jdbcTemplate.query(countries_in_current_year, (rs, n) -> rs.getString("connect_ip")).forEach(ip -> {
try {
stats.getCountries().merge(geoIP.GetCountry(ip), 1, (x, y) -> x+y);
} catch (IOException | GeoIp2Exception e) {
logger.error("Cannot update country", e);
}
stats.getCountriesWriter().merge(geoIP.GetCountry(ip), 1, Integer::sum);
});
return true;
}

Loading…
Cancel
Save