Browse Source

more env and other

master
gsd 2 years ago
parent
commit
c8d25012b8
  1. 7
      src/main/java/app/controllers/admin/RconController.java
  2. 24
      src/main/java/app/controllers/user/DetailController.java
  3. 49
      src/main/java/app/controllers/user/ProfileController.java
  4. 8
      src/main/java/app/entities/server/Server.java
  5. 4
      src/main/java/app/entities/server/players/RCONPlayer.java
  6. 4
      src/main/java/app/services/db/FreeVIPService.java
  7. 3
      src/main/java/app/updates/PlayersUpdater.java
  8. 10
      src/main/resources/application.yaml

7
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.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("api/admin/rcon") @RequestMapping("api/admin/rcon")
@ -23,7 +20,7 @@ public class RconController {
this.statsService = statsService; this.statsService = statsService;
} }
@GetMapping @PostMapping
@NeedValidCookie @NeedValidCookie
@CheckPermitionFlag(flag = "m") @CheckPermitionFlag(flag = "m")
public ResponseEntity<String> rcon(HttpServletRequest request, public ResponseEntity<String> rcon(HttpServletRequest request,

24
src/main/java/app/controllers/ProfileController.java → 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.CheckPermitionFlag;
import app.annotations.interfaces.NeedValidCookie; import app.annotations.interfaces.NeedValidCookie;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.services.ProfileService; import app.services.ProfileService;
import app.utils.SaltedCookie;
import app.utils.SteamIDConverter;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; 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 @RestController
@RequestMapping("api/profile") @RequestMapping("api/profile")
public class ProfileController { public class DetailController {
private SaltedCookie saltedCookie;
private ProfileService profileService; private ProfileService profileService;
@Autowired @Autowired
public ProfileController(SaltedCookie saltedCookie, public DetailController(ProfileService profileService) {
ProfileService profileService) {
this.saltedCookie = saltedCookie;
this.profileService = profileService; this.profileService = profileService;
} }
@ -33,14 +31,6 @@ public class ProfileController {
return new ResponseEntity(profileService.GetProfile(steam64), HttpStatus.OK); 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") @GetMapping("/steam")
@NeedValidCookie @NeedValidCookie
@CheckPermitionFlag(flag = "z") @CheckPermitionFlag(flag = "z")

49
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);
}
}

8
src/main/java/app/entities/server/Server.java

@ -81,7 +81,13 @@ public class Server {
} }
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
List<String> player_line = Arrays.stream(player_text.split("\\s+")).toList(); List<String> 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) { for (DefaultPlayer sourcePlayer: players) {
if (sourcePlayer.getName().equals(player.getName())) { if (sourcePlayer.getName().equals(player.getName())) {
player.setScore(sourcePlayer.getScore()); player.setScore(sourcePlayer.getScore());

4
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)); id = Integer.parseInt(status_line.get(1));
ip = status_line.get(status_line.size() - 1); ip = status_line.get(status_line.size() - 1);
state = status_line.get(status_line.size() - 2); state = status_line.get(status_line.size() - 2);
if (state.equals("BOT")) {
name = "";
return;
}
loss = Integer.parseInt(status_line.get(status_line.size() - 3)); loss = Integer.parseInt(status_line.get(status_line.size() - 3));
ping = Integer.parseInt(status_line.get(status_line.size() - 4)); ping = Integer.parseInt(status_line.get(status_line.size() - 4));
duration = status_line.get(status_line.size() - 5); duration = status_line.get(status_line.size() - 5);

4
src/main/java/app/services/db/FreeVIPService.java

@ -68,13 +68,13 @@ public class FreeVIPService {
long need_usertime = 60 * 60 * 24 * 2; long need_usertime = 60 * 60 * 24 * 2;
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
long last_free_vip_gived = getLastGivedFreeVIP(socialAuth); 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.Права из под социального аккаунта уже имеются //2.Права из под социального аккаунта уже имеются
return Map.of(2, timeout - (current_server_time - last_free_vip_gived)); return Map.of(2, timeout - (current_server_time - last_free_vip_gived));
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
last_free_vip_gived = getLastGivedFreeVIP(steamID); 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 аккаунта уже имеются //3.Права из под steam аккаунта уже имеются
return Map.of(3, timeout - (current_server_time - last_free_vip_gived)); return Map.of(3, timeout - (current_server_time - last_free_vip_gived));
} }

3
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.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Instant;
@Component @Component
public class PlayersUpdater { public class PlayersUpdater {
Stats stats; Stats stats;
@ -40,5 +42,6 @@ public class PlayersUpdater {
@Job(name = "Update A2S data on: %0") @Job(name = "Update A2S data on: %0")
public void UpdatePlayersOnServer(String server_name) { public void UpdatePlayersOnServer(String server_name) {
stats.RefreshServerA2SData(context, server_name); stats.RefreshServerA2SData(context, server_name);
stats.getUpdates().merge("servers", Instant.now().getEpochSecond(), (x, y) -> y);
} }
} }

10
src/main/resources/application.yaml

@ -25,11 +25,11 @@ backend:
servers_file: ${SERVERS_FILE} servers_file: ${SERVERS_FILE}
geoip_file: ${GEOIP_FILE} geoip_file: ${GEOIP_FILE}
updates: updates:
unique_global: false unique_global: ${UNIQUE_GLOBAL}
unique_server: false unique_server: ${UNIQUE_SERVER}
ban_count: false ban_count: ${BAN_COUNT}
a2s: true a2s: ${A2S}
countries: false countries: ${COUNTRIES}
auth: auth:
salt: ${AUTH_SALT} salt: ${AUTH_SALT}
steam_api_key: ${STEAM_WEBAPI_KEY} steam_api_key: ${STEAM_WEBAPI_KEY}

Loading…
Cancel
Save