Skip to content

Commit 5f7b7de

Browse files
committed
Added timeout for the server checker CUSTOM tactic
1 parent 0eacf4d commit 5f7b7de

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ProviderType.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.connection.provider.AbstractProvider;
55
import com.jaimemartz.playerbalancer.connection.provider.types.*;
6-
import com.jaimemartz.playerbalancer.ping.ServerStatus;
76
import com.jaimemartz.playerbalancer.section.ServerSection;
8-
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
97
import net.md_5.bungee.api.config.ServerInfo;
108
import net.md_5.bungee.api.connection.ProxiedPlayer;
119

12-
import java.util.ArrayList;
1310
import java.util.List;
14-
import java.util.concurrent.ThreadLocalRandom;
1511

1612
public enum ProviderType {
1713
NONE {

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/PingTactic.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public enum PingTactic {
1616
public void ping(ServerInfo server, Callback<ServerStatus> callback, PlayerBalancer plugin) {
1717
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
1818
try {
19-
StatusResponse response = utility.ping(server.getAddress());
19+
StatusResponse response = utility.ping(
20+
server.getAddress(),
21+
plugin.getSettings().getServerCheckerProps().getTimeout());
2022
callback.done(new ServerStatus(
2123
response.getDescription().toLegacyText(),
2224
response.getPlayers().getOnline(),

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/ServerCheckerProps.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class ServerCheckerProps {
2020
@Setting
2121
private int interval;
2222

23+
@Setting
24+
private int timeout;
25+
2326
@Setting(value = "marker-descs")
2427
private List<String> markerDescs;
2528

@@ -58,6 +61,14 @@ public void setInterval(int interval) {
5861
this.interval = interval;
5962
}
6063

64+
public int getTimeout() {
65+
return timeout;
66+
}
67+
68+
public void setTimeout(int timeout) {
69+
this.timeout = timeout;
70+
}
71+
6172
public List<String> getMarkerDescs() {
6273
return markerDescs;
6374
}
@@ -81,6 +92,7 @@ public String toString() {
8192
", tactic=" + tactic +
8293
", attempts=" + attempts +
8394
", interval=" + interval +
95+
", timeout=" + timeout +
8496
", markerDescs=" + markerDescs +
8597
", debug=" + debug +
8698
'}';

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.List;
1818

1919
public final class ServerListPing {
20-
private int timeout = 7000;
2120
private static Gson gson = new GsonBuilder()
2221
.registerTypeAdapter(BaseComponent.class, new ComponentSerializer())
2322
.registerTypeAdapter(TextComponent.class, new TextComponentSerializer())
@@ -48,7 +47,7 @@ private static void writeVarInt(DataOutputStream out, int paramInt) throws IOExc
4847
}
4948
}
5049

51-
public StatusResponse ping(InetSocketAddress host) throws IOException {
50+
public StatusResponse ping(InetSocketAddress host, int timeout) throws IOException {
5251
try (Socket socket = new Socket()) {
5352
socket.setSoTimeout(timeout);
5453
socket.connect(host, timeout);
@@ -118,14 +117,6 @@ public StatusResponse ping(InetSocketAddress host) throws IOException {
118117
}
119118
}
120119

121-
public void setTimeout(int timeout) {
122-
this.timeout = timeout;
123-
}
124-
125-
public int getTimeout() {
126-
return timeout;
127-
}
128-
129120
public static class StatusResponse {
130121
private BaseComponent description;
131122
private Players players;

Main Plugin/src/main/resources/default.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ features {
132132
# The interval between every round of checks (in milliseconds)
133133
interval=10000
134134

135+
# The timeout of a ping, only applied to the CUSTOM tactic
136+
timeout=7000
137+
135138
# When true, the plugin will print useful info when a server gets checked
136139
debug-info=false
137140

0 commit comments

Comments
 (0)