You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
4.1 KiB
94 lines
4.1 KiB
package app.controllers.admin;
|
|
|
|
import app.annotations.enums.AuthMethod;
|
|
import app.annotations.enums.CollectStages;
|
|
import app.annotations.interfaces.*;
|
|
import app.entities.db.Ban;
|
|
import app.services.ProfileService;
|
|
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;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* удивительно, контроллер который используется для ботов и прочий хуйни чтоб банить игроков
|
|
*/
|
|
@RestController
|
|
@RequestMapping("api/admin/ban")
|
|
public class BanController {
|
|
ProfileService profileService;
|
|
BanService banService;
|
|
PermitionService permitionService;
|
|
|
|
@Autowired
|
|
public BanController(ProfileService profileService,
|
|
BanService banService,
|
|
PermitionService permitionService) {
|
|
this.profileService = profileService;
|
|
this.banService = banService;
|
|
this.permitionService = permitionService;
|
|
}
|
|
|
|
@PostMapping
|
|
@CheckWebAccess
|
|
@CheckPermitionFlag(flag = "d")
|
|
@BurstUpdatePlayers
|
|
@WaitAfterNext(order = "ban")
|
|
@CollectStatistic(stage = CollectStages.COMBINED)
|
|
public ResponseEntity banPlayer(
|
|
HttpServletRequest request,
|
|
@CookieValue(value = "steam64") String admin_steam64,
|
|
@RequestParam(value = "steam64") String user_steam64,
|
|
@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.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 > 0 ? new ResponseEntity(result, HttpStatus.CREATED) : new ResponseEntity(result * -1, HttpStatus.ACCEPTED);
|
|
}
|
|
|
|
@RequestMapping(method = RequestMethod.OPTIONS)
|
|
@CheckPermitionFlag(flag = "d")
|
|
public ResponseEntity checkBanPlayer(HttpServletRequest request) {
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping
|
|
@CheckWebAccess
|
|
@CheckPermitionFlag(flag = "e")
|
|
@WaitAfterNext(order = "unban")
|
|
@CollectStatistic(stage = CollectStages.COMBINED)
|
|
public ResponseEntity unbanPlayer(
|
|
HttpServletRequest request,
|
|
@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()));
|
|
return result ? new ResponseEntity(result, HttpStatus.OK) : new ResponseEntity(result, HttpStatus.NOT_FOUND);
|
|
}
|
|
|
|
@GetMapping("/list")
|
|
@CheckWebAccess(auth_method = AuthMethod.SECRET_KEY)
|
|
public ResponseEntity banList(
|
|
HttpServletRequest request,
|
|
@RequestParam(required = false, defaultValue = "10") Integer limit,
|
|
@RequestParam(required = false, defaultValue = "0") Integer offset
|
|
){
|
|
return new ResponseEntity(banService.getLastBans(limit, offset), HttpStatus.OK);
|
|
}
|
|
}
|
|
|