|
|
@ -8,8 +8,12 @@ import app.entities.server.players.RCONPlayer; |
|
|
|
import com.fasterxml.jackson.annotation.JsonGetter; |
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
|
|
|
import com.ibasco.agql.core.enums.RateLimitType; |
|
|
|
import com.ibasco.agql.core.exceptions.ReadTimeoutException; |
|
|
|
import com.ibasco.agql.core.util.FailsafeOptions; |
|
|
|
import com.ibasco.agql.core.util.GeneralOptions; |
|
|
|
import com.ibasco.agql.protocols.valve.source.query.SourceQueryClient; |
|
|
|
import com.ibasco.agql.protocols.valve.source.query.SourceQueryOptions; |
|
|
|
import com.ibasco.agql.protocols.valve.source.query.info.SourceQueryInfoResponse; |
|
|
|
import com.ibasco.agql.protocols.valve.source.query.players.SourceQueryPlayerResponse; |
|
|
|
import com.ibasco.agql.protocols.valve.source.query.rcon.exceptions.RconException; |
|
|
@ -28,6 +32,8 @@ import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.CompletionException; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
@Data |
|
|
|
@Component |
|
|
@ -44,6 +50,7 @@ public class Stats { |
|
|
|
HashMap<String, Long> uniq = new HashMap<>(); |
|
|
|
HashMap<String, Long> updates = new HashMap<>(); |
|
|
|
Statistic statistic = new Statistic(); |
|
|
|
|
|
|
|
@JsonGetter |
|
|
|
public Statistic getStatistic() { |
|
|
|
statistic.setTotal_servers(servers.size()); |
|
|
@ -55,7 +62,7 @@ public class Stats { |
|
|
|
statistic.setPlayer_max(0); |
|
|
|
} |
|
|
|
|
|
|
|
if(statistic.getPlayer_max() < statistic.getPlayer_now()) { |
|
|
|
if (statistic.getPlayer_max() < statistic.getPlayer_now()) { |
|
|
|
statistic.setPlayer_max(statistic.getPlayer_now()); |
|
|
|
} |
|
|
|
return statistic; |
|
|
@ -67,20 +74,22 @@ public class Stats { |
|
|
|
} |
|
|
|
|
|
|
|
public void UpdateUniq(String key, Long value) { |
|
|
|
uniq.merge(key, value, (x,y) -> y); |
|
|
|
uniq.merge(key, value, (x, y) -> y); |
|
|
|
} |
|
|
|
|
|
|
|
public void RefreshServerA2SData(ApplicationContext context, String server_name) throws IOException { |
|
|
|
try (SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class)) { |
|
|
|
public void RefreshServerA2SData(String server_name) throws IOException { |
|
|
|
//try (SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class)) {
|
|
|
|
try (SourceQueryClient sourceQueryClient = GetSourceQueryClient()) { |
|
|
|
sourceQueryClient.getInfo(getServers().get(server_name).getInetAddress()).whenComplete((info, error) -> { |
|
|
|
sourceQueryClient.getExecutor().shutdown(); |
|
|
|
if (!sourceQueryClient.getExecutor().isShutdown()) sourceQueryClient.getExecutor().shutdown(); |
|
|
|
if (error != null) { |
|
|
|
getServers().get(server_name).SetDownStatus(); |
|
|
|
return; |
|
|
|
} |
|
|
|
getServers().get(server_name).UpdateStatusFromA2S(info); |
|
|
|
}).join(); |
|
|
|
} catch (CompletionException err) {} |
|
|
|
} catch (CompletionException err) { |
|
|
|
} |
|
|
|
|
|
|
|
if (!getServers().get(server_name).isStatus() || getServers().get(server_name).getPlayer_count() < 1) { |
|
|
|
return; |
|
|
@ -88,9 +97,10 @@ public class Stats { |
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//If player count > 0 make base player request
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
try (SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class)) { |
|
|
|
//try (SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class)) {
|
|
|
|
try (SourceQueryClient sourceQueryClient = GetSourceQueryClient()) { |
|
|
|
sourceQueryClient.getPlayers(getServers().get(server_name).getInetAddress()).whenComplete((players, error) -> { |
|
|
|
sourceQueryClient.getExecutor().shutdown(); |
|
|
|
if (!sourceQueryClient.getExecutor().isShutdown()) sourceQueryClient.getExecutor().shutdown(); |
|
|
|
if (error != null) return; |
|
|
|
getServers().get(server_name).UpdatePlayersFromA2S(players); |
|
|
|
}).join(); |
|
|
@ -99,10 +109,20 @@ public class Stats { |
|
|
|
//Extend current players of rcon result
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
try { |
|
|
|
String response = getServers().get(server_name).ExecuteRCON(context,"status"); |
|
|
|
String response = getServers().get(server_name).ExecuteRCON("status"); |
|
|
|
getServers().get(server_name).UpdatePlayersFromRCON(response); |
|
|
|
} catch (RconException | CompletionException err) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@JsonIgnore |
|
|
|
public SourceQueryClient GetSourceQueryClient() { |
|
|
|
ExecutorService customExecutor = Executors.newCachedThreadPool(); |
|
|
|
SourceQueryOptions options = SourceQueryOptions.builder() |
|
|
|
.option(FailsafeOptions.FAILSAFE_RATELIMIT_TYPE, RateLimitType.BURST) |
|
|
|
.option(GeneralOptions.THREAD_EXECUTOR_SERVICE, customExecutor) |
|
|
|
.build(); |
|
|
|
return new SourceQueryClient(options); |
|
|
|
} |
|
|
|
} |
|
|
|