From 76bc2cded7c51f99767fde7e6559226425f3bf8d Mon Sep 17 00:00:00 2001 From: gsd Date: Wed, 5 Jun 2024 22:20:47 +0300 Subject: [PATCH] report features --- .../server/ServerUpdaterController.java | 10 ++++++++++ .../java/app/services/db/ReportService.java | 20 +++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/app/controllers/server/ServerUpdaterController.java b/src/main/java/app/controllers/server/ServerUpdaterController.java index 49cf581..d0cb42d 100644 --- a/src/main/java/app/controllers/server/ServerUpdaterController.java +++ b/src/main/java/app/controllers/server/ServerUpdaterController.java @@ -72,4 +72,14 @@ public class ServerUpdaterController { return ResponseEntity.status(HttpStatus.OK).body( reportService.createReport(ReportType.IN_GAME, profileService.GetProfile(body.getAuthor_steam64(), "permition,steam_data"), profileService.GetProfile(body.getReported_steam64(), "permition"), body.getReason())); } + + @PostMapping(value = "/{srv}/report/{report_id}") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity actionReport(HttpServletRequest request, + @PathVariable String srv, + @PathVariable Integer report_id, + @RequestBody String body) { + return ResponseEntity.status(HttpStatus.OK).body(reportService.addReportAction(report_id, body)); + } + } diff --git a/src/main/java/app/services/db/ReportService.java b/src/main/java/app/services/db/ReportService.java index 0b7f09b..a266be3 100644 --- a/src/main/java/app/services/db/ReportService.java +++ b/src/main/java/app/services/db/ReportService.java @@ -56,11 +56,11 @@ public class ReportService { restTemplate = new RestTemplate(); } - private void addReport(PlayerProfile current_user, PlayerProfile reported_user, String text, ReportType reportType) { + private int addReport(PlayerProfile current_user, PlayerProfile reported_user, String text, ReportType reportType) { PlayerOnServer current_player = (PlayerOnServer) statsService.searchPlayer(current_user); PlayerOnServer reported_player = (PlayerOnServer) statsService.searchPlayer(reported_user); - jdbcTemplate_rw.update("INSERT INTO user_reports (a_nickname, a_steam2, a_permition, a_kills, a_deads, a_seconds, " + + return jdbcTemplate_rw.update("INSERT INTO user_reports (a_nickname, a_steam2, a_permition, a_kills, a_deads, a_seconds, " + "r_nickname, r_steam2, r_permition, r_kills, r_deads, r_seconds, " + "reasons, utime, srv, online, type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", current_player == null ? current_user.getSteam_data().getNickname() : current_player.getName(), current_user.getSteamids().steam2, Permition2Prefix(current_user.getPermition()).ordinal(), @@ -78,6 +78,10 @@ public class ReportService { reportType.ordinal()); } + public int addReportAction(int report_id, String action) { + return jdbcTemplate_rw.update("INSERT INTO user_reports_action (report_id, action) VALUES (?, ?)", report_id, action); + } + public long getCreatedReportsCount(SteamID steamID) { return jdbcTemplate_ro.query("SELECT COUNT(*) as c FROM user_reports WHERE a_steam2 LIKE ?", new Object[]{steamID.steam2}, (rs,n) -> rs.getLong("c")).get(0); } @@ -106,16 +110,16 @@ public class ReportService { (Instant.now().getEpochSecond() - userKD.get(current_user.getSteamids().steam64)) < kd) { return (Instant.now().getEpochSecond() - userKD.get(current_user.getSteamids().steam64)) - kd; } - addReport(current_user, reported_user, text, reportType); - long res = createReportToDiscord(current_user, reported_user, text); + int report_id = addReport(current_user, reported_user, text, reportType); + long res = createReportToDiscord(current_user, reported_user, text, report_id); if (res == 0) return 0; userKD.merge(current_user.getSteamids().steam64, res, (x,y) -> y); return res; } case IN_GAME -> { - addReport(current_user, reported_user, text, reportType); - return createReportToDiscord(current_user, reported_user, text); + int report_id = addReport(current_user, reported_user, text, reportType); + return createReportToDiscord(current_user, reported_user, text, report_id); } default -> { return -1; @@ -123,7 +127,7 @@ public class ReportService { } } - private long createReportToDiscord(PlayerProfile current_user, PlayerProfile reported_user, String text) { + private long createReportToDiscord(PlayerProfile current_user, PlayerProfile reported_user, String text, int report_id) { PlayerOnServer current_player = (PlayerOnServer) statsService.searchPlayer(current_user); String author = "%s | %s%s | %s".formatted( current_player == null ? current_user.getSteam_data().getNickname() : current_player.getName(), @@ -157,7 +161,7 @@ public class ReportService { embed.put("url", reported_user.getSteamids().community_url); } embed.put("description", text); - embed.put("color", 16581375); // 255 * 255 * 255 | black + embed.put("color", report_id); // 255 * 255 * 255 | black embed.put("footer", Map.of( "text", "%s • %d/%d ".formatted( stats.getServers().get(reported_user==null?current_user.getPlay_on().getServer_id():reported_user.getPlay_on().getServer_id()).getName(),