Browse Source

hype features

master
gsd 9 months ago
parent
commit
641ae93bcd
  1. 15
      src/main/java/app/controllers/user/KillFeedController.java
  2. 1
      src/main/java/app/entities/PlayerProfile.java
  3. 30
      src/main/java/app/services/ProfileService.java
  4. 16
      src/main/java/app/services/StatsService.java
  5. 82
      src/main/java/app/services/db/KillfeedService.java

15
src/main/java/app/controllers/user/KillFeedController.java

@ -60,11 +60,12 @@ public class KillFeedController {
@RequestParam(required = false) String steam64, @RequestParam(required = false) String steam64,
@RequestParam(required = false) String srv, @RequestParam(required = false) String srv,
@RequestParam(required = false, defaultValue = "0") Integer offset, @RequestParam(required = false, defaultValue = "0") Integer offset,
@RequestParam(required = false, defaultValue = "20") Integer limit) { @RequestParam(required = false, defaultValue = "20") Integer limit,
@RequestParam(required = false, defaultValue = "false") boolean current) {
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64); SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND); if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity(killfeedService.getKills(steamID, srv, offset, limit), HttpStatus.OK); return new ResponseEntity(killfeedService.getKills(steamID, srv, offset, limit, current), HttpStatus.OK);
} }
@PutMapping @PutMapping
@ -76,11 +77,12 @@ public class KillFeedController {
@RequestParam(required = false) String steam64, @RequestParam(required = false) String steam64,
@RequestParam(required = false) String srv, @RequestParam(required = false) String srv,
@RequestParam(required = false, defaultValue = "0") Integer offset, @RequestParam(required = false, defaultValue = "0") Integer offset,
@RequestParam(required = false, defaultValue = "20") Integer limit) { @RequestParam(required = false, defaultValue = "20") Integer limit,
@RequestParam(required = false, defaultValue = "false") boolean current) {
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64); SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND); if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity(killfeedService.getAssists(steamID, srv, offset, limit), HttpStatus.OK); return new ResponseEntity(killfeedService.getAssists(steamID, srv, offset, limit, current), HttpStatus.OK);
} }
@DeleteMapping @DeleteMapping
@ -92,11 +94,12 @@ public class KillFeedController {
@RequestParam(required = false) String steam64, @RequestParam(required = false) String steam64,
@RequestParam(required = false) String srv, @RequestParam(required = false) String srv,
@RequestParam(required = false, defaultValue = "0") Integer offset, @RequestParam(required = false, defaultValue = "0") Integer offset,
@RequestParam(required = false, defaultValue = "20") Integer limit) { @RequestParam(required = false, defaultValue = "20") Integer limit,
@RequestParam(required = false, defaultValue = "false") boolean current) {
SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64); SteamID steamID = steam64 == null || steam64.isEmpty() ? SteamIDConverter.getSteamID(mysteam64) : SteamIDConverter.getSteamID(steam64);
if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND); if (steamID == null) return new ResponseEntity(HttpStatus.NOT_FOUND);
if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity(killfeedService.getDeads(steamID, srv, offset, limit), HttpStatus.OK); return new ResponseEntity(killfeedService.getDeads(steamID, srv, offset, limit, current), HttpStatus.OK);
} }
@DeleteMapping("/top") @DeleteMapping("/top")

1
src/main/java/app/entities/PlayerProfile.java

@ -30,6 +30,7 @@ public class PlayerProfile {
List<DonateStat> donates; List<DonateStat> donates;
List<Ban> ban_list; List<Ban> ban_list;
Killfeed killfeed; Killfeed killfeed;
Killfeed killfeed_current;
Long messages; Long messages;
ReportCount reports; ReportCount reports;
} }

30
src/main/java/app/services/ProfileService.java

@ -213,15 +213,15 @@ public class ProfileService {
}); });
} }
if(requests.contains("killfeed")){ if(requests.contains("killfeed")) {
callables.add(() -> { callables.add(() -> {
try { try {
long start_time = Instant.now().toEpochMilli(); long start_time = Instant.now().toEpochMilli();
profile.setKillfeed((new Killfeed()) profile.setKillfeed((new Killfeed())
.setKills(killfeedService.getKills(steamID, null)) .setKills(killfeedService.getKills(steamID, null, null))
.setDeads(killfeedService.getDeads(steamID, null)) .setDeads(killfeedService.getDeads(steamID, null, null))
.setAssists(killfeedService.getAssists(steamID, null)) .setAssists(killfeedService.getAssists(steamID, null, null))
.setSuicides(killfeedService.getSuicides(steamID, null))); .setSuicides(killfeedService.getSuicides(steamID, null, null)));
long end_time = Instant.now().toEpochMilli() - start_time; long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("killfeed", (double) end_time / 1000); profile.getResponse_time().put("killfeed", (double) end_time / 1000);
} catch (Exception err) { } catch (Exception err) {
@ -229,6 +229,26 @@ public class ProfileService {
} }
return null; return null;
}); });
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
Long currentPlayerTimeSession = statsService.searchCurrentPlayerStartTime(steamID);
if (currentPlayerTimeSession != null) {
Long ses_start = Instant.now().getEpochSecond() - currentPlayerTimeSession;
profile.setKillfeed_current((new Killfeed())
.setKills(killfeedService.getKills(steamID, null, ses_start))
.setDeads(killfeedService.getDeads(steamID, null, ses_start))
.setAssists(killfeedService.getAssists(steamID, null, ses_start))
.setSuicides(killfeedService.getSuicides(steamID, null, ses_start)));
}
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("killfeed_current", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
} }
if(requests.contains("reports")){ if(requests.contains("reports")){

16
src/main/java/app/services/StatsService.java

@ -6,6 +6,7 @@ import app.entities.other.SteamID;
import app.entities.server.PlayOn; import app.entities.server.PlayOn;
import app.entities.server.Server; import app.entities.server.Server;
import app.entities.server.players.RCONPlayer; import app.entities.server.players.RCONPlayer;
import app.entities.server.request.PlayerOnServer;
import app.services.io.readers.GeoIP; import app.services.io.readers.GeoIP;
import app.utils.CryptedCookie; import app.utils.CryptedCookie;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -39,6 +40,21 @@ public class StatsService {
return null; return null;
} }
private PlayerOnServer searchCurrentPlayer(SteamID steamID) {
for (Map.Entry<String, Server> stringServerEntry : stats.getServers().entrySet()) {
RCONPlayer player = stringServerEntry.getValue().searchPlayer(steamID);
if (player != null) return (PlayerOnServer) player;
}
return null;
}
public Long searchCurrentPlayerStartTime(SteamID steamID) {
PlayerOnServer player = searchCurrentPlayer(steamID);
if (player != null) {
return Integer.valueOf(player.getDuration_seconds()).longValue();
} else return null;
}
public SteamID searchPlayer(String player_nickname){ public SteamID searchPlayer(String player_nickname){
for (Map.Entry<String, Server> stringServerEntry : stats.getServers().entrySet()) { for (Map.Entry<String, Server> stringServerEntry : stats.getServers().entrySet()) {
SteamID steamID = stringServerEntry.getValue().searchPlayer(player_nickname); SteamID steamID = stringServerEntry.getValue().searchPlayer(player_nickname);

82
src/main/java/app/services/db/KillfeedService.java

@ -2,6 +2,7 @@ package app.services.db;
import app.entities.Stats; import app.entities.Stats;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.services.StatsService;
import lombok.Data; import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -11,6 +12,7 @@ import org.springframework.stereotype.Service;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -23,15 +25,18 @@ public class KillfeedService {
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
private Stats stats; private Stats stats;
private NicknameService nicknameService; private NicknameService nicknameService;
private StatsService statsService;
KillfeedService(Stats stats, NicknameService nicknameService) { @Autowired
KillfeedService(Stats stats, NicknameService nicknameService, StatsService statsService) {
this.stats = stats; this.stats = stats;
this.nicknameService = nicknameService; this.nicknameService = nicknameService;
this.statsService = statsService;
} }
public Long getKills(SteamID steamID, String server_id) { public Long getKills(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `utime` > ? AND `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, new Object[]{ utime==null?0:utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")) (rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);
} }
@ -42,9 +47,9 @@ public class KillfeedService {
(rs, n) -> new TopInFeed(rs).setNicknames(nicknameService)); (rs, n) -> new TopInFeed(rs).setNicknames(nicknameService));
} }
public Long getDeads(SteamID steamID, String server_id) { public Long getDeads(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `utime` > ? AND `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, new Object[]{ utime==null?0:utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")) (rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);
} }
@ -55,16 +60,16 @@ public class KillfeedService {
(rs, n) -> new TopInFeed(rs).setNicknames(nicknameService)); (rs, n) -> new TopInFeed(rs).setNicknames(nicknameService));
} }
public Long getSuicides(SteamID steamID, String server_id) { public Long getSuicides(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` = `victim_id` AND `server_id` like ?", return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `utime` > ? AND `victim_id` = ? AND `attacker_id` = `victim_id` AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, new Object[]{ utime==null?0:utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")) (rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);
} }
public Long getAssists(SteamID steamID, String server_id) { public Long getAssists(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `assister_id` = ? AND `server_id` like ?", return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `utime` > ? AND `assister_id` = ? AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id}, new Object[]{ utime==null?0:utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id},
(rs, n) -> rs.getLong("c")) (rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);
} }
@ -81,38 +86,59 @@ public class KillfeedService {
return Map.of("result", result, "count", -1); return Map.of("result", result, "count", -1);
} }
public Map getKills(SteamID steamID, String server_id, int offset, int limit) { public Map getKills(SteamID steamID, String server_id, int offset, int limit, boolean current) {
List<KillsInFeed> result = jdbcTemplate.query("SELECT -1, u.victim_id, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", long current_utime = 0L;
new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset}, if (current) {
Long currentPlayerSesTime = statsService.searchCurrentPlayerStartTime(steamID);
if (currentPlayerSesTime != null) current_utime = Instant.now().getEpochSecond() - currentPlayerSesTime;
else current_utime = Instant.now().getEpochSecond();
}
List<KillsInFeed> result = jdbcTemplate.query("SELECT -1, u.victim_id, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.utime > ? AND u.`attacker_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?",
new Object[]{ current_utime, steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset},
(rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService));
Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE utime > ? AND `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, new Object[]{ current_utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")) (rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);
return Map.of("result", result, "count", count, "type", FeedType.KILL.ordinal()); return Map.of("result", result, "count", count, "type", FeedType.KILL.ordinal());
} }
public Map getDeads(SteamID steamID, String server_id, int offset, int limit) { public Map getDeads(SteamID steamID, String server_id, int offset, int limit, boolean current) {
List<KillsInFeed> result = jdbcTemplate.query("SELECT u.attacker_id, -1, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`victim_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", long current_utime = 0L;
new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset}, if (current) {
Long currentPlayerSesTime = statsService.searchCurrentPlayerStartTime(steamID);
if (currentPlayerSesTime != null) current_utime = Instant.now().getEpochSecond() - currentPlayerSesTime;
else current_utime = Instant.now().getEpochSecond();
}
List<KillsInFeed> result = jdbcTemplate.query("SELECT u.attacker_id, -1, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.utime > ? AND u.`victim_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?",
new Object[]{ current_utime, steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset},
(rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService));
Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE utime > ? AND `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, new Object[]{ current_utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L); (rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L);
return Map.of("result", result, "count", count, "type", FeedType.DEAD.ordinal()); return Map.of("result", result, "count", count, "type", FeedType.DEAD.ordinal());
} }
public Map getAssists(SteamID steamID, String server_id, int offset, int limit) { public Map getAssists(SteamID steamID, String server_id, int offset, int limit, boolean current) {
List<KillsInFeed> result = jdbcTemplate.query("SELECT u.attacker_id, u.victim_id, -1, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`assister_id` = ? AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", long current_utime = 0L;
new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset}, if (current) {
Long currentPlayerSesTime = statsService.searchCurrentPlayerStartTime(steamID);
if (currentPlayerSesTime != null) current_utime = Instant.now().getEpochSecond() - currentPlayerSesTime;
else current_utime = Instant.now().getEpochSecond();
}
List<KillsInFeed> result = jdbcTemplate.query("SELECT u.attacker_id, u.victim_id, -1, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.utime > ? AND u.`assister_id` = ? AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?",
new Object[]{ current_utime, steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset},
(rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService));
Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `assister_id` = ? AND `server_id` like ?", Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE utime > ? AND `assister_id` = ? AND `server_id` like ?",
new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, new Object[]{ current_utime, steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")) (rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);

Loading…
Cancel
Save