Browse Source

rcon controller

master
gsd 2 years ago
parent
commit
923b6764ec
  1. 1
      src/main/java/app/annotations/impl/PermitionFlagAspect.java
  2. 4
      src/main/java/app/controllers/admin/BanController.java
  3. 2
      src/main/java/app/controllers/admin/KickController.java
  4. 34
      src/main/java/app/controllers/admin/RconController.java
  5. 12
      src/main/java/app/services/StatsService.java

1
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);
}

4
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,

2
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,

34
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<String> rcon(HttpServletRequest request,
@RequestParam String srv,
@RequestParam String command) {
return new ResponseEntity<>(statsService.rconExecute(srv, command), HttpStatus.OK);
}
}

12
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);
}
}

Loading…
Cancel
Save