Browse Source

a2splayers

master
gsd 2 years ago
parent
commit
c47e74a360
  1. 19
      src/main/java/app/entities/server/Server.java

19
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<String> naming;
HashMap<String, Long> uniq = new HashMap<>();
List<DefaultPlayer> players = new ArrayList<>();
List<RCONPlayer> players = new ArrayList<>();
@JsonIgnore
List<SourcePlayer> 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<String> 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

Loading…
Cancel
Save