Browse Source

Удалены лишние импорты

Добавлен в бан и кик контролеры нормальные  коды ответа
Теперь можно разбанивать
Если банить возращается бан ид
master
gsd 2 years ago
parent
commit
dad391acbb
  1. 2
      src/main/java/app/annotations/impl/PermitionFlagAspect.java
  2. 1
      src/main/java/app/controllers/AuthController.java
  3. 11
      src/main/java/app/controllers/admin/BanController.java
  4. 24
      src/main/java/app/controllers/admin/KickController.java
  5. 1
      src/main/java/app/controllers/user/DetailController.java
  6. 2
      src/main/java/app/entities/SocialAuth.java
  7. 26
      src/main/java/app/entities/Stats.java
  8. 3
      src/main/java/app/entities/a2s/external/ExternalValveClient.java
  9. 1
      src/main/java/app/entities/a2s/requests/A2SRequest.java
  10. 4
      src/main/java/app/entities/db/Ban.java
  11. 4
      src/main/java/app/entities/server/Server.java
  12. 1
      src/main/java/app/entities/server/players/DefaultPlayer.java
  13. 3
      src/main/java/app/entities/server/players/RCONPlayer.java
  14. 1
      src/main/java/app/entities/server/players/SourcePlayer.java
  15. 6
      src/main/java/app/services/ProfileService.java
  16. 4
      src/main/java/app/services/ServerService.java
  17. 19
      src/main/java/app/services/db/BanService.java
  18. 4
      src/main/java/app/updates/BaseUpdater.java

2
src/main/java/app/annotations/impl/PermitionFlagAspect.java

@ -8,8 +8,6 @@ import app.entities.db.Permition;
import app.services.ProfileService; import app.services.ProfileService;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint; 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.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;

1
src/main/java/app/controllers/AuthController.java

@ -5,7 +5,6 @@ import app.utils.SaltedCookie;
import jakarta.servlet.http.Cookie; import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;

11
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.CheckPermitionFlag;
import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CheckWebAccess;
import app.entities.db.Ban;
import app.services.ProfileService; import app.services.ProfileService;
import app.services.db.BanService; import app.services.db.BanService;
import app.services.db.PermitionService; 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_length", required = false, defaultValue = "0") int ban_length,
@RequestParam(value = "ban_reason", required = false, defaultValue = "фурриёб") String ban_reason @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); if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(admin_steam64), SteamIDConverter.getSteamID(user_steam64))) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
boolean result = banService.addBan( int result = banService.addBan(
profileService.GetProfile(user_steam64, List.of("steam_data")), profileService.GetProfile(user_steam64, List.of("steam_data")),
profileService.GetProfile(admin_steam64, List.of("steam_data")), profileService.GetProfile(admin_steam64, List.of("steam_data")),
ban_length, ban_reason); 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 @DeleteMapping
@ -56,6 +57,10 @@ public class BanController {
@CookieValue(value = "steam64") String admin_steam64, @CookieValue(value = "steam64") String admin_steam64,
@RequestParam(value = "steam64") String user_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( boolean result = banService.removeBan(
profileService.GetProfile(user_steam64, List.of()), profileService.GetProfile(user_steam64, List.of()),
profileService.GetProfile(admin_steam64, List.of())); profileService.GetProfile(admin_steam64, List.of()));

24
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.CheckPermitionFlag;
import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CheckWebAccess;
import app.entities.PlayerProfile;
import app.services.ProfileService; import app.services.ProfileService;
import app.services.ServerService; import app.services.ServerService;
import app.services.db.BanService; import app.services.db.PermitionService;
import app.utils.SteamIDConverter;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -18,13 +20,15 @@ import java.util.List;
public class KickController { public class KickController {
ServerService serverService; ServerService serverService;
ProfileService profileService; ProfileService profileService;
BanService banService; PermitionService permitionService;
@Autowired @Autowired
public KickController(ServerService serverService, public KickController(ServerService serverService,
ProfileService profileService) { ProfileService profileService,
PermitionService permitionService) {
this.serverService = serverService; this.serverService = serverService;
this.profileService = profileService; this.profileService = profileService;
this.permitionService = permitionService;
} }
@PostMapping @PostMapping
@ -34,19 +38,23 @@ public class KickController {
HttpServletRequest request, HttpServletRequest request,
@CookieValue(value = "steam64") String steam64, @CookieValue(value = "steam64") String steam64,
@RequestParam(value = "steam64", required = false, defaultValue = "") String kicked_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); if(kicked_steam64.isEmpty() && player_name.isEmpty()) return new ResponseEntity<>(HttpStatus.NO_CONTENT);
boolean result = false; boolean result = false;
PlayerProfile profile = null;
if(!kicked_steam64.isEmpty()) { if(!kicked_steam64.isEmpty()) {
result = serverService.kickPlayer( profile = profileService.GetProfile(kicked_steam64, List.of());
profileService.GetProfile(kicked_steam64, List.of()));
} else if (!player_name.isEmpty()) { } else if (!player_name.isEmpty()) {
result = serverService.kickPlayer( profile = profileService.GetProfileOnPlayerOnServers(player_name, List.of());
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){ if(result){
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} else { } else {

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

@ -1,7 +1,6 @@
package app.controllers.user; package app.controllers.user;
import app.annotations.enums.AuthMethod; import app.annotations.enums.AuthMethod;
import app.annotations.interfaces.CheckPermitionFlag;
import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CheckWebAccess;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.services.ProfileService; import app.services.ProfileService;

2
src/main/java/app/entities/SocialAuth.java

@ -1,7 +1,5 @@
package app.entities; package app.entities;
import app.entities.other.SteamID;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
@Data @Data

26
src/main/java/app/entities/Stats.java

@ -1,39 +1,13 @@
package app.entities; package app.entities;
import app.entities.other.SteamID;
import app.entities.server.PlayOn;
import app.entities.server.Server; 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.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 lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap; 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 @Data
@Component @Component

3
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.A2SRequest;
import app.entities.a2s.requests.RCONRequest; import app.entities.a2s.requests.RCONRequest;
import app.entities.server.players.RCONPlayer; import app.entities.server.players.RCONPlayer;
import app.utils.SteamIDConverter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.*; import java.util.*;

1
src/main/java/app/entities/a2s/requests/A2SRequest.java

@ -1,7 +1,6 @@
package app.entities.a2s.requests; package app.entities.a2s.requests;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@JsonSerialize @JsonSerialize

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

@ -1,10 +1,6 @@
package app.entities.db; package app.entities.db;
import com.fasterxml.jackson.annotation.JsonGetter;
import lombok.Data; import lombok.Data;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp; import java.sql.Timestamp;
@Data @Data

4
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.external.ExternalValveClient;
import app.entities.a2s.requests.RCONRequest; import app.entities.a2s.requests.RCONRequest;
import app.entities.server.players.RCONPlayer; import app.entities.server.players.RCONPlayer;
import app.entities.server.players.SourcePlayer;
import com.fasterxml.jackson.annotation.*; 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 lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;

1
src/main/java/app/entities/server/players/DefaultPlayer.java

@ -1,6 +1,5 @@
package app.entities.server.players; package app.entities.server.players;
import app.entities.other.SteamID;
import lombok.Data; import lombok.Data;
@Data @Data

3
src/main/java/app/entities/server/players/RCONPlayer.java

@ -1,12 +1,9 @@
package app.entities.server.players; package app.entities.server.players;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.entities.server.players.DefaultPlayer;
import app.utils.SteamIDConverter; import app.utils.SteamIDConverter;
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import java.util.List; import java.util.List;

1
src/main/java/app/entities/server/players/SourcePlayer.java

@ -1,6 +1,5 @@
package app.entities.server.players; package app.entities.server.players;
import app.entities.server.players.DefaultPlayer;
import lombok.Data; import lombok.Data;
@Data @Data

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

@ -123,6 +123,12 @@ public class ProfileService {
if (result != null) return result; if (result != null) return result;
//3.Проверить что вводное это имя и проверить в БД //3.Проверить что вводное это имя и проверить в БД
result = usertimeService.getSteamOnUsername(any); 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; return result;
} }
} }

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

@ -19,9 +19,9 @@ public class ServerService {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
public boolean kickPlayer(PlayerProfile playerProfile){ public boolean kickPlayer(PlayerProfile playerProfile, String reason){
if (playerProfile == null || playerProfile.getPlay_on() == null) return false; if (playerProfile == null || playerProfile.getPlay_on() == null) return false;
return stats.getServers().get(playerProfile.getPlay_on().getServer_id()) 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");
} }
} }

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

@ -32,6 +32,13 @@ public class BanService {
return result.stream().map(Ban::new).findFirst().orElse(null); return result.stream().map(Ban::new).findFirst().orElse(null);
} }
public Ban getBan(int ban_id) {
List<Object[]> 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<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)
@ -55,10 +62,10 @@ public class BanService {
} }
@Transactional @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()); Ban ban = getBan(user.getSteamids());
if (ban != null) return true; if (ban != null) return -1 * ban.getId();
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)") 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(1, user.getSteamids().steam2)
.setParameter(2, user.getSteamids().account_id) .setParameter(2, user.getSteamids().account_id)
.setParameter(3, ban_length) .setParameter(3, ban_length)
@ -68,8 +75,8 @@ public class BanService {
.setParameter(7, user.getPlay_on() != null ? user.getPlay_on().getIp() : "") .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(8, user.getPlay_on() != null ? user.getPlay_on().getName() : user.getSteam_data().getNickname())
.setParameter(9, admin.getSteam_data().getNickname()) .setParameter(9, admin.getSteam_data().getNickname())
.executeUpdate() > 0; .executeUpdate();
serverService.kickPlayer(user); serverService.kickPlayer(user, "banned");
return result; return getBan(user.getSteamids()).getId();
} }
} }

4
src/main/java/app/updates/BaseUpdater.java

@ -1,10 +1,6 @@
package app.updates; package app.updates;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public abstract class BaseUpdater { public abstract class BaseUpdater {

Loading…
Cancel
Save