Browse Source

ban list and partical load

master
gsd 1 year ago
parent
commit
3741b87bf5
  1. 5
      src/main/java/app/controllers/user/DetailController.java
  2. 1
      src/main/java/app/entities/PlayerProfile.java
  3. 7
      src/main/java/app/entities/db/Ban.java
  4. 10
      src/main/java/app/services/ProfileService.java
  5. 15
      src/main/java/app/services/db/BanService.java

5
src/main/java/app/controllers/user/DetailController.java

@ -37,8 +37,9 @@ public class DetailController {
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext
public ResponseEntity GetUser4Web(HttpServletRequest request, public ResponseEntity GetUser4Web(HttpServletRequest request,
@RequestParam String steam64) { @RequestParam String steam64,
return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); @RequestParam(required = false, defaultValue = "") String requests) {
return new ResponseEntity(profileService.GetProfile(steam64, requests), HttpStatus.OK);
} }
@GetMapping("/steam") @GetMapping("/steam")

1
src/main/java/app/entities/PlayerProfile.java

@ -24,4 +24,5 @@ public class PlayerProfile {
PlayOn play_on; PlayOn play_on;
List attached_discords; List attached_discords;
List<DonateStat> donates; List<DonateStat> donates;
List<Ban> ban_list;
} }

7
src/main/java/app/entities/db/Ban.java

@ -1,5 +1,6 @@
package app.entities.db; package app.entities.db;
import app.utils.CryptedCookie;
import lombok.Data; import lombok.Data;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -39,4 +40,10 @@ public class Ban {
ban_length_seconds = ban_length * 60L; ban_length_seconds = ban_length * 60L;
ban_utime = timestamp.getTime() / 1000; ban_utime = timestamp.getTime() / 1000;
} }
public void cryptIP(CryptedCookie cryptedCookie) {
if (ip != null && !ip.isEmpty()) {
ip = cryptedCookie.Hashed(ip);
}
}
} }

10
src/main/java/app/services/ProfileService.java

@ -121,14 +121,22 @@ public class ProfileService {
profile.getResponse_time().put("donates", Double.valueOf(end_time) / 1000); 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; return profile;
} }
public PlayerProfile GetProfile(String steam64) { 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) { public PlayerProfile GetProfile(String steam64, String requests) {
if (requests == null || requests.isEmpty()) return GetProfile(steam64);
return GetProfile(steam64, List.of(requests.split(","))); return GetProfile(steam64, List.of(requests.split(",")));
} }

15
src/main/java/app/services/db/BanService.java

@ -5,6 +5,7 @@ import app.entities.db.Ban;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.services.ProfileService; import app.services.ProfileService;
import app.services.ServerService; import app.services.ServerService;
import app.utils.CryptedCookie;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -20,39 +21,41 @@ import java.util.List;
public class BanService { public class BanService {
EntityManager entityManager; EntityManager entityManager;
ServerService serverService; ServerService serverService;
CryptedCookie cryptedCookie;
@Autowired @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.entityManager = entityManager;
this.serverService = serverService; this.serverService = serverService;
this.cryptedCookie = cryptedCookie;
} }
public Ban getBan(SteamID steamID) { public Ban getBan(SteamID steamID) {
List<Object[]> result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE account_id = ?1 AND active = 1") List<Object[]> result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE account_id = ?1 AND active = 1")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
.getResultList(); .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) { public Ban getBan(int ban_id) {
List<Object[]> result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE id = ?1") List<Object[]> result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE id = ?1")
.setParameter(1, ban_id) .setParameter(1, ban_id)
.getResultList(); .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<Ban> getBans(SteamID steamID) { public List<Ban> getBans(SteamID steamID) {
List<Object[]> result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE account_id = ?1 AND active = 0") List<Object[]> result = entityManager.createNativeQuery("SELECT * FROM light_bans WHERE account_id = ?1 AND active = 0")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
.getResultList(); .getResultList();
return result.stream().map(Ban::new).toList(); return result.stream().map(Ban::new).peek(ban -> ban.cryptIP(cryptedCookie)).toList();
} }
public List<Ban> getLastBans(Integer limit) { public List<Ban> getLastBans(Integer limit) {
return entityManager.createNativeQuery("SELECT * FROM `light_bans` WHERE `active` = ?1 ORDER BY `light_bans`.`id` DESC LIMIT ?2") return ((List<Ban>) entityManager.createNativeQuery("SELECT * FROM `light_bans` WHERE `active` = ?1 ORDER BY `light_bans`.`id` DESC LIMIT ?2")
.setParameter(1, 1) .setParameter(1, 1)
.setParameter(2, limit) .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();
//этот каст конечно пиздец, но он работает //этот каст конечно пиздец, но он работает
} }

Loading…
Cancel
Save