package app.controllers.admin; import app.annotations.interfaces.BurstUpdatePlayers; 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.PermitionService; import app.utils.SteamIDConverter; 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.*; import java.util.List; @RestController @RequestMapping("api/admin/kick") public class KickController { ServerService serverService; ProfileService profileService; PermitionService permitionService; @Autowired public KickController(ServerService serverService, ProfileService profileService, PermitionService permitionService) { this.serverService = serverService; this.profileService = profileService; this.permitionService = permitionService; } @PostMapping @CheckWebAccess @CheckPermitionFlag(flag = "c") @BurstUpdatePlayers public ResponseEntity kickPlayer( 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 = "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()) { profile = profileService.GetProfile(kicked_steam64, List.of()); } else if (!player_name.isEmpty()) { 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 { return new ResponseEntity(HttpStatus.NOT_FOUND); } } }