From c8d25012b87daff822237f756ccecaace6935d87 Mon Sep 17 00:00:00 2001 From: gsd Date: Mon, 13 Feb 2023 19:25:10 +0300 Subject: [PATCH] more env and other --- .../app/controllers/admin/RconController.java | 7 +-- .../DetailController.java} | 24 +++------ .../controllers/user/ProfileController.java | 49 +++++++++++++++++++ src/main/java/app/entities/server/Server.java | 8 ++- .../entities/server/players/RCONPlayer.java | 4 ++ .../java/app/services/db/FreeVIPService.java | 4 +- src/main/java/app/updates/PlayersUpdater.java | 3 ++ src/main/resources/application.yaml | 10 ++-- 8 files changed, 79 insertions(+), 30 deletions(-) rename src/main/java/app/controllers/{ProfileController.java => user/DetailController.java} (62%) create mode 100644 src/main/java/app/controllers/user/ProfileController.java diff --git a/src/main/java/app/controllers/admin/RconController.java b/src/main/java/app/controllers/admin/RconController.java index d6061f3..c763cf6 100644 --- a/src/main/java/app/controllers/admin/RconController.java +++ b/src/main/java/app/controllers/admin/RconController.java @@ -7,10 +7,7 @@ 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; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("api/admin/rcon") @@ -23,7 +20,7 @@ public class RconController { this.statsService = statsService; } - @GetMapping + @PostMapping @NeedValidCookie @CheckPermitionFlag(flag = "m") public ResponseEntity rcon(HttpServletRequest request, diff --git a/src/main/java/app/controllers/ProfileController.java b/src/main/java/app/controllers/user/DetailController.java similarity index 62% rename from src/main/java/app/controllers/ProfileController.java rename to src/main/java/app/controllers/user/DetailController.java index ffd2d8e..518e8e0 100644 --- a/src/main/java/app/controllers/ProfileController.java +++ b/src/main/java/app/controllers/user/DetailController.java @@ -1,27 +1,25 @@ -package app.controllers; +package app.controllers.user; 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.*; +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/profile") -public class ProfileController { - private SaltedCookie saltedCookie; +public class DetailController { private ProfileService profileService; @Autowired - public ProfileController(SaltedCookie saltedCookie, - ProfileService profileService) { - this.saltedCookie = saltedCookie; + public DetailController(ProfileService profileService) { this.profileService = profileService; } @@ -33,14 +31,6 @@ public class ProfileController { return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); } - @GetMapping("/current") - @NeedValidCookie - 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") diff --git a/src/main/java/app/controllers/user/ProfileController.java b/src/main/java/app/controllers/user/ProfileController.java new file mode 100644 index 0000000..7a3a87e --- /dev/null +++ b/src/main/java/app/controllers/user/ProfileController.java @@ -0,0 +1,49 @@ +package app.controllers.user; + +import app.annotations.interfaces.CheckPermitionFlag; +import app.annotations.interfaces.NeedValidCookie; +import app.entities.SocialAuth; +import app.entities.other.SteamID; +import app.services.ProfileService; +import app.services.db.FreeVIPService; +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.*; + +@RestController +@RequestMapping("api/profile") +public class ProfileController { + private ProfileService profileService; + private FreeVIPService freeVIPService; + + @Autowired + public ProfileController(ProfileService profileService, + FreeVIPService freeVIPService) { + this.profileService = profileService; + this.freeVIPService = freeVIPService; + } + + @GetMapping("/current") + @NeedValidCookie + public ResponseEntity GetCurrentUser(HttpServletRequest request, + @CookieValue(value = "steam64", defaultValue = "") String steam64 + ){ + return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); + } + + @PostMapping("/current/freevip") + @NeedValidCookie + public ResponseEntity GetFreeVIP(HttpServletRequest request, + @CookieValue(value = "steam64", defaultValue = "") String steam64, + SocialAuth socialAuth) { + //return new ResponseEntity<>(freeVIPService.) + //1.get social + //2.get steam2discord + //3.так уж и быть випка без анального зонда + return new ResponseEntity(freeVIPService.addFreeVIP(SteamIDConverter.getSteamID(steam64), socialAuth), HttpStatus.OK); + } +} diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java index 67f6c44..5c3f38d 100644 --- a/src/main/java/app/entities/server/Server.java +++ b/src/main/java/app/entities/server/Server.java @@ -81,7 +81,13 @@ public class Server { } ///////////////////////////////////////////////////// List player_line = Arrays.stream(player_text.split("\\s+")).toList(); - RCONPlayer player = new RCONPlayer(player_line); + RCONPlayer player; + try { + player = new RCONPlayer(player_line); + } catch (Exception parse_err) { + System.out.println("Cannot parse: " + player_line); + continue; + } for (DefaultPlayer sourcePlayer: players) { if (sourcePlayer.getName().equals(player.getName())) { player.setScore(sourcePlayer.getScore()); diff --git a/src/main/java/app/entities/server/players/RCONPlayer.java b/src/main/java/app/entities/server/players/RCONPlayer.java index f0b3b2e..bb1bc5b 100644 --- a/src/main/java/app/entities/server/players/RCONPlayer.java +++ b/src/main/java/app/entities/server/players/RCONPlayer.java @@ -21,6 +21,10 @@ public class RCONPlayer extends DefaultPlayer { id = Integer.parseInt(status_line.get(1)); ip = status_line.get(status_line.size() - 1); state = status_line.get(status_line.size() - 2); + if (state.equals("BOT")) { + name = ""; + return; + } loss = Integer.parseInt(status_line.get(status_line.size() - 3)); ping = Integer.parseInt(status_line.get(status_line.size() - 4)); duration = status_line.get(status_line.size() - 5); diff --git a/src/main/java/app/services/db/FreeVIPService.java b/src/main/java/app/services/db/FreeVIPService.java index 612dee8..35093a0 100644 --- a/src/main/java/app/services/db/FreeVIPService.java +++ b/src/main/java/app/services/db/FreeVIPService.java @@ -68,13 +68,13 @@ public class FreeVIPService { long need_usertime = 60 * 60 * 24 * 2; //////////////////////////////////////////////////////////////// long last_free_vip_gived = getLastGivedFreeVIP(socialAuth); - if (current_server_time - last_free_vip_gived < timeout) { + if (last_free_vip_gived != 0L && current_server_time - last_free_vip_gived < timeout) { //2.Права из под социального аккаунта уже имеются return Map.of(2, timeout - (current_server_time - last_free_vip_gived)); } //////////////////////////////////////////////////////////////// last_free_vip_gived = getLastGivedFreeVIP(steamID); - if (current_server_time - last_free_vip_gived < timeout) { + if (last_free_vip_gived != 0L && current_server_time - last_free_vip_gived < timeout) { //3.Права из под steam аккаунта уже имеются return Map.of(3, timeout - (current_server_time - last_free_vip_gived)); } diff --git a/src/main/java/app/updates/PlayersUpdater.java b/src/main/java/app/updates/PlayersUpdater.java index f4e0fc0..22ea189 100644 --- a/src/main/java/app/updates/PlayersUpdater.java +++ b/src/main/java/app/updates/PlayersUpdater.java @@ -9,6 +9,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; +import java.time.Instant; + @Component public class PlayersUpdater { Stats stats; @@ -40,5 +42,6 @@ public class PlayersUpdater { @Job(name = "Update A2S data on: %0") public void UpdatePlayersOnServer(String server_name) { stats.RefreshServerA2SData(context, server_name); + stats.getUpdates().merge("servers", Instant.now().getEpochSecond(), (x, y) -> y); } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 69668d6..932c208 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -25,11 +25,11 @@ backend: servers_file: ${SERVERS_FILE} geoip_file: ${GEOIP_FILE} updates: - unique_global: false - unique_server: false - ban_count: false - a2s: true - countries: false + unique_global: ${UNIQUE_GLOBAL} + unique_server: ${UNIQUE_SERVER} + ban_count: ${BAN_COUNT} + a2s: ${A2S} + countries: ${COUNTRIES} auth: salt: ${AUTH_SALT} steam_api_key: ${STEAM_WEBAPI_KEY}