diff --git a/src/main/java/app/controllers/user/DetailController.java b/src/main/java/app/controllers/user/DetailController.java index 393ffbc..d462d4b 100644 --- a/src/main/java/app/controllers/user/DetailController.java +++ b/src/main/java/app/controllers/user/DetailController.java @@ -37,8 +37,9 @@ public class DetailController { @BurstUpdatePlayers @WaitAfterNext public ResponseEntity GetUser4Web(HttpServletRequest request, - @RequestParam String steam64) { - return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); + @RequestParam String steam64, + @RequestParam(required = false, defaultValue = "") String requests) { + return new ResponseEntity(profileService.GetProfile(steam64, requests), HttpStatus.OK); } @GetMapping("/steam") diff --git a/src/main/java/app/entities/PlayerProfile.java b/src/main/java/app/entities/PlayerProfile.java index bdbf082..8587b36 100644 --- a/src/main/java/app/entities/PlayerProfile.java +++ b/src/main/java/app/entities/PlayerProfile.java @@ -24,4 +24,5 @@ public class PlayerProfile { PlayOn play_on; List attached_discords; List donates; + List ban_list; } diff --git a/src/main/java/app/entities/db/Ban.java b/src/main/java/app/entities/db/Ban.java index cd004ea..146a092 100644 --- a/src/main/java/app/entities/db/Ban.java +++ b/src/main/java/app/entities/db/Ban.java @@ -1,5 +1,6 @@ package app.entities.db; +import app.utils.CryptedCookie; import lombok.Data; import java.sql.Timestamp; @@ -39,4 +40,10 @@ public class Ban { ban_length_seconds = ban_length * 60L; ban_utime = timestamp.getTime() / 1000; } + + public void cryptIP(CryptedCookie cryptedCookie) { + if (ip != null && !ip.isEmpty()) { + ip = cryptedCookie.Hashed(ip); + } + } } diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 0aab1d4..132eda7 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -121,14 +121,22 @@ public class ProfileService { profile.getResponse_time().put("donates", Double.valueOf(end_time) / 1000); } + if(requests.contains("ban_list")){ + start_time = Instant.now().toEpochMilli(); + profile.setBan_list(banService.getBans(steamID)); + end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("ban_list", Double.valueOf(end_time) / 1000); + } + return profile; } public PlayerProfile GetProfile(String steam64) { - return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition,ban,attached_discord,donates".split(","))); + return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition,ban,attached_discord,donates,ban_list".split(","))); } public PlayerProfile GetProfile(String steam64, String requests) { + if (requests == null || requests.isEmpty()) return GetProfile(steam64); return GetProfile(steam64, List.of(requests.split(","))); } diff --git a/src/main/java/app/services/db/BanService.java b/src/main/java/app/services/db/BanService.java index 167750a..6cc8f8f 100644 --- a/src/main/java/app/services/db/BanService.java +++ b/src/main/java/app/services/db/BanService.java @@ -5,6 +5,7 @@ import app.entities.db.Ban; import app.entities.other.SteamID; import app.services.ProfileService; import app.services.ServerService; +import app.utils.CryptedCookie; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.springframework.beans.factory.annotation.Autowired; @@ -20,39 +21,41 @@ import java.util.List; public class BanService { EntityManager entityManager; ServerService serverService; + CryptedCookie cryptedCookie; @Autowired - public BanService(ServerService serverService, @Qualifier(value = "RwEntityManager") EntityManager entityManager) { + public BanService(ServerService serverService, @Qualifier(value = "RwEntityManager") EntityManager entityManager, CryptedCookie cryptedCookie) { this.entityManager = entityManager; this.serverService = serverService; + this.cryptedCookie = cryptedCookie; } public Ban getBan(SteamID steamID) { List result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE account_id = ?1 AND active = 1") .setParameter(1, steamID.account_id) .getResultList(); - return result.stream().map(Ban::new).findFirst().orElse(null); + return result.stream().map(Ban::new).peek(ban -> ban.cryptIP(cryptedCookie)).findFirst().orElse(null); } public Ban getBan(int ban_id) { List result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE id = ?1") .setParameter(1, ban_id) .getResultList(); - return result.stream().map(Ban::new).findFirst().orElse(null); + return result.stream().map(Ban::new).peek(ban -> ban.cryptIP(cryptedCookie)).findFirst().orElse(null); } public List getBans(SteamID steamID) { List result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE account_id = ?1 AND active = 0") .setParameter(1, steamID.account_id) .getResultList(); - return result.stream().map(Ban::new).toList(); + return result.stream().map(Ban::new).peek(ban -> ban.cryptIP(cryptedCookie)).toList(); } public List getLastBans(Integer limit) { - return entityManager.createNativeQuery("SELECT * FROM `light_bans` WHERE `active` = ?1 ORDER BY `light_bans`.`id` DESC LIMIT ?2") + return ((List) entityManager.createNativeQuery("SELECT * FROM `light_bans` WHERE `active` = ?1 ORDER BY `light_bans`.`id` DESC LIMIT ?2") .setParameter(1, 1) .setParameter(2, limit) - .getResultStream().map(obj -> new Ban((Object[]) obj)).toList(); + .getResultStream().map(obj -> new Ban((Object[]) obj)).toList()).stream().peek(ban -> ban.cryptIP(cryptedCookie)).toList(); //этот каст конечно пиздец, но он работает }