From c47e74a36037b226224d8409fdfeb2402a1860c5 Mon Sep 17 00:00:00 2001 From: gsd Date: Sun, 19 Feb 2023 19:37:45 +0300 Subject: [PATCH] a2splayers --- src/main/java/app/entities/server/Server.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java index e57036c..0689957 100644 --- a/src/main/java/app/entities/server/Server.java +++ b/src/main/java/app/entities/server/Server.java @@ -3,10 +3,10 @@ package app.entities.server; import app.entities.other.SteamID; import app.entities.server.players.DefaultPlayer; import app.entities.server.players.RCONPlayer; +import app.entities.server.players.SourcePlayer; import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.ibasco.agql.protocols.valve.source.query.info.SourceQueryInfoResponse; -import com.ibasco.agql.protocols.valve.source.query.players.SourcePlayer; import com.ibasco.agql.protocols.valve.source.query.players.SourceQueryPlayerResponse; import com.ibasco.agql.protocols.valve.source.query.rcon.SourceRconClient; import com.ibasco.agql.protocols.valve.source.query.rcon.message.SourceRconAuthResponse; @@ -36,7 +36,9 @@ public class Server { String workshop; List naming; HashMap uniq = new HashMap<>(); - List players = new ArrayList<>(); + List players = new ArrayList<>(); + @JsonIgnore + List a2s_players = new ArrayList<>(); @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) private String db; @@ -66,15 +68,14 @@ public class Server { } public void UpdatePlayersFromA2S(SourceQueryPlayerResponse response) { - players.clear(); + a2s_players.clear(); if (response != null) { - for (SourcePlayer player: response.getResult()) { - players.add(new app.entities.server.players.SourcePlayer(player)); - } + response.getResult().stream().map(app.entities.server.players.SourcePlayer::new).forEach(a2s_players::add); } } public void UpdatePlayersFromRCON(String response) { + players.clear(); int start_index = response.indexOf("# userid"); if (start_index == -1) return; List players_list = Arrays.stream(response.substring(start_index, response.length()).split("\n")).toList(); @@ -93,15 +94,17 @@ public class Server { System.out.println("Cannot parse: " + player_line); continue; } - for (DefaultPlayer sourcePlayer: players) { + + for (SourcePlayer sourcePlayer: a2s_players) { if (sourcePlayer.getName().equals(player.getName())) { player.setScore(sourcePlayer.getScore()); - players.remove(sourcePlayer); + a2s_players.remove(sourcePlayer); players.add(player); break; } } } + a2s_players.clear(); } @JsonIgnore