From 4907bfa9345eeae9aad967fbdf1bf6cbcc0e8c7a Mon Sep 17 00:00:00 2001 From: gsd Date: Mon, 13 Feb 2023 17:11:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=B0=D0=BB=20=D0=BA=D0=B0=D0=BB=D1=8B?= =?UTF-8?q?=D1=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controllers/ProfileController.java | 29 +++++++++++++++---- .../app/controllers/admin/BanController.java | 9 +++++- .../java/app/services/ProfileService.java | 12 ++++++++ .../java/app/services/db/UsertimeService.java | 12 ++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/main/java/app/controllers/ProfileController.java b/src/main/java/app/controllers/ProfileController.java index ebf2df6..ffd2d8e 100644 --- a/src/main/java/app/controllers/ProfileController.java +++ b/src/main/java/app/controllers/ProfileController.java @@ -1,15 +1,16 @@ package app.controllers; +import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.NeedValidCookie; +import app.entities.other.SteamID; import app.services.ProfileService; import app.utils.SaltedCookie; +import app.utils.SteamIDConverter; +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.CookieValue; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("api/profile") @@ -24,11 +25,27 @@ public class ProfileController { this.profileService = profileService; } + @GetMapping + @NeedValidCookie + @CheckPermitionFlag(flag = "z") + public ResponseEntity GetUser(HttpServletRequest request, + @RequestParam String steam64) { + return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); + } + @GetMapping("/current") @NeedValidCookie - public ResponseEntity GetCurrentUser( - @CookieValue(value = "steam64", defaultValue = "") String steam64 + public ResponseEntity GetCurrentUser(HttpServletRequest request, + @CookieValue(value = "steam64", defaultValue = "") String steam64 ){ return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); } + + @GetMapping("/steam") + @NeedValidCookie + @CheckPermitionFlag(flag = "z") + public ResponseEntity GetSteam(HttpServletRequest request, + @RequestParam String any) { + return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK); + } } diff --git a/src/main/java/app/controllers/admin/BanController.java b/src/main/java/app/controllers/admin/BanController.java index 773f2aa..34ca57a 100644 --- a/src/main/java/app/controllers/admin/BanController.java +++ b/src/main/java/app/controllers/admin/BanController.java @@ -3,8 +3,11 @@ package app.controllers.admin; import app.annotations.interfaces.CheckPermitionFlag; import app.annotations.interfaces.NeedValidCookie; import app.entities.db.Ban; +import app.entities.other.SteamID; import app.services.ProfileService; import app.services.db.BanService; +import app.services.db.PermitionService; +import app.utils.SteamIDConverter; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -18,12 +21,15 @@ import java.util.List; public class BanController { ProfileService profileService; BanService banService; + PermitionService permitionService; @Autowired public BanController(ProfileService profileService, - BanService banService) { + BanService banService, + PermitionService permitionService) { this.profileService = profileService; this.banService = banService; + this.permitionService = permitionService; } @PostMapping @@ -36,6 +42,7 @@ public class BanController { @RequestParam(value = "ban_length", required = false, defaultValue = "0") int ban_length, @RequestParam(value = "ban_reason", required = false, defaultValue = "фурриёб") String ban_reason ){ + if (!permitionService.CheckMorePowerfull(SteamIDConverter.getSteamID(admin_steam64), SteamIDConverter.getSteamID(user_steam64))) return new ResponseEntity(HttpStatus.FORBIDDEN); boolean result = banService.addBan( profileService.GetProfile(user_steam64, List.of("steam_data")), profileService.GetProfile(admin_steam64, List.of("steam_data")), diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 2d39eab..195f70c 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -104,4 +104,16 @@ public class ProfileService { if (steamID == null) return null; return GetProfile(steamID, requests); } + + public SteamID GetSteamIDFromAnyData(String any) { + //1.Проверить не играет ли чел с таким именем на сервере + SteamID result = statsService.searchPlayer(any); + if (result != null) return result; + //2.Проверить что возможно это стим ид в любой интрапретации + result = SteamIDConverter.getSteamID(any); + if (result != null) return result; + //3.Проверить что вводное это имя и проверить в БД + result = usertimeService.getSteamOnUsername(any); + return result; + } } diff --git a/src/main/java/app/services/db/UsertimeService.java b/src/main/java/app/services/db/UsertimeService.java index 3e6797e..a9bc8d0 100644 --- a/src/main/java/app/services/db/UsertimeService.java +++ b/src/main/java/app/services/db/UsertimeService.java @@ -3,6 +3,7 @@ package app.services.db; import app.entities.other.SteamID; import app.entities.server.Server; import app.entities.Stats; +import app.utils.SteamIDConverter; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.springframework.beans.factory.annotation.Autowired; @@ -110,4 +111,15 @@ public class UsertimeService { //.setParameter(1, db) .getResultList()); } + + public SteamID getSteamOnUsername(String username) { + SteamID steamID; + for (Map.Entry stringServerEntry : stats.getServers().entrySet()) { + steamID = (SteamID) entityManager.createNativeQuery("SELECT account_id FROM `"+stringServerEntry.getValue().getDb()+"`.`user_connections` WHERE player_name LIKE ?1 ORDER BY `id` DESC LIMIT 1") + .setParameter(1, username) + .getResultStream().map(x -> SteamIDConverter.getSteamID("[U:1:%d]".formatted(x))).findFirst().orElse(null); + if (steamID != null) return steamID; + } + return null; + } }