diff --git a/src/main/java/app/controllers/AdminController.java b/src/main/java/app/controllers/AdminController.java index 73bb72b..bc48d65 100644 --- a/src/main/java/app/controllers/AdminController.java +++ b/src/main/java/app/controllers/AdminController.java @@ -38,11 +38,23 @@ public class AdminController { public ResponseEntity kickPlayer( @CookieValue(value = "steam64", defaultValue = "") String steam64, @CookieValue(value = "steam64_secured", defaultValue = "") String steam64_secured, - @RequestParam(value = "steam64", required = true) String kicked_steam64 + @RequestParam(value = "steam64", required = false, defaultValue = "") String kicked_steam64, + @RequestParam(value = "player_name", required = false, defaultValue = "") String player_name ) { if(!saltedCookie.Validate(steam64, steam64_secured)) return new ResponseEntity<>(HttpStatus.FORBIDDEN); if(!ValidateAdmin(steam64, "z")) return new ResponseEntity<>(HttpStatus.FORBIDDEN); - if(serverService.kickPlayer(profileService.GetProfile(kicked_steam64,List.of()))){ + if(kicked_steam64.isEmpty() && player_name.isEmpty()) return new ResponseEntity<>(HttpStatus.NO_CONTENT); + + boolean result = false; + if(!kicked_steam64.isEmpty()) { + result = serverService.kickPlayer( + profileService.GetProfile(kicked_steam64, List.of())); + } else if (!player_name.isEmpty()) { + result = serverService.kickPlayer( + profileService.GetProfileOnPlayerOnServers(player_name, List.of())); + } + + if(result){ return new ResponseEntity(HttpStatus.OK); } else { return new ResponseEntity(HttpStatus.NOT_FOUND); diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java index b8cf141..ad0ef1b 100644 --- a/src/main/java/app/entities/server/Server.java +++ b/src/main/java/app/entities/server/Server.java @@ -116,4 +116,9 @@ public class Server { public RCONPlayer searchPlayer(SteamID steamID){ return (RCONPlayer) players.stream().filter(player -> player.getSteam().is(steamID)).findFirst().orElse(null); } + + @JsonIgnore + public SteamID searchPlayer(String player_nickname){ + return players.stream().filter(player -> player.getName().equals(player_nickname)).map(player -> player.getSteam()).findFirst().orElse(null); + } } diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 218c285..c10879c 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -31,6 +31,14 @@ public class ProfileService { this.statsService = statsService; } + public PlayerProfile GetProfile(SteamID steamID, List requests) { + return GetProfile(steamID.steam64, requests); + } + + public PlayerProfile GetProfile(Long steam64, List requests){ + return GetProfile(steam64.toString(), requests); + } + public PlayerProfile GetProfile(String steam64, List requests) { PlayerProfile profile = new PlayerProfile(); profile.setResponse_time(new HashMap<>()); @@ -79,4 +87,10 @@ public class ProfileService { public PlayerProfile GetProfile(String steam64) { return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition".split(","))); } + + public PlayerProfile GetProfileOnPlayerOnServers(String name, List requests) { + SteamID steamID = statsService.searchPlayer(name); + if (steamID == null) return null; + return GetProfile(steamID, requests); + } } diff --git a/src/main/java/app/services/ServerService.java b/src/main/java/app/services/ServerService.java index 071a5ae..0221318 100644 --- a/src/main/java/app/services/ServerService.java +++ b/src/main/java/app/services/ServerService.java @@ -20,7 +20,7 @@ public class ServerService { } public boolean kickPlayer(PlayerProfile playerProfile){ - if (playerProfile.getPlay_on() == null) return false; + if (playerProfile == null || playerProfile.getPlay_on() == null) return false; return stats.getServers().get(playerProfile.getPlay_on().getServer_id()) .ExecuteRCON(applicationContext, "sm_kick #%d kicked from backend".formatted(playerProfile.getPlay_on().getPlayer_id())).contains("kicked"); } diff --git a/src/main/java/app/services/StatsService.java b/src/main/java/app/services/StatsService.java index d1bd299..55563fa 100644 --- a/src/main/java/app/services/StatsService.java +++ b/src/main/java/app/services/StatsService.java @@ -27,4 +27,11 @@ public class StatsService { return null; } + public SteamID searchPlayer(String player_nickname){ + for (Map.Entry stringServerEntry : stats.getServers().entrySet()) { + SteamID steamID = stringServerEntry.getValue().searchPlayer(player_nickname); + if(steamID != null) return steamID; + } + return null; + } }