6666import com .velocitypowered .proxy .connection .player .resourcepack .VelocityResourcePackInfo ;
6767import com .velocitypowered .proxy .connection .player .resourcepack .handler .ResourcePackHandler ;
6868import com .velocitypowered .proxy .connection .util .ConnectionMessages ;
69- import com .velocitypowered .proxy .connection .util .ConnectionRequestResults ;
7069import com .velocitypowered .proxy .connection .util .ConnectionRequestResults .Impl ;
7170import com .velocitypowered .proxy .connection .util .VelocityInboundConnection ;
7271import com .velocitypowered .proxy .protocol .StateRegistry ;
106105import io .netty .buffer .Unpooled ;
107106import java .net .InetSocketAddress ;
108107import java .util .Collection ;
109- import java .util .Collections ;
110108import java .util .HashSet ;
111109import java .util .List ;
112110import java .util .Locale ;
111+ import java .util .Map ;
113112import java .util .Optional ;
114113import java .util .Set ;
115114import java .util .UUID ;
@@ -195,7 +194,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
195194 private @ MonotonicNonNull List <String > serversToTry = null ;
196195 private final ResourcePackHandler resourcePackHandler ;
197196 private final BundleDelimiterHandler bundleHandler = new BundleDelimiterHandler (this );
198- private boolean connectionInProgress ;
199197 private boolean dontRemoveFromRedis ;
200198 private @ Nullable String clientBrand ;
201199 private @ Nullable Locale effectiveLocale ;
@@ -750,8 +748,12 @@ public void handleConnectionException(final RegisteredServer server, final Throw
750748 friendlyError = Component .translatable ("velocity.error.connected-server-error" ,
751749 Component .text (server .getServerInfo ().getName ()));
752750 } else {
753- logger .error ("{}: unable to connect to server {}" , this , server .getServerInfo ().getName (),
754- wrapped );
751+ if (Boolean .getBoolean ("velocity.suppress-connection-timeout-logs" )) {
752+ logger .error ("{}: unable to connect to server {}" , this , server .getServerInfo ().getName ());
753+ } else {
754+ logger .error ("{}: unable to connect to server {}" , this , server .getServerInfo ().getName (),
755+ wrapped );
756+ }
755757 friendlyError = Component .translatable ("velocity.error.connecting-server-error" ,
756758 Component .text (server .getServerInfo ().getName ()));
757759 }
@@ -945,20 +947,24 @@ public Optional<RegisteredServer> getNextServerToTry() {
945947 * @return the next server to try
946948 */
947949 private Optional <RegisteredServer > getNextServerToTry (@ Nullable final RegisteredServer current ) {
948- if (serversToTry == null ) {
950+ if (serversToTry == null || serversToTry . isEmpty () ) {
949951 String virtualHostStr = getVirtualHost ().map (InetSocketAddress ::getHostString )
950952 .orElse ("" )
951953 .toLowerCase (Locale .ROOT );
952- serversToTry = server .getConfiguration ().getForcedHosts ().getOrDefault (virtualHostStr ,
953- Collections .emptyList ());
954- }
955954
956- if (serversToTry .isEmpty ()) {
957- List <String > connOrder = server .getConfiguration ().getAttemptConnectionOrder ();
958- if (connOrder .isEmpty ()) {
959- return Optional .empty ();
960- } else {
961- serversToTry = connOrder ;
955+ serversToTry = server .getConfiguration ().getForcedHosts ().get (virtualHostStr );
956+ if (serversToTry == null || serversToTry .isEmpty ()) {
957+ for (Map .Entry <String , List <String >> entry : server .getConfiguration ().getForcedHosts ().entrySet ()) {
958+ String pattern = entry .getKey ().toLowerCase (Locale .ROOT );
959+ if (pattern .startsWith ("*." ) && virtualHostStr .endsWith (pattern .substring (1 ))) {
960+ serversToTry = entry .getValue ();
961+ break ;
962+ }
963+ }
964+ }
965+
966+ if (serversToTry == null || serversToTry .isEmpty ()) {
967+ serversToTry = server .getConfiguration ().getAttemptConnectionOrder ();
962968 }
963969 }
964970
@@ -982,20 +988,20 @@ private Optional<RegisteredServer> getNextServerToTry(@Nullable final Registered
982988
983989 if (selectedServer .isEmpty ()) {
984990 if (strategy .equalsIgnoreCase ("FIRST_AVAILABLE" )) {
985- tryIndex = i + 1 ;
991+ tryIndex = i ;
986992 return Optional .of (registeredServer );
987993 }
988994 selectedServer = Optional .of (registeredServer );
989- tryIndex = i + 1 ;
995+ tryIndex = i ;
990996 } else if (strategy .equalsIgnoreCase ("MOST_POPULATED" )) {
991997 if (registeredServer .getTotalPlayerCount () > selectedServer .get ().getTotalPlayerCount ()) {
992998 selectedServer = Optional .of (registeredServer );
993- tryIndex = i + 1 ;
999+ tryIndex = i ;
9941000 }
9951001 } else if (strategy .equalsIgnoreCase ("LEAST_POPULATED" )) {
9961002 if (registeredServer .getTotalPlayerCount () < selectedServer .get ().getTotalPlayerCount ()) {
9971003 selectedServer = Optional .of (registeredServer );
998- tryIndex = i + 1 ;
1004+ tryIndex = i ;
9991005 }
10001006 }
10011007 }
@@ -1576,11 +1582,6 @@ private void resetIfInFlightIs(final VelocityServerConnection establishedConnect
15761582
15771583 @Override
15781584 public CompletableFuture<Result> connect() {
1579- if (connectionInProgress) {
1580- return completedFuture(ConnectionRequestResults.plainResult(Status.CONNECTION_CANCELLED, toConnect));
1581- }
1582-
1583- connectionInProgress = true;
15841585 return this.internalConnect().whenCompleteAsync((status, throwable) -> {
15851586 if (status != null && !status.isSuccessful()) {
15861587 if (!status.isSafe()) {
@@ -1603,22 +1604,11 @@ public CompletableFuture<Result> connect() {
16031604 }
16041605 }
16051606 }
1606-
1607- connectionInProgress = false;
1608- }, connection.eventLoop())
1609- .exceptionally((ex) -> {
1610- connectionInProgress = false;
1611- return null;
1612- }).thenApply(x -> x);
1607+ }, connection.eventLoop()).thenApply(x -> x);
16131608 }
16141609
16151610 @Override
16161611 public CompletableFuture<Boolean> connectWithIndication() {
1617- if (connectionInProgress) {
1618- return completedFuture(false);
1619- }
1620-
1621- connectionInProgress = true;
16221612 return internalConnect().whenCompleteAsync((status, throwable) -> {
16231613 if (throwable != null) {
16241614 // TODO: The exception handling from this is not very good. Find a better way.
@@ -1649,19 +1639,13 @@ public CompletableFuture<Boolean> connectWithIndication() {
16491639 }
16501640 }
16511641 default -> {
1652- // The only remaining value is successful (no need to do anything!)
1642+ // In this case, the default handler removes the user on server switch.
16531643 if (server.getConfiguration().getQueue().isRemovePlayerOnServerSwitch()) {
16541644 server.getQueueManager().removeFromAll(get());
16551645 }
16561646 }
16571647 }
1658-
1659- connectionInProgress = false;
1660- }, connection.eventLoop())
1661- .exceptionally((ex) -> {
1662- connectionInProgress = false;
1663- return null;
1664- }).thenApply(Result::isSuccessful);
1648+ }, connection.eventLoop()).thenApply(Result::isSuccessful);
16651649 }
16661650
16671651 @Override
0 commit comments