mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-27 13:15:29 +01:00
Added timeout for the server checker CUSTOM tactic
This commit is contained in:
parent
0eacf4da31
commit
5f7b7deb48
@ -3,15 +3,11 @@ package com.jaimemartz.playerbalancer.connection;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.provider.AbstractProvider;
|
||||
import com.jaimemartz.playerbalancer.connection.provider.types.*;
|
||||
import com.jaimemartz.playerbalancer.ping.ServerStatus;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public enum ProviderType {
|
||||
NONE {
|
||||
|
@ -16,7 +16,9 @@ public enum PingTactic {
|
||||
public void ping(ServerInfo server, Callback<ServerStatus> callback, PlayerBalancer plugin) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
|
||||
try {
|
||||
StatusResponse response = utility.ping(server.getAddress());
|
||||
StatusResponse response = utility.ping(
|
||||
server.getAddress(),
|
||||
plugin.getSettings().getServerCheckerProps().getTimeout());
|
||||
callback.done(new ServerStatus(
|
||||
response.getDescription().toLegacyText(),
|
||||
response.getPlayers().getOnline(),
|
||||
|
@ -20,6 +20,9 @@ public class ServerCheckerProps {
|
||||
@Setting
|
||||
private int interval;
|
||||
|
||||
@Setting
|
||||
private int timeout;
|
||||
|
||||
@Setting(value = "marker-descs")
|
||||
private List<String> markerDescs;
|
||||
|
||||
@ -58,6 +61,14 @@ public class ServerCheckerProps {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public List<String> getMarkerDescs() {
|
||||
return markerDescs;
|
||||
}
|
||||
@ -81,6 +92,7 @@ public class ServerCheckerProps {
|
||||
", tactic=" + tactic +
|
||||
", attempts=" + attempts +
|
||||
", interval=" + interval +
|
||||
", timeout=" + timeout +
|
||||
", markerDescs=" + markerDescs +
|
||||
", debug=" + debug +
|
||||
'}';
|
||||
|
@ -17,7 +17,6 @@ import java.net.Socket;
|
||||
import java.util.List;
|
||||
|
||||
public final class ServerListPing {
|
||||
private int timeout = 7000;
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(BaseComponent.class, new ComponentSerializer())
|
||||
.registerTypeAdapter(TextComponent.class, new TextComponentSerializer())
|
||||
@ -48,7 +47,7 @@ public final class ServerListPing {
|
||||
}
|
||||
}
|
||||
|
||||
public StatusResponse ping(InetSocketAddress host) throws IOException {
|
||||
public StatusResponse ping(InetSocketAddress host, int timeout) throws IOException {
|
||||
try (Socket socket = new Socket()) {
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.connect(host, timeout);
|
||||
@ -118,14 +117,6 @@ public final class ServerListPing {
|
||||
}
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public static class StatusResponse {
|
||||
private BaseComponent description;
|
||||
private Players players;
|
||||
|
@ -132,6 +132,9 @@ features {
|
||||
# The interval between every round of checks (in milliseconds)
|
||||
interval=10000
|
||||
|
||||
# The timeout of a ping, only applied to the CUSTOM tactic
|
||||
timeout=7000
|
||||
|
||||
# When true, the plugin will print useful info when a server gets checked
|
||||
debug-info=false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user