Skip to content

Commit

Permalink
Reiterate queue system, strip showall command, reimplement resend whe…
Browse files Browse the repository at this point in the history
…n server returns online delay, enhance queue precision, allow users to swap queues without having to leave, and much, much more (#406)

Co-authored-by: BrianMay <[email protected]>
  • Loading branch information
R00tB33rMan and devnootnoot authored Jan 7, 2025
1 parent a9b0513 commit 77e078a
Show file tree
Hide file tree
Showing 48 changed files with 1,530 additions and 1,426 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ dependencies, useful performance improvements, and more.
* Configurable `/plist` command that displays the total users on your proxy
or from a defined proxy scope.
* The `/send` supports sending users from `{SERVER_FROM}` to `{SERVER_TO}`.
* Configurable `/showall` command that displays all users connected to a specific
instance rather than flooding your chat with users connected everywhere.
* Configurable `/transfer` command that allows you to move a player, "current" players,
a specific server, or all players from one proxy to another.
* Configurable `/velocity sudo` command to force users to execute a command on the
Expand Down Expand Up @@ -93,8 +91,6 @@ dependencies, useful performance improvements, and more.
connected to and not the latency of the backend server).
* `velocity.command.plist` [/plist] (Returns the total users on your proxy
or from a defined proxy scope).
* `velocity.command.showall` [/showall] (Shows all users connected to a specific server
on the proxy).
* `velocity.command.sudo` [/velocity sudo] (Allows you to run a message or a command
for a player).
* `velocity.command.transfer` [/transfer] (Allows you to transfer a player, "current" players,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public interface RegisteredServer extends ChannelMessageSink, Audience {
*/
Collection<Player> getPlayersConnected();

/**
* Get the total player count of the server (redis support).
*
* @return The total player count.
*/
long getTotalPlayerCount();

/**
* Returns a list of all the players currently connected to this server on all proxies
* or the current proxy, in case Redis is disabled.
Expand Down
18 changes: 11 additions & 7 deletions proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.velocitypowered.proxy.command.builtin.QueueAdminCommand;
import com.velocitypowered.proxy.command.builtin.SendCommand;
import com.velocitypowered.proxy.command.builtin.ServerCommand;
import com.velocitypowered.proxy.command.builtin.ShowAllCommand;
import com.velocitypowered.proxy.command.builtin.ShutdownCommand;
import com.velocitypowered.proxy.command.builtin.SlashServerCommand;
import com.velocitypowered.proxy.command.builtin.TransferCommand;
Expand Down Expand Up @@ -683,7 +682,6 @@ private void unregisterCommands() {
unregisterCommand("plist");
unregisterCommand("ping");
unregisterCommand("send");
unregisterCommand("showall");
unregisterCommand("hub");
unregisterCommand("lobby");
unregisterCommand("transfer");
Expand Down Expand Up @@ -730,10 +728,6 @@ private void registerCommands() {
new SendCommand(this).register(configuration.isSendEnabled());
}

if (!commandManager.hasCommand("showall")) {
new ShowAllCommand(this).register(configuration.isShowAllEnabled());
}

if (!commandManager.hasCommand("queueadmin")) {
new QueueAdminCommand(this).register(configuration.getQueue().isEnabled());
}
Expand Down Expand Up @@ -825,6 +819,12 @@ public void shutdown(final boolean explicitExit, final Component reason) {

ImmutableList<ConnectedPlayer> players = ImmutableList.copyOf(connectionsByUuid.values());

if (this.getQueueManager().isQueueEnabled()) {
players.forEach(p -> {
this.getQueueManager().removeFromAll(p);
});
}

if (!getConfiguration().isAcceptTransfers()) {
for (ConnectedPlayer player : players) {
player.disconnect(reason);
Expand All @@ -842,7 +842,7 @@ public void shutdown(final boolean explicitExit, final Component reason) {
if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20_5)) {
String connectedServer = player.getConnectedServer() != null ? player.getConnectedServer().getServerInfo().getName() : null;

if (this.getMultiProxyHandler().isEnabled()) {
if (this.getMultiProxyHandler().isRedisEnabled()) {
getRedisManager().send(new RedisPlayerSetTransferringRequest(player.getUniqueId(), true,
connectedServer));
}
Expand Down Expand Up @@ -936,6 +936,10 @@ public void shutdown() {
private ProxyAddress getProxyAddressToUse() {
final String filter = getConfiguration().getDynamicProxyFilter();
List<ProxyAddress> addresses = new ArrayList<>(getConfiguration().getProxyAddresses().stream().toList());
if (addresses.isEmpty()) {
return null;
}

if (getMultiProxyHandler().getOwnProxyId() != null) {
addresses.removeIf(address -> getMultiProxyHandler().getOwnProxyId().equalsIgnoreCase(address.proxyId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public static CompletableFuture<Suggestions> suggestPlayer(
? ctx.getArgument("player", String.class)
: "";

if (includeRemote && server.getMultiProxyHandler().isEnabled()) {
if (includeRemote && server.getMultiProxyHandler().isRedisEnabled()) {
for (RemotePlayerInfo info : server.getMultiProxyHandler().getAllPlayers()) {
if (info.getName().regionMatches(true, 0, argument, 0, argument.length())) {
builder.suggest(info.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private int alert(final CommandContext<CommandSource> context) {
return 0;
}

if (server.getMultiProxyHandler().isEnabled()) {
if (server.getMultiProxyHandler().isRedisEnabled()) {
server.getMultiProxyHandler().alert(Component.translatable("velocity.command.alert.message", NamedTextColor.WHITE,
ComponentUtils.colorify(message)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private int alert(final CommandContext<CommandSource> context) {
return 0;
}

if (server.getMultiProxyHandler().isEnabled()) {
if (server.getMultiProxyHandler().isRedisEnabled()) {
server.getMultiProxyHandler().alert(Component.translatable("velocity.command.alertraw.message", NamedTextColor.WHITE,
ComponentUtils.colorify(message)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void register(final boolean isFindEnabled) {
}

private int find(final CommandContext<CommandSource> context) {
if (server.getMultiProxyHandler().isEnabled()) {
if (server.getMultiProxyHandler().isRedisEnabled()) {
return findMultiProxy(context);
}

Expand Down Expand Up @@ -115,7 +115,7 @@ private int find(final CommandContext<CommandSource> context) {

private int findMultiProxy(final CommandContext<CommandSource> context) {
final String player = context.getArgument("player", String.class);
if (!server.getMultiProxyHandler().isPlayerOnline(player)) {
if (server.getMultiProxyHandler().isPlayerOnline(player)) {
context.getSource().sendMessage(
CommandMessages.PLAYER_NOT_FOUND.arguments(Component.text(player))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private int serverCount(final CommandContext<CommandSource> context) {
private void sendTotalProxyCount(final CommandSource target) {
final int online;

if (server.getMultiProxyHandler().isEnabled()) {
if (server.getMultiProxyHandler().isRedisEnabled()) {
online = server.getMultiProxyHandler().getTotalPlayerCount();
} else {
online = server.getPlayerCount();
Expand All @@ -151,7 +151,7 @@ private void sendServerPlayers(final CommandSource target,
List<Component> players = new ArrayList<>();
MultiProxyHandler multiProxyHandler = this.server.getMultiProxyHandler();

if (multiProxyHandler.isEnabled()) {
if (multiProxyHandler.isRedisEnabled()) {
for (String proxyId : multiProxyHandler.getAllProxyIds()) {
for (RemotePlayerInfo player : multiProxyHandler.getPlayers(proxyId)) {
if (player.getServerName() == null || !player.getServerName().equals(server.getServerInfo().getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private int lobby(final CommandContext<CommandSource> context) {
}

if (this.server.getConfiguration().getQueue().getNoQueueServers()
.contains(serverToTry.getServerInfo().getName()) || !server.getMultiProxyHandler().isEnabled()
.contains(serverToTry.getServerInfo().getName()) || !server.getMultiProxyHandler().isRedisEnabled()
|| player.hasPermission("velocity.queue.bypass")) {
player.createConnectionRequest(serverToTry).connectWithIndication();
return Command.SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import com.velocitypowered.proxy.command.VelocityCommands;
import com.velocitypowered.proxy.plugin.virtual.VelocityVirtualPlugin;
import com.velocitypowered.proxy.queue.ServerQueueStatus;
import com.velocitypowered.proxy.redis.multiproxy.RedisQueueLeaveRequest;
import com.velocitypowered.proxy.redis.multiproxy.RemotePlayerInfo;
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import java.util.List;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -68,7 +66,7 @@ public void register(final boolean isQueueEnabled) {
.suggests(VelocityCommands.suggestServer(server, "server", false))
.executes(this::leaveQueue)
)
.executes(this::leaveAllQueues);
.executes(this::leaveAllQueuesNoRedis);

final BrigadierCommand command = new BrigadierCommand(rootNode);
server.getCommandManager().register(
Expand All @@ -80,33 +78,6 @@ public void register(final boolean isQueueEnabled) {
);
}

private int leaveAllQueues(final CommandContext<CommandSource> ctx) {
if (ctx.getSource() instanceof Player player) {

if (!this.server.getMultiProxyHandler().isEnabled()) {
return leaveAllQueuesNoRedis(ctx);
}

RemotePlayerInfo info = this.server.getMultiProxyHandler().getPlayerInfo(player.getUniqueId());
if (info != null && info.getQueuedServer() == null) {
ctx.getSource().sendMessage(Component.translatable("velocity.queue.error.not-in-queue.all"));
return -1;
}

for (RegisteredServer server : this.server.getAllServers()) {
this.server.getRedisManager().send(new RedisQueueLeaveRequest(player.getUniqueId(),
server.getServerInfo().getName(), false));
}

player.sendMessage(Component.translatable("velocity.queue.command.left-queue.all"));

return Command.SINGLE_SUCCESS;
} else {
ctx.getSource().sendMessage(CommandMessages.PLAYERS_ONLY);
return -1;
}
}

private int leaveAllQueuesNoRedis(final CommandContext<CommandSource> ctx) {
if (ctx.getSource() instanceof Player p) {
int amountDone = 0;
Expand All @@ -132,7 +103,7 @@ private int leaveAllQueuesNoRedis(final CommandContext<CommandSource> ctx) {
}

private int leaveQueue(final CommandContext<CommandSource> ctx) {
if (!this.server.getMultiProxyHandler().isEnabled()) {
if (!this.server.getMultiProxyHandler().isRedisEnabled()) {
return leaveQueueNoRedis(ctx);
}

Expand All @@ -142,8 +113,7 @@ private int leaveQueue(final CommandContext<CommandSource> ctx) {
}

if (ctx.getSource() instanceof Player player) {
this.server.getRedisManager().send(new RedisQueueLeaveRequest(player.getUniqueId(),
server.getServerInfo().getName(), true));
this.server.getQueueManager().getQueue(server.getServerInfo().getName()).dequeue(player.getUniqueId(), false);
} else {
ctx.getSource().sendMessage(CommandMessages.PLAYERS_ONLY);
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private int getPing(final CommandContext<CommandSource> context, final String us
.arguments(Component.text(ping))
);
} else {
if (server.getMultiProxyHandler().isEnabled()) {
if (!this.server.getMultiProxyHandler().isPlayerOnline(username)) {
if (server.getMultiProxyHandler().isRedisEnabled()) {
if (this.server.getMultiProxyHandler().isPlayerOnline(username)) {
context.getSource().sendMessage(Component.translatable("velocity.command.player-not-found")
.arguments(Component.text(username)));
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public PlistCommand(final VelocityServer server) {
* Registers this command.
*/
public void register(final boolean isPlistEnabled) {
if (!isPlistEnabled || !server.getMultiProxyHandler().isEnabled()) {
if (!isPlistEnabled || !server.getMultiProxyHandler().isRedisEnabled()) {
return;
}

Expand Down
Loading

0 comments on commit 77e078a

Please sign in to comment.