Browse Source

ахуй

master
gsd 2 years ago
parent
commit
317b5ccf1d
  1. 16
      src/main/java/app/controllers/AdminController.java
  2. 5
      src/main/java/app/entities/server/Server.java
  3. 14
      src/main/java/app/services/ProfileService.java
  4. 2
      src/main/java/app/services/ServerService.java
  5. 7
      src/main/java/app/services/StatsService.java

16
src/main/java/app/controllers/AdminController.java

@ -38,11 +38,23 @@ public class AdminController {
public ResponseEntity kickPlayer( public ResponseEntity kickPlayer(
@CookieValue(value = "steam64", defaultValue = "") String steam64, @CookieValue(value = "steam64", defaultValue = "") String steam64,
@CookieValue(value = "steam64_secured", defaultValue = "") String steam64_secured, @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(!saltedCookie.Validate(steam64, steam64_secured)) return new ResponseEntity<>(HttpStatus.FORBIDDEN);
if(!ValidateAdmin(steam64, "z")) 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); return new ResponseEntity(HttpStatus.OK);
} else { } else {
return new ResponseEntity(HttpStatus.NOT_FOUND); return new ResponseEntity(HttpStatus.NOT_FOUND);

5
src/main/java/app/entities/server/Server.java

@ -116,4 +116,9 @@ public class Server {
public RCONPlayer searchPlayer(SteamID steamID){ public RCONPlayer searchPlayer(SteamID steamID){
return (RCONPlayer) players.stream().filter(player -> player.getSteam().is(steamID)).findFirst().orElse(null); 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);
}
} }

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

@ -31,6 +31,14 @@ public class ProfileService {
this.statsService = statsService; this.statsService = statsService;
} }
public PlayerProfile GetProfile(SteamID steamID, List<String> requests) {
return GetProfile(steamID.steam64, requests);
}
public PlayerProfile GetProfile(Long steam64, List<String> requests){
return GetProfile(steam64.toString(), requests);
}
public PlayerProfile GetProfile(String steam64, List<String> requests) { public PlayerProfile GetProfile(String steam64, List<String> requests) {
PlayerProfile profile = new PlayerProfile(); PlayerProfile profile = new PlayerProfile();
profile.setResponse_time(new HashMap<>()); profile.setResponse_time(new HashMap<>());
@ -79,4 +87,10 @@ public class ProfileService {
public PlayerProfile GetProfile(String steam64) { public PlayerProfile GetProfile(String steam64) {
return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition".split(","))); return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition".split(",")));
} }
public PlayerProfile GetProfileOnPlayerOnServers(String name, List<String> requests) {
SteamID steamID = statsService.searchPlayer(name);
if (steamID == null) return null;
return GetProfile(steamID, requests);
}
} }

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

@ -20,7 +20,7 @@ public class ServerService {
} }
public boolean kickPlayer(PlayerProfile playerProfile){ 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()) 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"); .ExecuteRCON(applicationContext, "sm_kick #%d kicked from backend".formatted(playerProfile.getPlay_on().getPlayer_id())).contains("kicked");
} }

7
src/main/java/app/services/StatsService.java

@ -27,4 +27,11 @@ public class StatsService {
return null; return null;
} }
public SteamID searchPlayer(String player_nickname){
for (Map.Entry<String, Server> stringServerEntry : stats.getServers().entrySet()) {
SteamID steamID = stringServerEntry.getValue().searchPlayer(player_nickname);
if(steamID != null) return steamID;
}
return null;
}
} }

Loading…
Cancel
Save