You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

128 lines
5.1 KiB

package app.services;
import app.entities.PlayerProfile;
import app.entities.Stats;
import app.entities.other.SteamID;
import app.services.db.BanService;
import app.services.db.PermitionService;
import app.services.db.UsertimeService;
import app.services.steam.SteamWebApi;
import app.utils.SteamIDConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
@Service
public class ProfileService {
SteamWebApi steamWebApi;
UsertimeService usertimeService;
PermitionService permitionService;
StatsService statsService;
BanService banService;
@Autowired
public ProfileService(SteamWebApi steamWebApi,
UsertimeService usertimeService,
PermitionService permitionService,
StatsService statsService,
BanService banService) {
this.steamWebApi = steamWebApi;
this.usertimeService = usertimeService;
this.permitionService = permitionService;
this.statsService = statsService;
this.banService = banService;
}
public PlayerProfile GetProfile(SteamID steamID, List<String> requests) {
return GetProfile(steamID.steam64, requests);
}
public PlayerProfile GetProfile(Long steam64, List<String> requests){
return GetProfile(steam64.toString(), requests);
}
public PlayerProfile GetProfile(String steam64, List<String> requests) {
PlayerProfile profile = new PlayerProfile();
profile.setResponse_time(new HashMap<>());
SteamID steamID = SteamIDConverter.getSteamID(steam64);
profile.setSteamids(steamID);
Long start_time, end_time;
start_time = Instant.now().toEpochMilli();
profile.setPlay_on(statsService.searchPlayer(steamID));
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("play_on", Double.valueOf(end_time) / 1000);
if(requests.contains("steam_data")){
start_time = Instant.now().toEpochMilli();
profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64));
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("steam_data", Double.valueOf(end_time) / 1000);
}
if(requests.contains("lastplay")){
start_time = Instant.now().toEpochMilli();
profile.setLastplay(usertimeService.getPlayerLastplay(steamID));
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("lastplay", Double.valueOf(end_time) / 1000);
}
if(requests.contains("usertime")){
start_time = Instant.now().toEpochMilli();
profile.setGametime(usertimeService.getPlayerUsertime(steamID));
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("usertime", Double.valueOf(end_time) / 1000);
}
//if(requests.contains("permition")){
start_time = Instant.now().toEpochMilli();
profile.setPermition(permitionService.getPermition(steamID));
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("permition", Double.valueOf(end_time) / 1000);
//}
//if(requests.contains("ban")){
start_time = Instant.now().toEpochMilli();
profile.setBan(banService.getBan(steamID));
if(profile.getBan() != null) {
profile.getBan().setAdmin_info(
permitionService.getAdminInfo(SteamIDConverter.getSteamID(profile.getBan().getBanned_by_id()))
);
}
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000);
//}
return profile;
}
public PlayerProfile GetProfile(String steam64) {
return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition,ban".split(",")));
}
public PlayerProfile GetProfile(String steam64, String requests) {
return GetProfile(steam64, List.of(requests.split(",")));
}
public PlayerProfile GetProfileOnPlayerOnServers(String name, List<String> requests) {
SteamID steamID = statsService.searchPlayer(name);
if (steamID == null) return null;
return GetProfile(steamID, requests);
}
public SteamID GetSteamIDFromAnyData(String any) {
//1.Проверить не играет ли чел с таким именем на сервере
SteamID result = statsService.searchPlayer(any);
if (result != null) return result;
//2.Проверить что возможно это стим ид в любой интрапретации
result = SteamIDConverter.getSteamID(any);
if (result != null) return result;
//3.Проверить что вводное это имя и проверить в БД
result = usertimeService.getSteamOnUsername(any);
return result;
}
}