From 31556f96151718720fa41bffa2b83ba05228c86e Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 26 Sep 2023 17:56:10 +0300 Subject: [PATCH] hype --- .../discord/DiscordController.java | 19 ++++++++++++++ .../controllers/user/ProfileController.java | 3 +++ src/main/java/app/entities/PlayerProfile.java | 2 ++ .../java/app/services/ProfileService.java | 17 ++++++++---- .../java/app/services/db/DetectService.java | 6 +++++ .../app/services/db/DiscordAuthService.java | 26 +++++++++++++++++++ 6 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/main/java/app/controllers/discord/DiscordController.java b/src/main/java/app/controllers/discord/DiscordController.java index 0a3114d..ff0ce75 100644 --- a/src/main/java/app/controllers/discord/DiscordController.java +++ b/src/main/java/app/controllers/discord/DiscordController.java @@ -11,6 +11,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.HashMap; +import java.util.List; + @RestController @RequestMapping("api/discord") public class DiscordController { @@ -48,6 +51,7 @@ public class DiscordController { if (steamID != null) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); steamID = SteamIDConverter.getSteamID(steam64); boolean result = discordAuthService.setSteamIDofDiscordID(steamID, discord_id); + if (result) discordAuthService.setProcessing_accounts("reg",discord_id); return new ResponseEntity(result ,HttpStatus.CREATED); } @@ -58,6 +62,21 @@ public class DiscordController { SteamID steamID = discordAuthService.getSteamIDofDiscordID(discord_id); if (steamID == null) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); boolean result = discordAuthService.removeSteamIDofDiscordID(steamID); + if (result) discordAuthService.setProcessing_accounts("unreg",discord_id); return new ResponseEntity(result, HttpStatus.OK); } + + @GetMapping("/sync") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity getCurrentProcessingAccounts(HttpServletRequest request) { + return new ResponseEntity(discordAuthService.getProcessing_accounts(), HttpStatus.OK); + } + + @PostMapping("/sync") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity syncAuthDiscordUsers(HttpServletRequest request, + @RequestBody List discord_accounts) { + return new ResponseEntity(discordAuthService.getAccountsNotInList(discord_accounts), HttpStatus.OK); + } + } diff --git a/src/main/java/app/controllers/user/ProfileController.java b/src/main/java/app/controllers/user/ProfileController.java index 56a160c..9724493 100644 --- a/src/main/java/app/controllers/user/ProfileController.java +++ b/src/main/java/app/controllers/user/ProfileController.java @@ -76,6 +76,9 @@ public class ProfileController { @CookieValue(value = "steam64", defaultValue = "") String steam64, @RequestParam(value = "steam64", defaultValue = "") String reported_steam64, @RequestParam(value = "text", defaultValue = "") String text) { + if (profileService.GetProfile(steam64, "ban").getBan() != null) + return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).build(); + return new ResponseEntity(reportService.createReport( profileService.GetProfile(steam64, "permition,steam_data"), profileService.GetProfile(reported_steam64, "permition"), diff --git a/src/main/java/app/entities/PlayerProfile.java b/src/main/java/app/entities/PlayerProfile.java index bc01599..361157a 100644 --- a/src/main/java/app/entities/PlayerProfile.java +++ b/src/main/java/app/entities/PlayerProfile.java @@ -9,6 +9,7 @@ import lombok.Data; import java.math.BigDecimal; import java.util.HashMap; +import java.util.List; @Data public class PlayerProfile { @@ -20,4 +21,5 @@ public class PlayerProfile { SteamData steam_data; SteamID steamids; PlayOn play_on; + List attached_discords; } diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index dafb497..16b882e 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -4,10 +4,7 @@ import app.entities.PlayerProfile; import app.entities.Stats; import app.entities.db.Ban; import app.entities.other.SteamID; -import app.services.db.BanService; -import app.services.db.DiscordAuthService; -import app.services.db.PermitionService; -import app.services.db.UsertimeService; +import app.services.db.*; import app.services.steam.SteamWebApi; import app.utils.SteamIDConverter; import app.utils.SteamInviteConverter; @@ -26,19 +23,22 @@ public class ProfileService { StatsService statsService; BanService banService; DiscordAuthService discordAuthService; + DetectService detectService; @Autowired public ProfileService(SteamWebApi steamWebApi, UsertimeService usertimeService, PermitionService permitionService, StatsService statsService, BanService banService, - DiscordAuthService discordAuthService) { + DiscordAuthService discordAuthService, + DetectService detectService) { this.steamWebApi = steamWebApi; this.usertimeService = usertimeService; this.permitionService = permitionService; this.statsService = statsService; this.banService = banService; this.discordAuthService = discordAuthService; + this.detectService = detectService; } public PlayerProfile GetProfile(SteamID steamID, List requests) { @@ -103,6 +103,13 @@ public class ProfileService { profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000); //} + if(requests.contains("attached_discord")){ + start_time = Instant.now().toEpochMilli(); + profile.setAttached_discords(detectService.getAttachedDiscordAccountPerSteam(steamID)); + end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("attached_discord", Double.valueOf(end_time) / 1000); + } + return profile; } diff --git a/src/main/java/app/services/db/DetectService.java b/src/main/java/app/services/db/DetectService.java index 9e0ee21..d23c1f3 100644 --- a/src/main/java/app/services/db/DetectService.java +++ b/src/main/java/app/services/db/DetectService.java @@ -19,5 +19,11 @@ public class DetectService { .setParameter(1, steamID.steam2) .getResultStream().map(SteamIDConverter::getSteamID).toList(); } + + public List getAttachedDiscordAccountPerSteam(SteamID steamID) { + return entityManager.createNativeQuery("SELECT `discord_id`, UNIX_TIMESTAMP(`timestamp`) as utime, `active` FROM `steam2discord` WHERE `steam_id` LIKE ?1 GROUP BY `discord_id`") + .setParameter(1, steamID.steam2) + .getResultList(); + } //SELECT CONCAT(SUBSTRING_INDEX(connect_ip,'.', 1),'.',SUBSTRING_INDEX(SUBSTRING_INDEX(connect_ip,'.', 2),'.',-1),'.',SUBSTRING_INDEX(SUBSTRING_INDEX(connect_ip,'.', 3),'.',-1),'.','%') FROM `all_users_con_2` WHERE `steam_id` LIKE 'STEAM_0:1:768781968'; } diff --git a/src/main/java/app/services/db/DiscordAuthService.java b/src/main/java/app/services/db/DiscordAuthService.java index 67209ac..b9dcc0c 100644 --- a/src/main/java/app/services/db/DiscordAuthService.java +++ b/src/main/java/app/services/db/DiscordAuthService.java @@ -7,12 +7,19 @@ import jakarta.persistence.PersistenceContext; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @Service @Transactional public class DiscordAuthService { @PersistenceContext EntityManager entityManager; + private HashMap> processing_accounts = new HashMap<>(); + public SteamID getSteamIDofDiscordID(String discord_id) { return (SteamID) entityManager.createNativeQuery("SELECT steam_id FROM steam2discord WHERE discord_id = ?1 AND active = 1 LIMIT 1") .setParameter(1, discord_id) @@ -45,4 +52,23 @@ public class DiscordAuthService { .setParameter(1, steamID.steam2) .executeUpdate() > 0; } + + public List getAccountsNotInList(List discord_accounts) { + return entityManager.createNativeQuery("SELECT `discord_id` FROM `steam2discord` WHERE `active` = 1 AND `discord_id` in ?1") + .setParameter(1, discord_accounts) + .getResultStream().map(String::valueOf).toList(); + } + + public HashMap> getProcessing_accounts() { + HashMap> copy = (HashMap>) Map.copyOf(this.processing_accounts); + this.processing_accounts.clear(); + return copy; + } + + public void setProcessing_accounts(String slot, String processing_account) { + if (!this.processing_accounts.containsKey(slot)) { + this.processing_accounts.put(slot, new ArrayList<>()); + } + this.processing_accounts.get(slot).add(processing_account); + } }