Error handling when cannot connect to server.

This commit is contained in:
md_5 2013-03-11 09:39:37 +11:00
parent 0b7b87d9c3
commit 6ae5feee60
2 changed files with 16 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import java.net.InetSocketAddress;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -95,10 +96,10 @@ public final class UserConnection implements ProxiedPlayer
@Override @Override
public void connect(ServerInfo target) public void connect(ServerInfo target)
{ {
connect( target, true ); connect( target, false );
} }
private void connect(ServerInfo info, final boolean retry) public void connect(ServerInfo info, final boolean retry)
{ {
ServerConnectEvent event = new ServerConnectEvent( this, info ); ServerConnectEvent event = new ServerConnectEvent( this, info );
ProxyServer.getInstance().getPluginManager().callEvent( event ); ProxyServer.getInstance().getPluginManager().callEvent( event );
@ -132,7 +133,13 @@ public final class UserConnection implements ProxiedPlayer
connect( def, false ); connect( def, false );
} else } else
{ {
disconnect( "Server down, could not connect to default!" ); if ( server == null )
{
disconnect( "Server down, could not connect to default! " + future.cause().getClass().getName() );
} else
{
sendMessage( ChatColor.RED + "Could not connect to target server: " + future.cause().getClass().getName() );
}
} }
} }
} }
@ -144,11 +151,15 @@ public final class UserConnection implements ProxiedPlayer
{ {
if ( ch.isActive() ) if ( ch.isActive() )
{ {
bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + reason );
ch.write( new PacketFFKick( reason ) ); ch.write( new PacketFFKick( reason ) );
ch.close(); ch.close();
if ( server != null )
{
server.disconnect( "Quitting" ); server.disconnect( "Quitting" );
} }
} }
}
@Override @Override
public void sendMessage(String message) public void sendMessage(String message)

View File

@ -201,7 +201,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
ch.pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );
ServerInfo server = bungee.getReconnectHandler().getServer( userCon ); ServerInfo server = bungee.getReconnectHandler().getServer( userCon );
userCon.connect( server ); userCon.connect( server, true );
thisState = State.FINISHED; thisState = State.FINISHED;
throw new CancelSendSignal(); throw new CancelSendSignal();