Handle removed servers in reconnect

This commit is contained in:
md_5 2013-03-02 19:26:19 +11:00
parent 385699380f
commit 317f286789
3 changed files with 22 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.api;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public interface ReconnectHandler
@ -9,9 +10,9 @@ public interface ReconnectHandler
* Gets the initial server name for a connecting player.
*
* @param player the connecting player
* @return the server name
* @return the server to connect to
*/
public String getServer(ProxiedPlayer player);
public ServerInfo getServer(ProxiedPlayer player);
/**
* Save the server of this player before they disconnect so it can be

View File

@ -156,9 +156,8 @@ public class InitialHandler extends PacketHandler implements Runnable, PendingCo
Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" );
UserConnection userCon = new UserConnection( socket, this, stream, handshake, forgeLogin, loginMessages );
String server = ProxyServer.getInstance().getReconnectHandler().getServer( userCon );
ServerInfo s = BungeeCord.getInstance().config.getServers().get( server );
userCon.connect( s, true );
ServerInfo server = ProxyServer.getInstance().getReconnectHandler().getServer( userCon );
userCon.connect( server, true );
thisState = State.FINISHED;
}

View File

@ -1,5 +1,6 @@
package net.md_5.bungee;
import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
@ -11,6 +12,7 @@ import java.util.logging.Level;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ReconnectHandler;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.yaml.snakeyaml.Yaml;
@ -47,16 +49,26 @@ public class YamlReconnectHandler implements ReconnectHandler
}
@Override
public String getServer(ProxiedPlayer player)
public ServerInfo getServer(ProxiedPlayer player)
{
ListenerInfo listener = player.getPendingConnection().getListener();
String name;
if ( listener.isForceDefault() )
{
return listener.getDefaultServer();
name = listener.getDefaultServer();
} else
{
String forced = listener.getForcedHosts().get( player.getPendingConnection().getVirtualHost().getHostName() );
String server = ( forced == null ) ? data.get( key( player ) ) : forced;
name = ( server != null ) ? server : listener.getDefaultServer();
}
String forced = listener.getForcedHosts().get( player.getPendingConnection().getVirtualHost().getHostName() );
String server = ( forced == null ) ? data.get( key( player ) ) : forced;
return ( server != null ) ? server : listener.getDefaultServer();
ServerInfo info = ProxyServer.getInstance().getServerInfo( name );
if ( info == null )
{
info = ProxyServer.getInstance().getServerInfo( listener.getDefaultServer() );
}
Preconditions.checkState( info != null, "Default server not defined" );
return info;
}
@Override