Browse Source

hype

master
gsd 2 years ago
parent
commit
31556f9615
  1. 19
      src/main/java/app/controllers/discord/DiscordController.java
  2. 3
      src/main/java/app/controllers/user/ProfileController.java
  3. 2
      src/main/java/app/entities/PlayerProfile.java
  4. 17
      src/main/java/app/services/ProfileService.java
  5. 6
      src/main/java/app/services/db/DetectService.java
  6. 26
      src/main/java/app/services/db/DiscordAuthService.java

19
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<HashMap> getCurrentProcessingAccounts(HttpServletRequest request) {
return new ResponseEntity(discordAuthService.getProcessing_accounts(), HttpStatus.OK);
}
@PostMapping("/sync")
@CheckWebAccess(auth_method = AuthMethod.SECRET_KEY)
public ResponseEntity<List> syncAuthDiscordUsers(HttpServletRequest request,
@RequestBody List<String> discord_accounts) {
return new ResponseEntity(discordAuthService.getAccountsNotInList(discord_accounts), HttpStatus.OK);
}
}

3
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"),

2
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;
}

17
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<String> 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;
}

6
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';
}

26
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<String, List<String>> 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<String> getAccountsNotInList(List<String> 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<String, List<String>> getProcessing_accounts() {
HashMap<String, List<String>> copy = (HashMap<String, List<String>>) 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);
}
}

Loading…
Cancel
Save