Skip to content

Commit

Permalink
Resolve obscure server links reload issue when outside of CONFIGURATI…
Browse files Browse the repository at this point in the history
…ON or PLAY state, allow Bungee messaging channel to discern non-queueable servers, resolve NPEs with adding users to queue in rare conditions, add handler for no available fallbacks, and raise default max concurrent connections
  • Loading branch information
R00tB33rMan authored Dec 17, 2024
1 parent f652441 commit c080c93
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.network.ProtocolState;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription;
Expand Down Expand Up @@ -650,7 +651,13 @@ public boolean reloadConfiguration() throws IOException {
if (!this.getConfiguration().getServerLinks().isEmpty()) {
for (Player player : this.getAllPlayers()) {
if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21)) {
player.setServerLinks(getConfiguration().getServerLinks());
try {
if (player.getProtocolState() == ProtocolState.CONFIGURATION || player.getProtocolState() == ProtocolState.PLAY) {
player.setServerLinks(getConfiguration().getServerLinks());
}
} catch (IllegalStateException ignored) {
// Ignore illegal state to ensure each reload is successful.
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ private int lobby(final CommandContext<CommandSource> context) {

RegisteredServer serverToTry = p.getNextServerToTry().orElse(null);
if (serverToTry == null) {
player.sendMessage(Component.translatable("velocity.command.no-fallbacks"));
return 0;
}

if (translationExists("velocity.command.hub.fallback-connecting", player)) {
if (translationExists(player)) {
player.sendMessage(Component.translatable("velocity.command.hub.fallback-connecting")
.arguments(Component.text(serverToTry.getServerInfo().getName())));
}
Expand All @@ -113,14 +114,14 @@ private int lobby(final CommandContext<CommandSource> context) {
return 0;
}

private static boolean translationExists(final String key, final Player player) {
private static boolean translationExists(final Player player) {
Locale locale = player.getEffectiveLocale();

if (locale == null) {
locale = Locale.ENGLISH;
}

Component format = GlobalTranslator.translator().translate(Component.translatable(key), locale);
Component format = GlobalTranslator.translator().translate(Component.translatable("velocity.command.hub.fallback-connecting"), locale);
return format != null && !format.equals(Component.empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ private void sendPlayersFromServer(final CommandContext<CommandSource> context,
Component.text(targetServer.getServerInfo().getName())));
}


private int sendMultiProxy(final CommandContext<CommandSource> context) {
final String serverName = context.getArgument(SERVER_ARG, String.class);
final String player = context.getArgument(PLAYER_ARG, String.class);
Expand Down Expand Up @@ -416,6 +415,7 @@ private int sendMultiProxy(final CommandContext<CommandSource> context) {
}

if (player.startsWith("+")) {

final ServerResult result = findServer(player.substring(1));

if (result.bestMatch().isEmpty()) {
Expand Down Expand Up @@ -495,6 +495,7 @@ private ServerResult findServer(final String serverName) {
boolean multipleMatches = false;

for (RegisteredServer server : servers) {

final String lowerName = server.getServerInfo().getName().toLowerCase();

if (lowerName.equals(lowerServerName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ private void processConnect(final ByteBufDataInput in, final boolean queue) {

proxy.getServer(serverName).ifPresent(server -> {
if (queue && proxy.getQueueManager().isEnabled()) {
if (this.proxy.getConfiguration().getQueue().getNoQueueServers().contains(server.getServerInfo().getName())) {
player.createConnectionRequest(server).connectWithIndication();
return;
}
if (player.hasPermission("velocity.queue.bypass")) {
player.createConnectionRequest(server).connectWithIndication();
} else {
Expand All @@ -113,6 +117,11 @@ private void processConnectOther(final ByteBufDataInput in, final boolean queue)
}

if (queue && proxy.getQueueManager().isEnabled()) {
if (this.proxy.getConfiguration().getQueue().getNoQueueServers().contains(referencedServer.get().getServerInfo().getName())) {
player.createConnectionRequest(referencedServer.get()).connectWithIndication();
return;
}

if (!referencedPlayer.get().hasPermission("velocity.queue.bypass")) {
proxy.getQueueManager().queue(player, (VelocityRegisteredServer) referencedServer.get());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ public void tickMessageForAllPlayers() {

for (Player player : temp.keySet()) {
ServerQueueStatus status = temp.get(player);
ServerQueueEntry entry = status.getEntry(player.getUniqueId()).orElse(null);
if (entry != null) {
player.sendActionBar(temp.get(player).getActionBarComponent(entry));
}
status.getEntry(player.getUniqueId()).ifPresent(entry -> player.sendActionBar(temp.get(player).getActionBarComponent(entry)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.velocitypowered.proxy.redis.multiproxy.RedisQueueSendStatusRequest;
import com.velocitypowered.proxy.redis.multiproxy.RedisSendActionBarRequest;
import com.velocitypowered.proxy.redis.multiproxy.RedisSendMessageToUuidRequest;
import com.velocitypowered.proxy.redis.multiproxy.RemotePlayerInfo;
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -283,11 +284,11 @@ public void queue(final Player player, final VelocityRegisteredServer server) {
}

if (!this.server.getConfiguration().getQueue().isAllowMultiQueue()) {
for (ServerQueueStatus status : this.serverQueues.values()) {
if (status.isQueued(player.getUniqueId())) {
player.sendMessage(Component.translatable("velocity.queue.error.multi-queue"));
return;
}
RemotePlayerInfo info = this.server.getMultiProxyHandler().getPlayerInfo(player.getUniqueId());

if (info != null && info.getQueuedServer() != null) {
player.sendMessage(Component.translatable("velocity.queue.error.multi-queue"));
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ public void queue(final UUID playerUuid, final int priority, final boolean fullB

if (this.velocityServer.getMultiProxyHandler().isEnabled()) {
RemotePlayerInfo info = this.velocityServer.getMultiProxyHandler().getPlayerInfo(playerUuid);
info.setQueuedServer(this.server.getServerInfo().getName());
this.velocityServer.getRedisManager().addOrUpdatePlayer(info);
if (info != null) {
info.setQueuedServer(this.server.getServerInfo().getName());
this.velocityServer.getRedisManager().addOrUpdatePlayer(info);
}
}

synchronized (queue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ private void registerListeners(final VelocityServer proxy) {
}).delay(1, TimeUnit.SECONDS).schedule();
});

listen(RedisSwitchServerRequest.ID, RedisSwitchServerRequest.class, it -> {
proxy.getPlayer(it.username()).ifPresent(player -> {
proxy.getServer(it.server()).ifPresent(server -> {
player.createConnectionRequest(server).connectWithIndication();
});
});
});
listen(RedisSwitchServerRequest.ID, RedisSwitchServerRequest.class, it
-> proxy.getPlayer(it.username()).ifPresent(player
-> proxy.getServer(it.server()).ifPresent(server
-> player.createConnectionRequest(server).connectWithIndication())));
}

/**
Expand Down Expand Up @@ -258,6 +255,10 @@ public void addOrUpdatePlayer(final RemotePlayerInfo player) {
String json = gson.toJson(player);

try (Jedis jedis = this.jedisPool.getResource()) {
if (!"hash".equals(jedis.type(CACHE_KEY))) {
jedis.del(CACHE_KEY);
}

jedis.hset(CACHE_KEY, player.getUuid().toString(), json);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ velocity.command.generic-error=<red>An error occurred while running this command
velocity.command.command-does-not-exist=<red>This command does not exist.
velocity.command.players-only=<red>Only players can run this command.
velocity.command.server-does-not-exist=<red>The specified server <arg:0> does not exist.
velocity.command.no-fallbacks=<red>You do not have access to any fallback servers.
velocity.command.server-multiple-matches=<red>Multiple servers matched the query. Please be more specific.
velocity.command.player-not-found=<red>The specified player <arg:0> does not exist or is currently offline.
velocity.command.server-current-server=<yellow>You are currently connected to <arg:0>.
Expand Down
4 changes: 2 additions & 2 deletions proxy/src/main/resources/default-velocity.toml
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ use-ssl = false

# Maximum number of maintained connections to the Redis server.
#
# We encourage leaving this at "10," as having an absurd number
# We encourage leaving this at "50," as having an absurd number
# of connections to your Redis instance will massively depreciate performance.
max-concurrent-connections = 10
max-concurrent-connections = 50

# The ID of this proxy and is only needed for multi-proxy setups.
# Leave blank if you do not use Redis and is left blank by
Expand Down

0 comments on commit c080c93

Please sign in to comment.