diff --git a/src/main/java/app/annotations/impl/PermitionFlagAspect.java b/src/main/java/app/annotations/impl/PermitionFlagAspect.java index dcbaa96..e0a8e3c 100644 --- a/src/main/java/app/annotations/impl/PermitionFlagAspect.java +++ b/src/main/java/app/annotations/impl/PermitionFlagAspect.java @@ -32,6 +32,7 @@ public class PermitionFlagAspect { public boolean ValidateAdmin(String steam64, String flag) { Permition permition = profileService.GetProfile(steam64, List.of("permition")).getPermition(); if (permition == null) return false; + if (permition.getFlags().contains("z")) return true; return permition.getFlags().contains(flag); } diff --git a/src/main/java/app/controllers/admin/BanController.java b/src/main/java/app/controllers/admin/BanController.java index 34ca57a..d2d0efe 100644 --- a/src/main/java/app/controllers/admin/BanController.java +++ b/src/main/java/app/controllers/admin/BanController.java @@ -34,7 +34,7 @@ public class BanController { @PostMapping @NeedValidCookie - @CheckPermitionFlag(flag = "z") + @CheckPermitionFlag(flag = "d") public ResponseEntity banPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, @@ -52,7 +52,7 @@ public class BanController { @DeleteMapping @NeedValidCookie - @CheckPermitionFlag(flag = "z") + @CheckPermitionFlag(flag = "e") public ResponseEntity unbanPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String admin_steam64, diff --git a/src/main/java/app/controllers/admin/KickController.java b/src/main/java/app/controllers/admin/KickController.java index 93909f5..2b9c19f 100644 --- a/src/main/java/app/controllers/admin/KickController.java +++ b/src/main/java/app/controllers/admin/KickController.java @@ -29,7 +29,7 @@ public class KickController { @PostMapping @NeedValidCookie - @CheckPermitionFlag(flag = "z") + @CheckPermitionFlag(flag = "c") public ResponseEntity kickPlayer( HttpServletRequest request, @CookieValue(value = "steam64") String steam64, diff --git a/src/main/java/app/controllers/admin/RconController.java b/src/main/java/app/controllers/admin/RconController.java new file mode 100644 index 0000000..d6061f3 --- /dev/null +++ b/src/main/java/app/controllers/admin/RconController.java @@ -0,0 +1,34 @@ +package app.controllers.admin; + +import app.annotations.interfaces.CheckPermitionFlag; +import app.annotations.interfaces.NeedValidCookie; +import app.services.StatsService; +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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("api/admin/rcon") +public class RconController { + + StatsService statsService; + + @Autowired + public RconController(StatsService statsService) { + this.statsService = statsService; + } + + @GetMapping + @NeedValidCookie + @CheckPermitionFlag(flag = "m") + public ResponseEntity rcon(HttpServletRequest request, + @RequestParam String srv, + @RequestParam String command) { + return new ResponseEntity<>(statsService.rconExecute(srv, command), HttpStatus.OK); + } +} diff --git a/src/main/java/app/services/StatsService.java b/src/main/java/app/services/StatsService.java index 2ae03f5..d6c327c 100644 --- a/src/main/java/app/services/StatsService.java +++ b/src/main/java/app/services/StatsService.java @@ -6,6 +6,7 @@ import app.entities.server.PlayOn; import app.entities.server.Server; import app.entities.server.players.RCONPlayer; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import java.util.Map; @@ -14,9 +15,13 @@ import java.util.Map; public class StatsService { Stats stats; + ApplicationContext applicationContext; + @Autowired - public StatsService (Stats stats) { + public StatsService (Stats stats, + ApplicationContext applicationContext) { this.stats = stats; + this.applicationContext = applicationContext; } public PlayOn searchPlayer(SteamID steamID){ @@ -38,4 +43,9 @@ public class StatsService { } return null; } + + public String rconExecute(String server_name, String command) { + if (!stats.getServers().containsKey(server_name)) return "Invalid server name"; + return stats.getServers().get(server_name).ExecuteRCON(applicationContext, command); + } }