Skip to content

Commit 7a75d48

Browse files
added kick-on-restart, kick-on-busy and removed name from config
1 parent 6f029c8 commit 7a75d48

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

run/proxy/velocity.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ read-timeout = 30000
125125
haproxy-protocol = false
126126

127127
# Enables TCP fast open support on the proxy. Requires the proxy to run on Linux.
128-
tcp-fast-open = true
128+
tcp-fast-open = false
129129

130130
# Enables BungeeCord plugin messaging channel support on Velocity.
131131
bungee-plugin-message-channel = true

src/main/java/org/zeroBzeroT/anarchyqueue/Config.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public class Config {
1313

1414
public static String queue = null;
1515

16-
public static String name = null; // TODO: not in use, implement or remove this
17-
1816
public static int maxPlayers = 0;
1917

2018
public static String messagePosition = null;
@@ -25,7 +23,11 @@ public class Config {
2523

2624
public static String messageOffline = null;
2725

28-
public static boolean kick = true;
26+
public static boolean kickPassthrough = true;
27+
28+
public static boolean kickOnRestart = false;
29+
30+
public static boolean kickOnBusy = false;
2931

3032
public static int waitOnKick = 16;
3133

@@ -61,13 +63,14 @@ static void loadConfig(Path path) throws IOException {
6163
Toml toml = new Toml().read(file);
6264
target = toml.getString("target", "main");
6365
queue = toml.getString("queue", "queue");
64-
name = toml.getString("name", "0b0t");
6566
maxPlayers = toml.getLong("max-players", 420L).intValue();
6667
messagePosition = toml.getString("message-position", "Position in queue: ");
6768
messageConnecting = toml.getString("message-connecting", "Connecting to the server...");
6869
messageFull = toml.getString("message-full", "Server is currently full!");
6970
messageOffline = toml.getString("message-offline", "Server is currently offline!");
70-
kick = toml.getBoolean("kick", true);
71+
kickPassthrough = toml.getBoolean("kick-passthrough", true);
72+
kickOnRestart = toml.getBoolean("kick-on-restart", false);
73+
kickOnBusy = toml.getBoolean("kick-on-busy", false);
7174
waitOnKick = toml.getLong("wait-on-kick", 16L).intValue();
7275
sendTitle = toml.getBoolean("send-title", true);
7376
bStats = toml.getBoolean("bStats", true);

src/main/java/org/zeroBzeroT/anarchyqueue/Queue.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.velocitypowered.api.proxy.server.RegisteredServer;
1111
import net.kyori.adventure.text.Component;
1212
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
13+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
1314
import net.kyori.adventure.title.Title;
1415

1516
import java.time.Duration;
@@ -73,6 +74,13 @@ public int getSize() {
7374
return playerQueue.size();
7475
}
7576

77+
/**
78+
* Converts Component to a plain string
79+
*/
80+
private String toPlainText(Component component) {
81+
return PlainTextComponentSerializer.plainText().serialize(component);
82+
}
83+
7684
/**
7785
* This event is fired before the player connects to a server.
7886
* Velocity will wait on this event to finish firing before initiating the connection.
@@ -95,7 +103,7 @@ public void onServerPreConnect(ServerPreConnectEvent event) {
95103
if (currentPlayers < Config.maxPlayers) {
96104
// Allow direct connection to target server
97105
event.setResult(ServerPreConnectEvent.ServerResult.allowed(serverTarget));
98-
log.info(mm("<white>" + event.getPlayer().getUsername() + "<dark_aqua> was directly connected to server <aqua>" + Config.target + "<dark_aqua>. Main count is " + (getSize() + 1) + " of " + Config.maxPlayers + "."));
106+
log.info(mm("<white>" + event.getPlayer().getUsername() + "<dark_aqua> was directly connected to server <aqua>" + Config.target + "<dark_aqua>. Main count is " + (serverTarget.getPlayersConnected().size() + 1) + " of " + Config.maxPlayers + "."));
99107
} else {
100108
// Notify player that server is full
101109
event.getPlayer().sendMessage(mm(Config.messageFull));
@@ -167,16 +175,26 @@ public void onPlayerDisconnect(DisconnectEvent event) {
167175
}
168176
}
169177

170-
171178
/**
172179
* Kick a player if kicking is allowed in the config
173180
*
174181
* @param player Player to kick
175182
* @param reason kicking reason from the target server
176183
*/
177184
private void KickOrRequeue(Player player, Component reason) {
178-
// is kicking enabled?
179-
if (!Config.kick) {
185+
String textReason = toPlainText(reason);
186+
187+
// Cancel the event, if one of the following:
188+
// - kicking is not enabled
189+
// - target is restarting (and restart kicks are disabled)
190+
// - target is busy with connecting players (and busy kicks are disabled)
191+
if (!Config.kickPassthrough
192+
|| (!Config.kickOnRestart && textReason.contains("Server is restarting")) // Restart
193+
|| (!Config.kickOnRestart && textReason.contains("Kicked without a reason.")) // Server went down
194+
|| (!Config.kickOnRestart && textReason.contains("Server closed")) // Server stopped
195+
|| (!Config.kickOnBusy && textReason.contains("Too many people logging in, retry soon.")) // NCP
196+
|| (!Config.kickOnBusy && textReason.contains("Too fast re-login, try with a little delay.")) // NCP
197+
) {
180198
// save the disconnection time
181199
kickedPlayers.put(player, Instant.now().getEpochSecond());
182200

src/main/resources/config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
target = "main"
22
queue = "queue"
3-
name = "0b0t"
43
max-players = 420
54
message-position = "<gold>Position in queue: <bold>%position%<reset>"
65
message-connecting = "<gold>Connecting to the server...<reset>"
76
message-full = "<red>Server is currently full!<reset>"
87
message-offline = "<red>Server is currently down!<reset>"
9-
kick = true
8+
kick-passthrough = true
9+
kick-on-restart = false
10+
kick-on-busy = false
1011
wait-on-kick = 16
1112
send-title = true
1213
bStats = true

0 commit comments

Comments
 (0)