Skip to content

Commit 6f029c8

Browse files
reimplemented passthrough when the queue is empty and the server not full
1 parent a6d37b2 commit 6f029c8

File tree

7 files changed

+92
-31
lines changed

7 files changed

+92
-31
lines changed

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ tasks {
7373
runDirectory = layout.projectDirectory.dir('run').dir('proxy')
7474
velocityVersion("${project.velocity_api_version}")
7575
dependsOn('build')
76+
downloadPlugins {
77+
url("https://github.com/ViaVersion/ViaBackwards/releases/download/5.3.2/ViaBackwards-5.3.2.jar")
78+
url("https://github.com/ViaVersion/ViaVersion/releases/download/5.3.2/ViaVersion-5.3.2.jar")
79+
}
7680
}
7781
}
7882

@@ -90,8 +94,8 @@ tasks.register('runServerQueue', runServer.getClass() as Class<Task>) {
9094
systemProperty('Paper.skipServerPropertiesComments', 'true')
9195
runDirectory = layout.projectDirectory.dir('run').dir('queue')
9296
downloadPlugins {
93-
github("zeroBzeroT", "QueueServerPlugin", "3.0.0-SNAPSHOT", "queueplugin-3.0.0-SNAPSHOT+1.20.6-paper.jar")
94-
url("https://ci.dmulloy2.net/job/ProtocolLib/723/artifact/build/libs/ProtocolLib.jar")
97+
github("zeroBzeroT", "QueuePlugin", "v3.0.1", "QueuePlugin-3.0.1+1.21-paper.jar")
98+
url("https://github.com/dmulloy2/ProtocolLib/releases/download/5.3.0/ProtocolLib.jar")
9599
}
96100
dependsOn('build')
97101
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
plugin_version=3.0.10
1+
plugin_version=3.0.11
22
velocity_api_version=3.4.0-SNAPSHOT
33
minecraft_version=1.20.6

run/main/server.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
accepts-transfers=false
24
allow-flight=true
35
allow-nether=false

run/proxy/velocity.toml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Config version. Do not change this
22
config-version = "2.7"
33

4-
# What port should the proxy be bound to? By default, we'll bind to all addresses on port 25577.
4+
# What port should the proxy be bound to? By default, we'll bind to all addresses on port 25565.
55
bind = "0.0.0.0:25565"
66

77
# What should be the MOTD? This gets displayed when the player adds your server to
88
# their server list. Only MiniMessage format is accepted.
9-
motd = "<#09add3>A Velocity Server"
9+
#motd = "<dark_gray><i><b>0B</b></i></dark_gray> <dark_red>0B</dark_red><blue>0T</blue><green>.ORG</green><newline><dark_gray><i><b>0T</b></i></dark_gray> <gold>Aloha snackbar!</gold>"
10+
motd = "<dark_gray><i><b>0B</b></i></dark_gray> <dark_red>0B</dark_red><blue>0T</blue><green>.ORG</green><newline><dark_gray><i><b>0T</b></i></dark_gray> <gold>You will be baked, and then there will be cake.</gold>"
1011

1112
# What should we display for the maximum number of players? (Velocity does not support a cap
1213
# on the number of players online.)
13-
show-max-players = 500
14+
show-max-players = 1337
1415

1516
# Should we authenticate players with Mojang? By default, this is on.
1617
online-mode = true
@@ -34,15 +35,15 @@ prevent-client-proxy-connections = false
3435
# unable to implement network level firewalling (on a shared host).
3536
# - "modern": Forward player IPs and UUIDs as part of the login process using
3637
# Velocity's native forwarding. Only applicable for Minecraft 1.13 or higher.
37-
player-info-forwarding-mode = "MODERN"
38+
player-info-forwarding-mode = "modern"
3839

3940
# If you are using modern or BungeeGuard IP forwarding, configure a file that contains a unique secret here.
4041
# The file is expected to be UTF-8 encoded and not empty.
4142
forwarding-secret-file = "forwarding.secret"
4243

43-
# Announce whether your server supports Forge. If you run a modded server, we
44+
# Announce whether or not your server supports Forge. If you run a modded server, we
4445
# suggest turning this on.
45-
#
46+
#
4647
# If your network runs one modpack consistently, consider using ping-passthrough = "mods"
4748
# instead for a nicer display in the server list.
4849
announce-forge = false
@@ -64,30 +65,46 @@ kick-existing-players = false
6465
# description and mod list.
6566
# - "all": Uses the backend server's response as the proxy response. The Velocity
6667
# configuration is used if no servers could be contacted.
67-
ping-passthrough = "DISABLED"
68+
ping-passthrough = "mods"
6869

6970
# If not enabled (default is true) player IP addresses will be replaced by <ip address withheld> in logs
70-
enable-player-address-logging = true
71+
enable-player-address-logging = false
7172

7273
[servers]
7374
# Configure your servers here. Each key represents the server's name, and the value
7475
# represents the IP address of the server to connect to.
7576
main = "127.0.0.1:25567"
7677
queue = "127.0.0.1:25566"
78+
test = "127.0.0.1:9200"
79+
temp = "127.0.0.1:9300"
7780

7881
# In what order we should try servers when a player logs in or is kicked from a server.
7982
try = [
80-
"main",
81-
"queue"
83+
"queue"
8284
]
8385

8486
[forced-hosts]
85-
87+
# Configure your forced hosts here.
88+
"0b0t.org" = [
89+
"queue"
90+
]
91+
"0b0t.net" = [
92+
"queue"
93+
]
94+
"shield.0b0t.org" = [
95+
"queue"
96+
]
97+
"test.0b0t.org" = [
98+
"test"
99+
]
100+
"temp.0b0t.org" = [
101+
"temp"
102+
]
86103

87104
[advanced]
88105
# How large a Minecraft packet has to be before we compress it. Setting this to zero will
89106
# compress all packets, and setting it to -1 will disable compression entirely.
90-
compression-threshold = 256
107+
compression-threshold = 512
91108

92109
# How much compression should be done (from 0-9). The default is -1, which uses the
93110
# default level of 6.
@@ -108,7 +125,7 @@ read-timeout = 30000
108125
haproxy-protocol = false
109126

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

113130
# Enables BungeeCord plugin messaging channel support on Velocity.
114131
bungee-plugin-message-channel = true
@@ -123,29 +140,28 @@ show-ping-requests = false
123140
failover-on-unexpected-server-disconnect = true
124141

125142
# Declares the proxy commands to 1.13+ clients.
126-
announce-proxy-commands = true
143+
announce-proxy-commands = false
127144

128145
# Enables the logging of commands
129146
log-command-executions = false
130147

131148
# Enables logging of player connections when connecting to the proxy, switching servers
132149
# and disconnecting from the proxy.
133-
log-player-connections = true
150+
log-player-connections = false
134151

135152
# Allows players transferred from other hosts via the
136153
# Transfer packet (Minecraft 1.20.5) to be received.
137-
# TODO: is this required by something we use?
138154
accepts-transfers = false
139155

140156
[query]
141157
# Whether to enable responding to GameSpy 4 query responses or not.
142158
enabled = false
143159

144160
# If query is enabled, on what port should the query protocol listen on?
145-
port = 25577
161+
port = 25575
146162

147163
# This is the map name that is reported to the query services.
148-
map = "Velocity"
164+
map = "Zerocity"
149165

150166
# Whether plugins should be shown in query response by default or not
151167
show-plugins = false

run/queue/server.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
accepts-transfers=false
24
allow-flight=true
35
allow-nether=false

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public class Config {
2121

2222
public static String messageConnecting = null;
2323

24-
public static String messageFull = null; // TODO: not in use, implement or remove this
24+
public static String messageFull = null;
2525

26-
public static String messageOffline = null; // TODO: not in use, implement or remove this
26+
public static String messageOffline = null;
2727

2828
public static boolean kick = true;
2929

@@ -66,7 +66,7 @@ static void loadConfig(Path path) throws IOException {
6666
messagePosition = toml.getString("message-position", "Position in queue: ");
6767
messageConnecting = toml.getString("message-connecting", "Connecting to the server...");
6868
messageFull = toml.getString("message-full", "Server is currently full!");
69-
messageOffline = toml.getString("message-offline", "Server is currently down!");
69+
messageOffline = toml.getString("message-offline", "Server is currently offline!");
7070
kick = toml.getBoolean("kick", true);
7171
waitOnKick = toml.getLong("wait-on-kick", 16L).intValue();
7272
sendTitle = toml.getBoolean("send-title", true);

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.velocitypowered.api.event.connection.DisconnectEvent;
55
import com.velocitypowered.api.event.player.KickedFromServerEvent;
66
import com.velocitypowered.api.event.player.ServerConnectedEvent;
7+
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
78
import com.velocitypowered.api.proxy.Player;
89
import com.velocitypowered.api.proxy.ProxyServer;
910
import com.velocitypowered.api.proxy.server.RegisteredServer;
@@ -21,7 +22,6 @@
2122

2223
// velocity api event docs:
2324
// https://jd.papermc.io/velocity/3.3.0/com/velocitypowered/api/event/package-summary.html
24-
// TODO: direct connection to the main server if the queue is empty
2525
// TODO: replace player objects with uuids
2626

2727
public class Queue {
@@ -73,6 +73,40 @@ public int getSize() {
7373
return playerQueue.size();
7474
}
7575

76+
/**
77+
* This event is fired before the player connects to a server.
78+
* Velocity will wait on this event to finish firing before initiating the connection.
79+
*/
80+
@Subscribe
81+
public void onServerPreConnect(ServerPreConnectEvent event) {
82+
// Check if it's a "fresh" connection
83+
if (event.getPreviousServer() != null)
84+
return;
85+
86+
// Check if player is connecting to the queue server
87+
if (getSize() == 0 && event.getOriginalServer().getServerInfo().getName().equals(Config.queue)) {
88+
// If queue is empty, attempt passthrough
89+
try {
90+
// Check target server reachability
91+
RegisteredServer serverTarget = getServer(Config.target);
92+
int currentPlayers = serverTarget.getPlayersConnected().size();
93+
94+
// Check if target server is not full
95+
if (currentPlayers < Config.maxPlayers) {
96+
// Allow direct connection to target server
97+
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 + "."));
99+
} else {
100+
// Notify player that server is full
101+
event.getPlayer().sendMessage(mm(Config.messageFull));
102+
}
103+
} catch (ServerNotReachableException e) {
104+
// Target server offline or unreachable, proceed with queue and notify the player
105+
event.getPlayer().sendMessage(mm(Config.messageOffline));
106+
}
107+
}
108+
}
109+
76110
/**
77111
* This event is fired once the player has successfully connected to the
78112
* target server and the connection to the previous server has been de-established.
@@ -109,7 +143,6 @@ public void onKickedFromServer(KickedFromServerEvent event) {
109143
try {
110144
Player player = event.getPlayer();
111145
Component reason = event.getServerKickReason().isPresent() ? event.getServerKickReason().get() : mm("Kicked without a reason.");
112-
113146
KickOrRequeue(player, reason);
114147
} catch (Exception e) {
115148
log.error(e.getMessage());
@@ -183,13 +216,13 @@ public void flushQueue() {
183216
try {
184217
serverMain = getServer(Config.target);
185218
} catch (ServerNotReachableException e) {
186-
// TODO: offline notification
219+
// offline notification handled by onServerPreConnect
187220
return;
188221
}
189222

190223
// check main server full
191224
if (serverMain.getPlayersConnected().size() >= Config.maxPlayers)
192-
// TODO: full notification
225+
// full notification handled by onServerPreConnect
193226
return;
194227

195228
lock.lock();
@@ -300,12 +333,16 @@ private RegisteredServer getServer(String name) throws ServerNotReachableExcepti
300333
*/
301334
public void sendTitle(Player player, Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
302335
try {
336+
// Convert ticks to milliseconds (1 tick = 50 ms)
303337
Title bungeeTitle = Title.title(
304338
title,
305339
subtitle,
306-
Title.Times.times(Duration.ofMillis(fadeIn * 20L),
307-
Duration.ofMillis(stay * 20L),
308-
Duration.ofMillis(fadeOut * 20L)));
340+
Title.Times.times(
341+
Duration.ofMillis(fadeIn * 50L),
342+
Duration.ofMillis(stay * 50L),
343+
Duration.ofMillis(fadeOut * 50L)
344+
)
345+
);
309346
player.showTitle(bungeeTitle);
310347
} catch (Exception e) {
311348
log.error(mm("<red>Could not send title to <white>" + player.getUsername() + "<red>: " + e.getMessage()));

0 commit comments

Comments
 (0)