diff --git a/src/main/java/app/annotations/impl/WaitAfterNextAspect.java b/src/main/java/app/annotations/impl/WaitAfterNextAspect.java index db75081..c8f8fe5 100644 --- a/src/main/java/app/annotations/impl/WaitAfterNextAspect.java +++ b/src/main/java/app/annotations/impl/WaitAfterNextAspect.java @@ -2,11 +2,13 @@ package app.annotations.impl; import app.annotations.exceptions.NeedCookie; import app.annotations.exceptions.WaitRateLimit; +import app.annotations.interfaces.WaitAfterNext; import jakarta.servlet.http.HttpServletRequest; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.reflect.MethodSignature; import org.springframework.context.annotation.Configuration; import java.util.HashSet; @@ -17,8 +19,9 @@ public class WaitAfterNextAspect { HashSet wait_steam64 = new HashSet<>(); @Before("@annotation(app.annotations.interfaces.WaitAfterNext) && args(request,..)") - public void before(HttpServletRequest request) { - String steam64 = getSteam64fromCookie(request); + public void before(JoinPoint joinPoint, HttpServletRequest request) { + final String order = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(WaitAfterNext.class).order(); + final String steam64 = getSteam64fromCookie(request) + order; if (steam64.isEmpty()) return; if (wait_steam64.contains(steam64)) throw new WaitRateLimit(); @@ -26,8 +29,9 @@ public class WaitAfterNextAspect { } @After("@annotation(app.annotations.interfaces.WaitAfterNext) && args(request,..)") - public void after(HttpServletRequest request) { - String steam64 = getSteam64fromCookie(request); + public void after(JoinPoint joinPoint, HttpServletRequest request) { + final String order = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(WaitAfterNext.class).order(); + final String steam64 = getSteam64fromCookie(request) + order; if (steam64.isEmpty()) return; if (wait_steam64.contains(steam64)) wait_steam64.remove(steam64); } diff --git a/src/main/java/app/annotations/interfaces/WaitAfterNext.java b/src/main/java/app/annotations/interfaces/WaitAfterNext.java index e57b771..f6c1e49 100644 --- a/src/main/java/app/annotations/interfaces/WaitAfterNext.java +++ b/src/main/java/app/annotations/interfaces/WaitAfterNext.java @@ -8,4 +8,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface WaitAfterNext { + public String order() default ""; } diff --git a/src/main/java/app/controllers/admin/BanController.java b/src/main/java/app/controllers/admin/BanController.java index 6ee68ff..5635b14 100644 --- a/src/main/java/app/controllers/admin/BanController.java +++ b/src/main/java/app/controllers/admin/BanController.java @@ -38,7 +38,7 @@ public class BanController { @CheckWebAccess @CheckPermitionFlag(flag = "d") @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "ban") public ResponseEntity banPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, @@ -63,7 +63,7 @@ public class BanController { @DeleteMapping @CheckWebAccess @CheckPermitionFlag(flag = "e") - @WaitAfterNext + @WaitAfterNext(order = "unban") public ResponseEntity unbanPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, diff --git a/src/main/java/app/controllers/admin/KickController.java b/src/main/java/app/controllers/admin/KickController.java index c206bd4..8cb2c99 100644 --- a/src/main/java/app/controllers/admin/KickController.java +++ b/src/main/java/app/controllers/admin/KickController.java @@ -37,7 +37,7 @@ public class KickController { @CheckWebAccess @CheckPermitionFlag(flag = "c") @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "kick") public ResponseEntity kickPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String steam64, diff --git a/src/main/java/app/controllers/admin/MuteContoller.java b/src/main/java/app/controllers/admin/MuteContoller.java index 12e2941..792ce75 100644 --- a/src/main/java/app/controllers/admin/MuteContoller.java +++ b/src/main/java/app/controllers/admin/MuteContoller.java @@ -37,7 +37,7 @@ public class MuteContoller { @CheckWebAccess @CheckPermitionFlag(flag = "c") @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "mute") public ResponseEntity mutePlayer( HttpServletRequest request, @CookieValue(value = "steam64") String steam64, @@ -55,7 +55,7 @@ public class MuteContoller { @CheckWebAccess @CheckPermitionFlag(flag = "c") @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "unmute") public ResponseEntity unmutePlayer( HttpServletRequest request, @CookieValue(value = "steam64") String steam64, diff --git a/src/main/java/app/controllers/admin/RconController.java b/src/main/java/app/controllers/admin/RconController.java index e0fbb09..68b5f80 100644 --- a/src/main/java/app/controllers/admin/RconController.java +++ b/src/main/java/app/controllers/admin/RconController.java @@ -24,7 +24,7 @@ public class RconController { @PostMapping @CheckWebAccess @CheckPermitionFlag(flag = "m") - @WaitAfterNext + @WaitAfterNext(order = "rcon") public ResponseEntity rcon(HttpServletRequest request, @RequestParam String srv, @RequestParam String command) { diff --git a/src/main/java/app/controllers/admin/VIPController.java b/src/main/java/app/controllers/admin/VIPController.java index b9f4b36..49fc8e4 100644 --- a/src/main/java/app/controllers/admin/VIPController.java +++ b/src/main/java/app/controllers/admin/VIPController.java @@ -25,7 +25,7 @@ public class VIPController { @PostMapping @CheckWebAccess @CheckPermitionFlag(flag = "z") - @WaitAfterNext + @WaitAfterNext(order = "givevip") public ResponseEntity giveVIP( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, @@ -46,7 +46,7 @@ public class VIPController { @DeleteMapping @CheckWebAccess @CheckPermitionFlag(flag = "z") - @WaitAfterNext + @WaitAfterNext(order = "removevip") public ResponseEntity removeVIP( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, diff --git a/src/main/java/app/controllers/user/DetailController.java b/src/main/java/app/controllers/user/DetailController.java index d462d4b..ef0b280 100644 --- a/src/main/java/app/controllers/user/DetailController.java +++ b/src/main/java/app/controllers/user/DetailController.java @@ -35,7 +35,7 @@ public class DetailController { @GetMapping("/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "getprofile") public ResponseEntity GetUser4Web(HttpServletRequest request, @RequestParam String steam64, @RequestParam(required = false, defaultValue = "") String requests) { @@ -51,7 +51,7 @@ public class DetailController { @GetMapping("/steam/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) - @WaitAfterNext + @WaitAfterNext(order = "search") public ResponseEntity GetSteam4Web(HttpServletRequest request, @RequestParam String any) { return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK); @@ -67,7 +67,7 @@ public class DetailController { @PostMapping("/steam/web") @CheckWebAccess(auth_method = AuthMethod.STEAM64) - @WaitAfterNext + @WaitAfterNext(order = "search") public ResponseEntity GetSteamOnHashMap4Web(HttpServletRequest request, @RequestBody HashMap container) { if (!container.containsKey("any")) return new ResponseEntity(HttpStatus.BAD_REQUEST); diff --git a/src/main/java/app/controllers/user/ProfileController.java b/src/main/java/app/controllers/user/ProfileController.java index 9724493..642e89a 100644 --- a/src/main/java/app/controllers/user/ProfileController.java +++ b/src/main/java/app/controllers/user/ProfileController.java @@ -41,7 +41,7 @@ public class ProfileController { @GetMapping @CheckWebAccess @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "currentuser") @ShowClientIP public ResponseEntity GetCurrentUser(HttpServletRequest request, @CookieValue(value = "steam64", defaultValue = "") String steam64, @@ -56,7 +56,7 @@ public class ProfileController { @PostMapping("/freevip") @CheckWebAccess - @WaitAfterNext + @WaitAfterNext(order = "freevip") public ResponseEntity GetFreeVIP(HttpServletRequest request, @CookieValue(value = "steam64", defaultValue = "") String steam64, @RequestBody(required = false) SocialAuth socialAuth, @@ -71,7 +71,7 @@ public class ProfileController { @PostMapping("/report") @CheckWebAccess @BurstUpdatePlayers - @WaitAfterNext + @WaitAfterNext(order = "report") public ResponseEntity ReportUser(HttpServletRequest request, @CookieValue(value = "steam64", defaultValue = "") String steam64, @RequestParam(value = "steam64", defaultValue = "") String reported_steam64, diff --git a/src/main/java/app/controllers/user/PublicController.java b/src/main/java/app/controllers/user/PublicController.java new file mode 100644 index 0000000..1d6a2d4 --- /dev/null +++ b/src/main/java/app/controllers/user/PublicController.java @@ -0,0 +1,36 @@ +package app.controllers.user; + +import app.annotations.enums.AuthMethod; +import app.annotations.interfaces.CheckWebAccess; +import app.annotations.interfaces.WaitAfterNext; +import app.entities.db.Ban; +import app.services.db.BanService; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("api/web") +public class PublicController { + + BanService banService; + + @Autowired + public PublicController(BanService banService) { + this.banService = banService; + } + + @GetMapping("/banlist") + @CheckWebAccess(auth_method = AuthMethod.STEAM64) + @WaitAfterNext(order = "banlist") + public ResponseEntity> getDiscordIDsBanList( + HttpServletRequest request) { + return new ResponseEntity<>(banService.getLastBans(20), HttpStatus.OK); + } +} diff --git a/src/main/java/app/entities/db/Ban.java b/src/main/java/app/entities/db/Ban.java index 146a092..89c1f38 100644 --- a/src/main/java/app/entities/db/Ban.java +++ b/src/main/java/app/entities/db/Ban.java @@ -1,6 +1,9 @@ package app.entities.db; +import app.entities.other.SteamID; import app.utils.CryptedCookie; +import app.utils.SteamIDConverter; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.sql.Timestamp; @@ -46,4 +49,9 @@ public class Ban { ip = cryptedCookie.Hashed(ip); } } + + @JsonIgnore + public SteamID getModeration() { + return SteamIDConverter.getSteamID(banned_by_id); + } } diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 132eda7..6c391c7 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -98,11 +98,11 @@ public class ProfileService { //if(requests.contains("ban")){ start_time = Instant.now().toEpochMilli(); profile.setBan(banService.getBan(steamID)); - if(profile.getBan() != null) { + /*if(profile.getBan() != null) { profile.getBan().setAdmin_info( permitionService.getAdminInfo(SteamIDConverter.getSteamID(profile.getBan().getBanned_by_id())) ); - } + }*/ end_time = Instant.now().toEpochMilli() - start_time; profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000); //} diff --git a/src/main/java/app/services/db/BanService.java b/src/main/java/app/services/db/BanService.java index 2f0e14d..0d8e028 100644 --- a/src/main/java/app/services/db/BanService.java +++ b/src/main/java/app/services/db/BanService.java @@ -22,40 +22,56 @@ public class BanService { EntityManager entityManager; ServerService serverService; CryptedCookie cryptedCookie; + PermitionService permitionService; @Autowired - public BanService(ServerService serverService, @Qualifier(value = "RwEntityManager") EntityManager entityManager, CryptedCookie cryptedCookie) { + public BanService(ServerService serverService, @Qualifier(value = "RwEntityManager") EntityManager entityManager, CryptedCookie cryptedCookie, PermitionService permitionService) { this.entityManager = entityManager; this.serverService = serverService; this.cryptedCookie = cryptedCookie; + this.permitionService = permitionService; } 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).peek(ban -> ban.cryptIP(cryptedCookie)).findFirst().orElse(null); + return result.stream().map(Ban::new) + .peek(ban -> ban.cryptIP(cryptedCookie)) + .peek(ban -> ban.setAdmin_info(permitionService.getAdminInfo(ban.getModeration()))) + .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).peek(ban -> ban.cryptIP(cryptedCookie)).findFirst().orElse(null); + return result.stream().map(Ban::new) + .peek(ban -> ban.cryptIP(cryptedCookie)) + .peek(ban -> ban.setAdmin_info(permitionService.getAdminInfo(ban.getModeration()))) + .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).peek(ban -> ban.cryptIP(cryptedCookie)).toList(); + return result.stream().map(Ban::new) + .peek(ban -> ban.cryptIP(cryptedCookie)) + .peek(ban -> ban.setAdmin_info(permitionService.getAdminInfo(ban.getModeration()))) + .toList(); } public List getLastBans(Integer limit) { 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()).stream().peek(ban -> ban.cryptIP(cryptedCookie)).toList(); + .getResultStream().map(obj -> new Ban((Object[]) obj)).toList()).stream() + .peek(ban -> ban.cryptIP(cryptedCookie)) + .peek(ban -> ban.setAdmin_info(permitionService.getAdminInfo(ban.getModeration()))) + .toList(); //этот каст конечно пиздец, но он работает }