Browse Source

banlist

master
gsd 1 year ago
parent
commit
05436fac43
  1. 12
      src/main/java/app/annotations/impl/WaitAfterNextAspect.java
  2. 1
      src/main/java/app/annotations/interfaces/WaitAfterNext.java
  3. 4
      src/main/java/app/controllers/admin/BanController.java
  4. 2
      src/main/java/app/controllers/admin/KickController.java
  5. 4
      src/main/java/app/controllers/admin/MuteContoller.java
  6. 2
      src/main/java/app/controllers/admin/RconController.java
  7. 4
      src/main/java/app/controllers/admin/VIPController.java
  8. 6
      src/main/java/app/controllers/user/DetailController.java
  9. 6
      src/main/java/app/controllers/user/ProfileController.java
  10. 36
      src/main/java/app/controllers/user/PublicController.java
  11. 8
      src/main/java/app/entities/db/Ban.java
  12. 4
      src/main/java/app/services/ProfileService.java
  13. 26
      src/main/java/app/services/db/BanService.java

12
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.NeedCookie;
import app.annotations.exceptions.WaitRateLimit; import app.annotations.exceptions.WaitRateLimit;
import app.annotations.interfaces.WaitAfterNext;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.HashSet; import java.util.HashSet;
@ -17,8 +19,9 @@ public class WaitAfterNextAspect {
HashSet<String> wait_steam64 = new HashSet<>(); HashSet<String> wait_steam64 = new HashSet<>();
@Before("@annotation(app.annotations.interfaces.WaitAfterNext) && args(request,..)") @Before("@annotation(app.annotations.interfaces.WaitAfterNext) && args(request,..)")
public void before(HttpServletRequest request) { public void before(JoinPoint joinPoint, HttpServletRequest request) {
String steam64 = getSteam64fromCookie(request); final String order = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(WaitAfterNext.class).order();
final String steam64 = getSteam64fromCookie(request) + order;
if (steam64.isEmpty()) return; if (steam64.isEmpty()) return;
if (wait_steam64.contains(steam64)) throw new WaitRateLimit(); if (wait_steam64.contains(steam64)) throw new WaitRateLimit();
@ -26,8 +29,9 @@ public class WaitAfterNextAspect {
} }
@After("@annotation(app.annotations.interfaces.WaitAfterNext) && args(request,..)") @After("@annotation(app.annotations.interfaces.WaitAfterNext) && args(request,..)")
public void after(HttpServletRequest request) { public void after(JoinPoint joinPoint, HttpServletRequest request) {
String steam64 = getSteam64fromCookie(request); final String order = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(WaitAfterNext.class).order();
final String steam64 = getSteam64fromCookie(request) + order;
if (steam64.isEmpty()) return; if (steam64.isEmpty()) return;
if (wait_steam64.contains(steam64)) wait_steam64.remove(steam64); if (wait_steam64.contains(steam64)) wait_steam64.remove(steam64);
} }

1
src/main/java/app/annotations/interfaces/WaitAfterNext.java

@ -8,4 +8,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
public @interface WaitAfterNext { public @interface WaitAfterNext {
public String order() default "";
} }

4
src/main/java/app/controllers/admin/BanController.java

@ -38,7 +38,7 @@ public class BanController {
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "d") @CheckPermitionFlag(flag = "d")
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "ban")
public ResponseEntity banPlayer( public ResponseEntity banPlayer(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String admin_steam64, @CookieValue(value = "steam64") String admin_steam64,
@ -63,7 +63,7 @@ public class BanController {
@DeleteMapping @DeleteMapping
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "e") @CheckPermitionFlag(flag = "e")
@WaitAfterNext @WaitAfterNext(order = "unban")
public ResponseEntity unbanPlayer( public ResponseEntity unbanPlayer(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String admin_steam64, @CookieValue(value = "steam64") String admin_steam64,

2
src/main/java/app/controllers/admin/KickController.java

@ -37,7 +37,7 @@ public class KickController {
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "c") @CheckPermitionFlag(flag = "c")
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "kick")
public ResponseEntity kickPlayer( public ResponseEntity kickPlayer(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String steam64, @CookieValue(value = "steam64") String steam64,

4
src/main/java/app/controllers/admin/MuteContoller.java

@ -37,7 +37,7 @@ public class MuteContoller {
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "c") @CheckPermitionFlag(flag = "c")
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "mute")
public ResponseEntity mutePlayer( public ResponseEntity mutePlayer(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String steam64, @CookieValue(value = "steam64") String steam64,
@ -55,7 +55,7 @@ public class MuteContoller {
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "c") @CheckPermitionFlag(flag = "c")
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "unmute")
public ResponseEntity unmutePlayer( public ResponseEntity unmutePlayer(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String steam64, @CookieValue(value = "steam64") String steam64,

2
src/main/java/app/controllers/admin/RconController.java

@ -24,7 +24,7 @@ public class RconController {
@PostMapping @PostMapping
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "m") @CheckPermitionFlag(flag = "m")
@WaitAfterNext @WaitAfterNext(order = "rcon")
public ResponseEntity<String> rcon(HttpServletRequest request, public ResponseEntity<String> rcon(HttpServletRequest request,
@RequestParam String srv, @RequestParam String srv,
@RequestParam String command) { @RequestParam String command) {

4
src/main/java/app/controllers/admin/VIPController.java

@ -25,7 +25,7 @@ public class VIPController {
@PostMapping @PostMapping
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "z") @CheckPermitionFlag(flag = "z")
@WaitAfterNext @WaitAfterNext(order = "givevip")
public ResponseEntity giveVIP( public ResponseEntity giveVIP(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String admin_steam64, @CookieValue(value = "steam64") String admin_steam64,
@ -46,7 +46,7 @@ public class VIPController {
@DeleteMapping @DeleteMapping
@CheckWebAccess @CheckWebAccess
@CheckPermitionFlag(flag = "z") @CheckPermitionFlag(flag = "z")
@WaitAfterNext @WaitAfterNext(order = "removevip")
public ResponseEntity removeVIP( public ResponseEntity removeVIP(
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String admin_steam64, @CookieValue(value = "steam64") String admin_steam64,

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

@ -35,7 +35,7 @@ public class DetailController {
@GetMapping("/web") @GetMapping("/web")
@CheckWebAccess(auth_method = AuthMethod.STEAM64) @CheckWebAccess(auth_method = AuthMethod.STEAM64)
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "getprofile")
public ResponseEntity GetUser4Web(HttpServletRequest request, public ResponseEntity GetUser4Web(HttpServletRequest request,
@RequestParam String steam64, @RequestParam String steam64,
@RequestParam(required = false, defaultValue = "") String requests) { @RequestParam(required = false, defaultValue = "") String requests) {
@ -51,7 +51,7 @@ public class DetailController {
@GetMapping("/steam/web") @GetMapping("/steam/web")
@CheckWebAccess(auth_method = AuthMethod.STEAM64) @CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext @WaitAfterNext(order = "search")
public ResponseEntity<SteamID> GetSteam4Web(HttpServletRequest request, public ResponseEntity<SteamID> GetSteam4Web(HttpServletRequest request,
@RequestParam String any) { @RequestParam String any) {
return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK); return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK);
@ -67,7 +67,7 @@ public class DetailController {
@PostMapping("/steam/web") @PostMapping("/steam/web")
@CheckWebAccess(auth_method = AuthMethod.STEAM64) @CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext @WaitAfterNext(order = "search")
public ResponseEntity<SteamID> GetSteamOnHashMap4Web(HttpServletRequest request, public ResponseEntity<SteamID> GetSteamOnHashMap4Web(HttpServletRequest request,
@RequestBody HashMap<String, String> container) { @RequestBody HashMap<String, String> container) {
if (!container.containsKey("any")) return new ResponseEntity(HttpStatus.BAD_REQUEST); if (!container.containsKey("any")) return new ResponseEntity(HttpStatus.BAD_REQUEST);

6
src/main/java/app/controllers/user/ProfileController.java

@ -41,7 +41,7 @@ public class ProfileController {
@GetMapping @GetMapping
@CheckWebAccess @CheckWebAccess
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "currentuser")
@ShowClientIP @ShowClientIP
public ResponseEntity GetCurrentUser(HttpServletRequest request, public ResponseEntity GetCurrentUser(HttpServletRequest request,
@CookieValue(value = "steam64", defaultValue = "") String steam64, @CookieValue(value = "steam64", defaultValue = "") String steam64,
@ -56,7 +56,7 @@ public class ProfileController {
@PostMapping("/freevip") @PostMapping("/freevip")
@CheckWebAccess @CheckWebAccess
@WaitAfterNext @WaitAfterNext(order = "freevip")
public ResponseEntity GetFreeVIP(HttpServletRequest request, public ResponseEntity GetFreeVIP(HttpServletRequest request,
@CookieValue(value = "steam64", defaultValue = "") String steam64, @CookieValue(value = "steam64", defaultValue = "") String steam64,
@RequestBody(required = false) SocialAuth socialAuth, @RequestBody(required = false) SocialAuth socialAuth,
@ -71,7 +71,7 @@ public class ProfileController {
@PostMapping("/report") @PostMapping("/report")
@CheckWebAccess @CheckWebAccess
@BurstUpdatePlayers @BurstUpdatePlayers
@WaitAfterNext @WaitAfterNext(order = "report")
public ResponseEntity<Long> ReportUser(HttpServletRequest request, public ResponseEntity<Long> ReportUser(HttpServletRequest request,
@CookieValue(value = "steam64", defaultValue = "") String steam64, @CookieValue(value = "steam64", defaultValue = "") String steam64,
@RequestParam(value = "steam64", defaultValue = "") String reported_steam64, @RequestParam(value = "steam64", defaultValue = "") String reported_steam64,

36
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<List<Ban>> getDiscordIDsBanList(
HttpServletRequest request) {
return new ResponseEntity<>(banService.getLastBans(20), HttpStatus.OK);
}
}

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

@ -1,6 +1,9 @@
package app.entities.db; package app.entities.db;
import app.entities.other.SteamID;
import app.utils.CryptedCookie; import app.utils.CryptedCookie;
import app.utils.SteamIDConverter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -46,4 +49,9 @@ public class Ban {
ip = cryptedCookie.Hashed(ip); ip = cryptedCookie.Hashed(ip);
} }
} }
@JsonIgnore
public SteamID getModeration() {
return SteamIDConverter.getSteamID(banned_by_id);
}
} }

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

@ -98,11 +98,11 @@ public class ProfileService {
//if(requests.contains("ban")){ //if(requests.contains("ban")){
start_time = Instant.now().toEpochMilli(); start_time = Instant.now().toEpochMilli();
profile.setBan(banService.getBan(steamID)); profile.setBan(banService.getBan(steamID));
if(profile.getBan() != null) { /*if(profile.getBan() != null) {
profile.getBan().setAdmin_info( profile.getBan().setAdmin_info(
permitionService.getAdminInfo(SteamIDConverter.getSteamID(profile.getBan().getBanned_by_id())) permitionService.getAdminInfo(SteamIDConverter.getSteamID(profile.getBan().getBanned_by_id()))
); );
} }*/
end_time = Instant.now().toEpochMilli() - start_time; end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000); profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000);
//} //}

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

@ -22,40 +22,56 @@ public class BanService {
EntityManager entityManager; EntityManager entityManager;
ServerService serverService; ServerService serverService;
CryptedCookie cryptedCookie; CryptedCookie cryptedCookie;
PermitionService permitionService;
@Autowired @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.entityManager = entityManager;
this.serverService = serverService; this.serverService = serverService;
this.cryptedCookie = cryptedCookie; this.cryptedCookie = cryptedCookie;
this.permitionService = permitionService;
} }
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).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) { 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).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<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).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<Ban> getLastBans(Integer limit) { public List<Ban> getLastBans(Integer limit) {
return ((List<Ban>) 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()).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();
//этот каст конечно пиздец, но он работает //этот каст конечно пиздец, но он работает
} }

Loading…
Cancel
Save