diff --git a/src/main/java/app/annotations/impl/PermitionFlagAspect.java b/src/main/java/app/annotations/impl/PermitionFlagAspect.java index e0a8e3c..fd4f893 100644 --- a/src/main/java/app/annotations/impl/PermitionFlagAspect.java +++ b/src/main/java/app/annotations/impl/PermitionFlagAspect.java @@ -8,8 +8,6 @@ import app.entities.db.Permition; import app.services.ProfileService; import jakarta.servlet.http.HttpServletRequest; import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.reflect.MethodSignature; diff --git a/src/main/java/app/controllers/AuthController.java b/src/main/java/app/controllers/AuthController.java index 76d2091..ef77dc6 100644 --- a/src/main/java/app/controllers/AuthController.java +++ b/src/main/java/app/controllers/AuthController.java @@ -5,7 +5,6 @@ import app.utils.SaltedCookie; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/app/controllers/admin/BanController.java b/src/main/java/app/controllers/admin/BanController.java index a6891d2..22165a8 100644 --- a/src/main/java/app/controllers/admin/BanController.java +++ b/src/main/java/app/controllers/admin/BanController.java @@ -2,6 +2,7 @@ package app.controllers.admin; import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.CheckWebAccess; +import app.entities.db.Ban; import app.services.ProfileService; import app.services.db.BanService; import app.services.db.PermitionService; @@ -40,12 +41,12 @@ public class BanController { @RequestParam(value = "ban_length", required = false, defaultValue = "0") int ban_length, @RequestParam(value = "ban_reason", required = false, defaultValue = "фурриёб") String ban_reason ){ - if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(admin_steam64), SteamIDConverter.getSteamID(user_steam64))) return new ResponseEntity(HttpStatus.FORBIDDEN); - boolean result = banService.addBan( + if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(admin_steam64), SteamIDConverter.getSteamID(user_steam64))) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); + int result = banService.addBan( profileService.GetProfile(user_steam64, List.of("steam_data")), profileService.GetProfile(admin_steam64, List.of("steam_data")), ban_length, ban_reason); - return result ? new ResponseEntity(result, HttpStatus.CREATED) : new ResponseEntity(result, HttpStatus.NOT_FOUND); + return result > 0 ? new ResponseEntity(result, HttpStatus.CREATED) : new ResponseEntity(result * -1, HttpStatus.ACCEPTED); } @DeleteMapping @@ -56,6 +57,10 @@ public class BanController { @CookieValue(value = "steam64") String admin_steam64, @RequestParam(value = "steam64") String user_steam64 ){ + Ban ban = banService.getBan(profileService.GetProfile(user_steam64, List.of()).getSteamids()); + if (ban == null) return new ResponseEntity(HttpStatus.NOT_FOUND); + if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(admin_steam64), SteamIDConverter.getSteamID(ban.getBanned_by_id()))) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); + boolean result = banService.removeBan( profileService.GetProfile(user_steam64, List.of()), profileService.GetProfile(admin_steam64, List.of())); diff --git a/src/main/java/app/controllers/admin/KickController.java b/src/main/java/app/controllers/admin/KickController.java index 186b3a0..db80e7c 100644 --- a/src/main/java/app/controllers/admin/KickController.java +++ b/src/main/java/app/controllers/admin/KickController.java @@ -2,9 +2,11 @@ package app.controllers.admin; import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.CheckWebAccess; +import app.entities.PlayerProfile; import app.services.ProfileService; import app.services.ServerService; -import app.services.db.BanService; +import app.services.db.PermitionService; +import app.utils.SteamIDConverter; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -18,13 +20,15 @@ import java.util.List; public class KickController { ServerService serverService; ProfileService profileService; - BanService banService; + PermitionService permitionService; @Autowired public KickController(ServerService serverService, - ProfileService profileService) { + ProfileService profileService, + PermitionService permitionService) { this.serverService = serverService; this.profileService = profileService; + this.permitionService = permitionService; } @PostMapping @@ -34,19 +38,23 @@ public class KickController { HttpServletRequest request, @CookieValue(value = "steam64") String steam64, @RequestParam(value = "steam64", required = false, defaultValue = "") String kicked_steam64, - @RequestParam(value = "player_name", required = false, defaultValue = "") String player_name + @RequestParam(value = "player_name", required = false, defaultValue = "") String player_name, + @RequestParam(value = "reason", required = false, defaultValue = "kicked from backend") String reason ) { if(kicked_steam64.isEmpty() && player_name.isEmpty()) return new ResponseEntity<>(HttpStatus.NO_CONTENT); boolean result = false; + PlayerProfile profile = null; if(!kicked_steam64.isEmpty()) { - result = serverService.kickPlayer( - profileService.GetProfile(kicked_steam64, List.of())); + profile = profileService.GetProfile(kicked_steam64, List.of()); } else if (!player_name.isEmpty()) { - result = serverService.kickPlayer( - profileService.GetProfileOnPlayerOnServers(player_name, List.of())); + profile = profileService.GetProfileOnPlayerOnServers(player_name, List.of()); } + if (profile == null) return new ResponseEntity(HttpStatus.NOT_FOUND); + if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(steam64), profile.getSteamids())) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); + result = serverService.kickPlayer(profile, reason); + if(result){ return new ResponseEntity(HttpStatus.OK); } else { diff --git a/src/main/java/app/controllers/user/DetailController.java b/src/main/java/app/controllers/user/DetailController.java index eb135a6..003c3e6 100644 --- a/src/main/java/app/controllers/user/DetailController.java +++ b/src/main/java/app/controllers/user/DetailController.java @@ -1,7 +1,6 @@ package app.controllers.user; import app.annotations.enums.AuthMethod; -import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.CheckWebAccess; import app.entities.other.SteamID; import app.services.ProfileService; diff --git a/src/main/java/app/entities/SocialAuth.java b/src/main/java/app/entities/SocialAuth.java index 261619f..789e221 100644 --- a/src/main/java/app/entities/SocialAuth.java +++ b/src/main/java/app/entities/SocialAuth.java @@ -1,7 +1,5 @@ package app.entities; -import app.entities.other.SteamID; -import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; @Data diff --git a/src/main/java/app/entities/Stats.java b/src/main/java/app/entities/Stats.java index cca6090..41216f2 100644 --- a/src/main/java/app/entities/Stats.java +++ b/src/main/java/app/entities/Stats.java @@ -1,39 +1,13 @@ package app.entities; -import app.entities.other.SteamID; -import app.entities.server.PlayOn; import app.entities.server.Server; -import app.entities.server.players.DefaultPlayer; -import app.entities.server.players.RCONPlayer; import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.ibasco.agql.core.enums.RateLimitType; -import com.ibasco.agql.core.exceptions.ReadTimeoutException; -import com.ibasco.agql.core.util.FailsafeOptions; -import com.ibasco.agql.core.util.GeneralOptions; -import com.ibasco.agql.protocols.valve.source.query.SourceQueryClient; -import com.ibasco.agql.protocols.valve.source.query.SourceQueryOptions; -import com.ibasco.agql.protocols.valve.source.query.info.SourceQueryInfoResponse; -import com.ibasco.agql.protocols.valve.source.query.players.SourceQueryPlayerResponse; -import com.ibasco.agql.protocols.valve.source.query.rcon.exceptions.RconException; import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; - -import java.io.IOException; import java.time.Instant; import java.time.LocalDate; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; @Data @Component diff --git a/src/main/java/app/entities/a2s/external/ExternalValveClient.java b/src/main/java/app/entities/a2s/external/ExternalValveClient.java index e0e1c05..79fc26a 100644 --- a/src/main/java/app/entities/a2s/external/ExternalValveClient.java +++ b/src/main/java/app/entities/a2s/external/ExternalValveClient.java @@ -3,10 +3,7 @@ package app.entities.a2s.external; import app.entities.a2s.requests.A2SRequest; import app.entities.a2s.requests.RCONRequest; import app.entities.server.players.RCONPlayer; -import app.utils.SteamIDConverter; import com.fasterxml.jackson.annotation.JsonIgnore; -import jakarta.annotation.PostConstruct; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.client.RestTemplate; import java.util.*; diff --git a/src/main/java/app/entities/a2s/requests/A2SRequest.java b/src/main/java/app/entities/a2s/requests/A2SRequest.java index c58984f..dbed307 100644 --- a/src/main/java/app/entities/a2s/requests/A2SRequest.java +++ b/src/main/java/app/entities/a2s/requests/A2SRequest.java @@ -1,7 +1,6 @@ package app.entities.a2s.requests; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import lombok.AllArgsConstructor; import lombok.Data; @JsonSerialize diff --git a/src/main/java/app/entities/db/Ban.java b/src/main/java/app/entities/db/Ban.java index 11c877d..cd004ea 100644 --- a/src/main/java/app/entities/db/Ban.java +++ b/src/main/java/app/entities/db/Ban.java @@ -1,10 +1,6 @@ package app.entities.db; -import com.fasterxml.jackson.annotation.JsonGetter; import lombok.Data; - -import java.math.BigInteger; -import java.sql.Time; import java.sql.Timestamp; @Data diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java index fb17bab..f9f7f5a 100644 --- a/src/main/java/app/entities/server/Server.java +++ b/src/main/java/app/entities/server/Server.java @@ -5,11 +5,7 @@ import app.entities.other.SteamID; import app.entities.a2s.external.ExternalValveClient; import app.entities.a2s.requests.RCONRequest; import app.entities.server.players.RCONPlayer; -import app.entities.server.players.SourcePlayer; import com.fasterxml.jackson.annotation.*; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.ibasco.agql.protocols.valve.source.query.info.SourceQueryInfoResponse; -import com.ibasco.agql.protocols.valve.source.query.players.SourceQueryPlayerResponse; import lombok.Data; import java.util.ArrayList; diff --git a/src/main/java/app/entities/server/players/DefaultPlayer.java b/src/main/java/app/entities/server/players/DefaultPlayer.java index d9222e6..9eeb225 100644 --- a/src/main/java/app/entities/server/players/DefaultPlayer.java +++ b/src/main/java/app/entities/server/players/DefaultPlayer.java @@ -1,6 +1,5 @@ package app.entities.server.players; -import app.entities.other.SteamID; import lombok.Data; @Data diff --git a/src/main/java/app/entities/server/players/RCONPlayer.java b/src/main/java/app/entities/server/players/RCONPlayer.java index 2041244..fd506cc 100644 --- a/src/main/java/app/entities/server/players/RCONPlayer.java +++ b/src/main/java/app/entities/server/players/RCONPlayer.java @@ -1,12 +1,9 @@ package app.entities.server.players; import app.entities.other.SteamID; -import app.entities.server.players.DefaultPlayer; import app.utils.SteamIDConverter; import com.fasterxml.jackson.annotation.*; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.Data; -import lombok.Getter; import java.util.List; diff --git a/src/main/java/app/entities/server/players/SourcePlayer.java b/src/main/java/app/entities/server/players/SourcePlayer.java index 731aba7..8de6123 100644 --- a/src/main/java/app/entities/server/players/SourcePlayer.java +++ b/src/main/java/app/entities/server/players/SourcePlayer.java @@ -1,6 +1,5 @@ package app.entities.server.players; -import app.entities.server.players.DefaultPlayer; import lombok.Data; @Data diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index cf4e4f4..0a94cac 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -123,6 +123,12 @@ public class ProfileService { if (result != null) return result; //3.Проверить что вводное это имя и проверить в БД result = usertimeService.getSteamOnUsername(any); + //4.Проверить возможно что это ид бана + if (any.startsWith("#")) { + String[] splitted = any.split("#", 2); + int ban_id = Integer.parseInt(splitted[1]); + result = SteamIDConverter.getSteamID(banService.getBan(ban_id).getSteam_id()); + } return result; } } diff --git a/src/main/java/app/services/ServerService.java b/src/main/java/app/services/ServerService.java index 3771bba..d68a5d4 100644 --- a/src/main/java/app/services/ServerService.java +++ b/src/main/java/app/services/ServerService.java @@ -19,9 +19,9 @@ public class ServerService { this.applicationContext = applicationContext; } - public boolean kickPlayer(PlayerProfile playerProfile){ + public boolean kickPlayer(PlayerProfile playerProfile, String reason){ if (playerProfile == null || playerProfile.getPlay_on() == null) return false; return stats.getServers().get(playerProfile.getPlay_on().getServer_id()) - .ExecuteRCON("sm_kick #%d kicked from backend".formatted(playerProfile.getPlay_on().getPlayer_id())).contains("kicked"); + .ExecuteRCON("sm_kick #%d %s".formatted(playerProfile.getPlay_on().getPlayer_id(), reason)).contains("kicked"); } } diff --git a/src/main/java/app/services/db/BanService.java b/src/main/java/app/services/db/BanService.java index 0ba1771..d387094 100644 --- a/src/main/java/app/services/db/BanService.java +++ b/src/main/java/app/services/db/BanService.java @@ -32,6 +32,13 @@ public class BanService { return result.stream().map(Ban::new).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); + } + 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) @@ -55,10 +62,10 @@ public class BanService { } @Transactional - public boolean addBan(PlayerProfile user, PlayerProfile admin, int ban_length, String ban_reason) { + public int addBan(PlayerProfile user, PlayerProfile admin, int ban_length, String ban_reason) { Ban ban = getBan(user.getSteamids()); - if (ban != null) return true; - boolean result = entityManager.createNativeQuery("INSERT INTO light_bans (steam_id, account_id, ban_length, ban_reason, banned_by_id, active, ip, player_name, banned_by) VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9)") + if (ban != null) return -1 * ban.getId(); + int result = entityManager.createNativeQuery("INSERT INTO light_bans (steam_id, account_id, ban_length, ban_reason, banned_by_id, active, ip, player_name, banned_by) VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9)") .setParameter(1, user.getSteamids().steam2) .setParameter(2, user.getSteamids().account_id) .setParameter(3, ban_length) @@ -68,8 +75,8 @@ public class BanService { .setParameter(7, user.getPlay_on() != null ? user.getPlay_on().getIp() : "") .setParameter(8, user.getPlay_on() != null ? user.getPlay_on().getName() : user.getSteam_data().getNickname()) .setParameter(9, admin.getSteam_data().getNickname()) - .executeUpdate() > 0; - serverService.kickPlayer(user); - return result; + .executeUpdate(); + serverService.kickPlayer(user, "banned"); + return getBan(user.getSteamids()).getId(); } } diff --git a/src/main/java/app/updates/BaseUpdater.java b/src/main/java/app/updates/BaseUpdater.java index 7860490..f008f95 100644 --- a/src/main/java/app/updates/BaseUpdater.java +++ b/src/main/java/app/updates/BaseUpdater.java @@ -1,10 +1,6 @@ package app.updates; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; -import java.util.function.Consumer; -import java.util.function.Function; import java.util.function.Supplier; public abstract class BaseUpdater {