diff --git a/src/main/java/app/annotations/impl/WebAccessAspect.java b/src/main/java/app/annotations/impl/WebAccessAspect.java index ca9d165..1f37b1d 100644 --- a/src/main/java/app/annotations/impl/WebAccessAspect.java +++ b/src/main/java/app/annotations/impl/WebAccessAspect.java @@ -34,10 +34,12 @@ public class WebAccessAspect { AuthMethod auth_method = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(CheckWebAccess.class).auth_method(); logger.info("check web access"); if(!(request instanceof HttpServletRequest)) { + logger.error("Invalid request"); throw new RuntimeException("cannot read cookie from invalid request"); } if(request.getHeader("Cookie") == null) { + logger.warn("[{}] Request not contain cookies", request.getHeader("X-Forwarded-For")); throw new NeedCookie(); } String[] rawCookieParams = request.getHeader("Cookie").split(";"); @@ -70,6 +72,7 @@ public class WebAccessAspect { logger.info("used secret key with steamid: {}", steam64); return; } else { + logger.warn("[{}] Request contain invalid secret key: {}, requested steam64: {}", request.getHeader("X-Forwarded-For"), secret_key, steam64); throw new InvalidSecretKey(); } } @@ -81,6 +84,7 @@ public class WebAccessAspect { logger.info("used secret key without steamid"); return; } else { + logger.warn("[{}] Request contain invalid secret key: {}", request.getHeader("X-Forwarded-For"), secret_key); throw new InvalidSecretKey(); } } diff --git a/src/main/java/app/entities/VipGiveMethod.java b/src/main/java/app/entities/VipGiveMethod.java new file mode 100644 index 0000000..4451fdf --- /dev/null +++ b/src/main/java/app/entities/VipGiveMethod.java @@ -0,0 +1,5 @@ +package app.entities; + +public enum VipGiveMethod { + FREE, STEAM, QIWI, MANUAL +} diff --git a/src/main/java/app/services/db/FreeVIPService.java b/src/main/java/app/services/db/FreeVIPService.java index 3407e01..adb3edf 100644 --- a/src/main/java/app/services/db/FreeVIPService.java +++ b/src/main/java/app/services/db/FreeVIPService.java @@ -1,6 +1,7 @@ package app.services.db; import app.entities.SocialAuth; +import app.entities.VipGiveMethod; import app.entities.db.freevip.FreeVIP; import app.entities.other.SteamID; import app.entities.server.Server; @@ -23,19 +24,15 @@ public class FreeVIPService{ @PersistenceContext EntityManager entityManager; - PermitionService permitionService; UsertimeService usertimeService; - @Value("${backend.vip.discord}") - String webhook_url; - RestTemplate restTemplate; + VIPService vipService; @Autowired - public FreeVIPService(PermitionService permitionService, - UsertimeService usertimeService) { - this.permitionService = permitionService; + public FreeVIPService(UsertimeService usertimeService, + VIPService vipService) { this.usertimeService = usertimeService; - this.restTemplate = new RestTemplate(); + this.vipService = vipService; } public Long getDBServerUTime() { @@ -90,7 +87,7 @@ public class FreeVIPService{ < 0 - недостаточно наиграно на сервере времени */ //1.имеются ли уже права - if (permitionService.getPermition(steamID) != null) return 0L; + if (vipService.CheckCurrentPermition(steamID) != null) return 0L; long current_server_time = getDBServerUTime(); long timeout = 60 * 60 * 24 * 30; long need_usertime = 60 * 60 * 24 * 2; @@ -128,20 +125,9 @@ public class FreeVIPService{ if (test != true) { setGivedFreeVip(steamID, socialAuth); - permitionService.addFreeVIP(steamID, 86400); - publishWebhook(steamID, 86400, "Free"); + vipService.addVIP(steamID, 86400, VipGiveMethod.FREE); } return 1L; } - public void publishWebhook(SteamID steamID, int amount, String status) { - HashMap payload = new HashMap<>(); - payload.put("content","Схватил бесплатно!!!"); - payload.put("embeds", List.of(Map.of("fields", List.of( - Map.of("name", "Ссылка на игрока:", "value", steamID.community_url, "inline", true), - Map.of("name", "Количество дней", "value", "%d".formatted(amount/60/60/24), "inline", true), - Map.of("name", "Оплата", "value", status, "inline", true) - )))); - restTemplate.postForEntity(webhook_url, payload, String.class); - } } diff --git a/src/main/java/app/services/db/VIPService.java b/src/main/java/app/services/db/VIPService.java index f2c2db7..fdee169 100644 --- a/src/main/java/app/services/db/VIPService.java +++ b/src/main/java/app/services/db/VIPService.java @@ -1,11 +1,19 @@ package app.services.db; +import app.entities.VipGiveMethod; +import app.entities.db.Permition; +import app.entities.other.SteamID; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service @Transactional @@ -13,6 +21,19 @@ public class VIPService { @PersistenceContext EntityManager entityManager; + RestTemplate restTemplate; + + @Value("${backend.vip.discord}") + String webhook_url; + + PermitionService permitionService; + + @Autowired + public VIPService(PermitionService permitionService) { + this.restTemplate = new RestTemplate(); + this.permitionService = permitionService; + } + public List getUsersDiscordWithActiveVIP() { return entityManager.createNativeQuery("SELECT `discord_id` FROM `sm_admins` INNER JOIN `steam2discord` ON `sm_admins`.`status` LIKE ?1 AND (`sm_admins`.`comment` LIKE ?2 OR `sm_admins`.`comment` LIKE ?3) AND `sm_admins`.`identity` = `steam2discord`.`steam_id`") .setParameter(1, "VIP") @@ -34,4 +55,42 @@ public class VIPService { .setParameter(1, "VIP") .executeUpdate(); } + + public Permition CheckCurrentPermition(SteamID steamID) { + return permitionService.getPermition(steamID); + } + + public void addVIP(SteamID steamID, int amount, VipGiveMethod vipGiveMethod) { + switch (vipGiveMethod){ + case FREE -> { + permitionService.addFreeVIP(steamID, amount); + publishWebhook(steamID, amount, "Free", true); + } + case QIWI -> { + permitionService.addVIP(steamID, amount); + publishWebhook(steamID, amount, "Qiwi", false); + } + case STEAM -> { + permitionService.addVIP(steamID, amount); + publishWebhook(steamID, amount, "Steam", false); + } + } + } + + public void publishWebhook(SteamID steamID, int amount, String status, boolean free) { + HashMap payload = new HashMap<>(); + //МДА БЛЯТЬ НЕ СМОТРИТЕ ЧТО НИЖЕ + if (free == true) { + payload.put("content", "Схватил бесплатно!!!"); + } else { + payload.put("content", "Делать деньги, делать деньги блять вот так..."); + //тут надо еще добавить + } + payload.put("embeds", List.of(Map.of("fields", List.of( + Map.of("name", "Ссылка на игрока:", "value", steamID.community_url, "inline", true), + Map.of("name", "Количество дней", "value", "%d".formatted(amount/60/60/24), "inline", true), + Map.of("name", "Оплата", "value", status, "inline", true) + )))); + restTemplate.postForEntity(webhook_url, payload, String.class); + } } diff --git a/src/main/java/app/utils/SaltedCookie.java b/src/main/java/app/utils/SaltedCookie.java index cc654e9..7277fad 100644 --- a/src/main/java/app/utils/SaltedCookie.java +++ b/src/main/java/app/utils/SaltedCookie.java @@ -74,7 +74,7 @@ public class SaltedCookie { public boolean ValidateSecretKey(String secret_key) { if (secret_keys == null || secret_keys.isEmpty()) return false; if (secret_keys.containsKey(secret_key)) { - logger.info("Use secret key: {}", secret_keys.get(secret_key)); + logger.debug("Use secret key: {}", secret_keys.get(secret_key)); return true; } return false; diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 83719ae..a1d2f98 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -54,4 +54,6 @@ backend: logging: level: com.ibasco.agql.core.util.*: OFF - app.updates.PlayersUpdater: ERROR \ No newline at end of file + app.updates.PlayersUpdater: ERROR + app.utils.SaltedCookie: INFO + app.annotations.impl.WebAccessAspect: WARN \ No newline at end of file