Set local address to listener address, closes #337

This commit is contained in:
md_5 2013-05-15 19:05:38 +10:00
parent a48ef137bd
commit 57793e93f0

View File

@ -89,34 +89,34 @@ public final class UserConnection implements ProxiedPlayer
@Getter @Getter
private String displayName; private String displayName;
/*========================================================================*/ /*========================================================================*/
public void init() public void init()
{ {
this.displayName = name; this.displayName = name;
Collection<String> g = bungee.getConfigurationAdapter().getGroups( name ); Collection<String> g = bungee.getConfigurationAdapter().getGroups( name );
for ( String s : g ) for ( String s : g )
{ {
addGroups( s ); addGroups( s );
} }
} }
public void sendPacket(DefinedPacket p) public void sendPacket(DefinedPacket p)
{ {
ch.write( p ); ch.write( p );
} }
public void sendPacket(byte[] b) public void sendPacket(byte[] b)
{ {
ch.write( b ); ch.write( b );
} }
@Deprecated @Deprecated
public boolean isActive() public boolean isActive()
{ {
return ch.getHandle().isActive(); return ch.getHandle().isActive();
} }
@Override @Override
public void setDisplayName(String name) public void setDisplayName(String name)
{ {
@ -126,20 +126,20 @@ public final class UserConnection implements ProxiedPlayer
displayName = name; displayName = name;
bungee.getTabListHandler().onConnect( this ); bungee.getTabListHandler().onConnect( this );
} }
@Override @Override
public void connect(ServerInfo target) public void connect(ServerInfo target)
{ {
connect( target, false ); connect( target, false );
} }
public void connectNow(ServerInfo target) public void connectNow(ServerInfo target)
{ {
sendPacket( Packet9Respawn.DIM1_SWITCH ); sendPacket( Packet9Respawn.DIM1_SWITCH );
sendPacket( Packet9Respawn.DIM2_SWITCH ); sendPacket( Packet9Respawn.DIM2_SWITCH );
connect( target ); connect( target );
} }
public 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 );
@ -147,7 +147,7 @@ public final class UserConnection implements ProxiedPlayer
{ {
return; return;
} }
Preconditions.checkArgument( event.getTarget() instanceof BungeeServerInfo, "BungeeCord can only connect to BungeeServerInfo instances" ); Preconditions.checkArgument( event.getTarget() instanceof BungeeServerInfo, "BungeeCord can only connect to BungeeServerInfo instances" );
final BungeeServerInfo target = (BungeeServerInfo) event.getTarget(); // Update in case the event changed target final BungeeServerInfo target = (BungeeServerInfo) event.getTarget(); // Update in case the event changed target
@ -161,9 +161,9 @@ public final class UserConnection implements ProxiedPlayer
sendMessage( ChatColor.RED + "Already connecting to this server!" ); sendMessage( ChatColor.RED + "Already connecting to this server!" );
return; return;
} }
pendingConnects.add( target ); pendingConnects.add( target );
new Bootstrap() new Bootstrap()
.channel( NioSocketChannel.class ) .channel( NioSocketChannel.class )
.group( BungeeCord.getInstance().eventLoops ) .group( BungeeCord.getInstance().eventLoops )
@ -176,6 +176,7 @@ public final class UserConnection implements ProxiedPlayer
ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
} }
} ) } )
.localAddress( getPendingConnection().getListener().getHost() )
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
.remoteAddress( target.getAddress() ) .remoteAddress( target.getAddress() )
.connect().addListener( new ChannelFutureListener() .connect().addListener( new ChannelFutureListener()
@ -187,7 +188,7 @@ public final class UserConnection implements ProxiedPlayer
{ {
future.channel().close(); future.channel().close();
pendingConnects.remove( target ); pendingConnects.remove( target );
ServerInfo def = ProxyServer.getInstance().getServers().get( getPendingConnection().getListener().getFallbackServer() ); ServerInfo def = ProxyServer.getInstance().getServers().get( getPendingConnection().getListener().getFallbackServer() );
if ( retry & target != def && ( getServer() == null || def != getServer().getInfo() ) ) if ( retry & target != def && ( getServer() == null || def != getServer().getInfo() ) )
{ {
@ -207,7 +208,7 @@ public final class UserConnection implements ProxiedPlayer
} }
} ); } );
} }
@Override @Override
public synchronized void disconnect(String reason) public synchronized void disconnect(String reason)
{ {
@ -222,20 +223,20 @@ public final class UserConnection implements ProxiedPlayer
} }
} }
} }
@Override @Override
public void chat(String message) public void chat(String message)
{ {
Preconditions.checkState( server != null, "Not connected to server" ); Preconditions.checkState( server != null, "Not connected to server" );
server.getCh().write( new Packet3Chat( message ) ); server.getCh().write( new Packet3Chat( message ) );
} }
@Override @Override
public void sendMessage(String message) public void sendMessage(String message)
{ {
sendPacket( new Packet3Chat( message ) ); sendPacket( new Packet3Chat( message ) );
} }
@Override @Override
public void sendMessages(String... messages) public void sendMessages(String... messages)
{ {
@ -244,25 +245,25 @@ public final class UserConnection implements ProxiedPlayer
sendMessage( message ); sendMessage( message );
} }
} }
@Override @Override
public void sendData(String channel, byte[] data) public void sendData(String channel, byte[] data)
{ {
sendPacket( new PacketFAPluginMessage( channel, data ) ); sendPacket( new PacketFAPluginMessage( channel, data ) );
} }
@Override @Override
public InetSocketAddress getAddress() public InetSocketAddress getAddress()
{ {
return (InetSocketAddress) ch.getHandle().remoteAddress(); return (InetSocketAddress) ch.getHandle().remoteAddress();
} }
@Override @Override
public Collection<String> getGroups() public Collection<String> getGroups()
{ {
return Collections.unmodifiableCollection( groups ); return Collections.unmodifiableCollection( groups );
} }
@Override @Override
public void addGroups(String... groups) public void addGroups(String... groups)
{ {
@ -275,7 +276,7 @@ public final class UserConnection implements ProxiedPlayer
} }
} }
} }
@Override @Override
public void removeGroups(String... groups) public void removeGroups(String... groups)
{ {
@ -288,13 +289,13 @@ public final class UserConnection implements ProxiedPlayer
} }
} }
} }
@Override @Override
public boolean hasPermission(String permission) public boolean hasPermission(String permission)
{ {
return bungee.getPluginManager().callEvent( new PermissionCheckEvent( this, permission, permissions.contains( permission ) ) ).hasPermission(); return bungee.getPluginManager().callEvent( new PermissionCheckEvent( this, permission, permissions.contains( permission ) ) ).hasPermission();
} }
@Override @Override
public void setPermission(String permission, boolean value) public void setPermission(String permission, boolean value)
{ {
@ -306,19 +307,19 @@ public final class UserConnection implements ProxiedPlayer
permissions.remove( permission ); permissions.remove( permission );
} }
} }
@Override @Override
public String toString() public String toString()
{ {
return name; return name;
} }
public void setClientEntityId(int clientEntityId) public void setClientEntityId(int clientEntityId)
{ {
Preconditions.checkState( this.clientEntityId == 0, "Client entityId already set!" ); Preconditions.checkState( this.clientEntityId == 0, "Client entityId already set!" );
this.clientEntityId = clientEntityId; this.clientEntityId = clientEntityId;
} }
@Override @Override
public void setTexturePack(TexturePackInfo pack) public void setTexturePack(TexturePackInfo pack)
{ {