Fix priority selection not playing nicely with reconnect handlers.

This commit is contained in:
md_5 2016-03-01 12:34:50 +11:00
parent 04a6eff14c
commit dd66e3068a
2 changed files with 27 additions and 27 deletions

View File

@ -240,6 +240,7 @@ public class ServerConnector extends PacketHandler
// TODO: Move this to the connected() method of DownstreamBridge // TODO: Move this to the connected() method of DownstreamBridge
target.addPlayer( user ); target.addPlayer( user );
user.getPendingConnects().remove( target ); user.getPendingConnects().remove( target );
user.setServerJoinQueue( null );
user.setDimensionChange( false ); user.setDimensionChange( false );
user.setServer( server ); user.setServer( server );
@ -261,18 +262,7 @@ public class ServerConnector extends PacketHandler
@Override @Override
public void handle(Kick kick) throws Exception public void handle(Kick kick) throws Exception
{ {
user.setLastServerJoined( user.getLastServerJoined() + 1 ); ServerInfo def = user.updateAndGetNextServer( target );
String serverName = "";
List<String> servers = user.getPendingConnection().getListener().getServerPriority();
if ( user.getLastServerJoined() < servers.size() )
{
serverName = servers.get( user.getLastServerJoined() );
}
ServerInfo def = ProxyServer.getInstance().getServers().get( serverName );
if ( Objects.equal( target, def ) )
{
def = null;
}
ServerKickEvent event = new ServerKickEvent( user, target, ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTING ); ServerKickEvent event = new ServerKickEvent( user, target, ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTING );
if ( event.getKickReason().toLowerCase().contains( "outdated" ) && def != null ) if ( event.getKickReason().toLowerCase().contains( "outdated" ) && def != null )
{ {

View File

@ -14,9 +14,11 @@ import java.net.InetSocketAddress;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Queue;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@ -106,9 +108,8 @@ public final class UserConnection implements ProxiedPlayer
@Getter @Getter
private int compressionThreshold = -1; private int compressionThreshold = -1;
// Used for trying multiple servers in order // Used for trying multiple servers in order
@Getter
@Setter @Setter
private int lastServerJoined = 0; private Queue<String> serverJoinQueue;
/*========================================================================*/ /*========================================================================*/
private final Collection<String> groups = new CaseInsensitiveSet(); private final Collection<String> groups = new CaseInsensitiveSet();
private final Collection<String> permissions = new CaseInsensitiveSet(); private final Collection<String> permissions = new CaseInsensitiveSet();
@ -222,6 +223,26 @@ public final class UserConnection implements ProxiedPlayer
connect( target ); connect( target );
} }
public ServerInfo updateAndGetNextServer(ServerInfo currentTarget)
{
if ( serverJoinQueue == null )
{
serverJoinQueue = new LinkedList<>( getPendingConnection().getListener().getServerPriority() );
}
ServerInfo next = null;
while ( !serverJoinQueue.isEmpty() )
{
ServerInfo candidate = ProxyServer.getInstance().getServerInfo( serverJoinQueue.remove() );
if ( !Objects.equal( currentTarget, candidate ) )
{
next = candidate;
}
}
return next;
}
public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry) public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry)
{ {
Preconditions.checkNotNull( info, "info" ); Preconditions.checkNotNull( info, "info" );
@ -274,16 +295,8 @@ public final class UserConnection implements ProxiedPlayer
future.channel().close(); future.channel().close();
pendingConnects.remove( target ); pendingConnects.remove( target );
lastServerJoined++; ServerInfo def = updateAndGetNextServer( target );
String serverName = ""; if ( retry && def != null && ( getServer() == null || def != getServer().getInfo() ) )
List<String> servers = getPendingConnection().getListener().getServerPriority();
if ( lastServerJoined < servers.size() )
{
serverName = servers.get( lastServerJoined );
}
ServerInfo def = ProxyServer.getInstance().getServers().get( serverName );
if ( retry && def != null && target != def && ( getServer() == null || def != getServer().getInfo() ) )
{ {
sendMessage( bungee.getTranslation( "fallback_lobby" ) ); sendMessage( bungee.getTranslation( "fallback_lobby" ) );
connect( def, null, false ); connect( def, null, false );
@ -294,9 +307,6 @@ public final class UserConnection implements ProxiedPlayer
{ {
sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) ); sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
} }
} else
{
lastServerJoined = 0;
} }
} }
}; };