mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-12-25 10:07:38 +01:00
Start work on a little spit and polish, with cleaner exceptions.
This commit is contained in:
parent
b4d104d258
commit
0ce02251d4
@ -1,6 +1,9 @@
|
|||||||
package net.md_5.bungee;
|
package net.md_5.bungee;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -48,8 +51,20 @@ public class BungeeServerInfo extends ServerInfo
|
|||||||
.channel( NioSocketChannel.class )
|
.channel( NioSocketChannel.class )
|
||||||
.group( BungeeCord.getInstance().eventLoops )
|
.group( BungeeCord.getInstance().eventLoops )
|
||||||
.handler( PipelineUtils.BASE )
|
.handler( PipelineUtils.BASE )
|
||||||
|
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||||
.remoteAddress( getAddress() )
|
.remoteAddress( getAddress() )
|
||||||
.connect()
|
.connect()
|
||||||
.channel().pipeline().get( HandlerBoss.class ).setHandler( new PingHandler( callback ) );
|
.addListener( new ChannelFutureListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void operationComplete(ChannelFuture future) throws Exception
|
||||||
|
{
|
||||||
|
if ( !future.isSuccess() )
|
||||||
|
{
|
||||||
|
callback.done( null, future.cause() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
.channel().pipeline().get( HandlerBoss.class ).setHandler( new PingHandler( this, callback ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public class ServerConnector extends PacketHandler
|
|||||||
target.addPlayer( user );
|
target.addPlayer( user );
|
||||||
|
|
||||||
user.setServer( server );
|
user.setServer( server );
|
||||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) );
|
ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
thisState = State.FINISHED;
|
thisState = State.FINISHED;
|
||||||
@ -119,4 +119,10 @@ public class ServerConnector extends PacketHandler
|
|||||||
{
|
{
|
||||||
throw new KickException( kick.message );
|
throw new KickException( kick.message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "[" + user.getName() + "] <-> ServerConnector [" + target.getName() + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -114,6 +115,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 ) );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
|
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||||
.remoteAddress( target.getAddress() )
|
.remoteAddress( target.getAddress() )
|
||||||
.connect().addListener( new ChannelFutureListener()
|
.connect().addListener( new ChannelFutureListener()
|
||||||
{
|
{
|
||||||
@ -128,6 +130,9 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
{
|
{
|
||||||
sendMessage( ChatColor.RED + "Could not connect to target server, you have been moved to the default server" );
|
sendMessage( ChatColor.RED + "Could not connect to target server, you have been moved to the default server" );
|
||||||
connect( def, false );
|
connect( def, false );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
disconnect( "Server down, could not connect to default!" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import net.md_5.bungee.Util;
|
|||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
import net.md_5.bungee.api.event.ChatEvent;
|
import net.md_5.bungee.api.event.ChatEvent;
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
import net.md_5.bungee.packet.Packet0KeepAlive;
|
import net.md_5.bungee.packet.Packet0KeepAlive;
|
||||||
@ -26,6 +27,7 @@ public class DownstreamBridge extends PacketHandler
|
|||||||
|
|
||||||
private final ProxyServer bungee;
|
private final ProxyServer bungee;
|
||||||
private final UserConnection con;
|
private final UserConnection con;
|
||||||
|
private final Server server;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(ByteBuf buf) throws Exception
|
public void handle(ByteBuf buf) throws Exception
|
||||||
@ -196,4 +198,10 @@ public class DownstreamBridge extends PacketHandler
|
|||||||
con.disconnect( "[Kicked] " + kick.message );
|
con.disconnect( "[Kicked] " + kick.message );
|
||||||
throw new CancelSendSignal();
|
throw new CancelSendSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "[" + con.getName() + "] <-> DownstreamBridge <-> [" + server.getInfo().getName() + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,4 +240,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|||||||
{
|
{
|
||||||
return (InetSocketAddress) ch.remoteAddress();
|
return (InetSocketAddress) ch.remoteAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "[" + ( ( getName() != null ) ? getName() : getAddress() ) + "] <-> InitialHandler";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import io.netty.channel.Channel;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.api.Callback;
|
import net.md_5.bungee.api.Callback;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import net.md_5.bungee.api.ServerPing;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.packet.PacketFFKick;
|
import net.md_5.bungee.packet.PacketFFKick;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
import net.md_5.bungee.packet.PacketHandler;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ import net.md_5.bungee.packet.PacketHandler;
|
|||||||
public class PingHandler extends PacketHandler
|
public class PingHandler extends PacketHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private final ServerInfo target;
|
||||||
private final Callback<ServerPing> callback;
|
private final Callback<ServerPing> callback;
|
||||||
private static final ByteBuf pingBuf = Unpooled.wrappedBuffer( new byte[]
|
private static final ByteBuf pingBuf = Unpooled.wrappedBuffer( new byte[]
|
||||||
{
|
{
|
||||||
@ -38,4 +40,10 @@ public class PingHandler extends PacketHandler
|
|||||||
ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
|
ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
|
||||||
callback.done( ping, null );
|
callback.done( ping, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "[Ping Handler] -> " + target.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,4 +75,10 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
throw new CancelSendSignal();
|
throw new CancelSendSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "[" + con.getName() + "] -> UpstreamBridge";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ import com.google.common.base.Preconditions;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
|
import io.netty.handler.timeout.ReadTimeoutException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.connection.CancelSendSignal;
|
import net.md_5.bungee.connection.CancelSendSignal;
|
||||||
import net.md_5.bungee.packet.DefinedPacket;
|
import net.md_5.bungee.packet.DefinedPacket;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
import net.md_5.bungee.packet.PacketHandler;
|
||||||
@ -30,6 +33,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<ByteBuf>
|
|||||||
if ( handler != null )
|
if ( handler != null )
|
||||||
{
|
{
|
||||||
handler.connected( ctx.channel() );
|
handler.connected( ctx.channel() );
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has connected", handler );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +42,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<ByteBuf>
|
|||||||
{
|
{
|
||||||
if ( handler != null )
|
if ( handler != null )
|
||||||
{
|
{
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has disconnected", handler );
|
||||||
handler.disconnected( ctx.channel() );
|
handler.disconnected( ctx.channel() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,9 +74,15 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<ByteBuf>
|
|||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
||||||
{
|
{
|
||||||
cause.printStackTrace();
|
|
||||||
if ( ctx.channel().isActive() )
|
if ( ctx.channel().isActive() )
|
||||||
{
|
{
|
||||||
|
if ( cause instanceof ReadTimeoutException )
|
||||||
|
{
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - read timed out" );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.SEVERE, handler + " - encountered exception", cause );
|
||||||
|
}
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,9 @@ import io.netty.channel.Channel;
|
|||||||
public abstract class PacketHandler
|
public abstract class PacketHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract String toString();
|
||||||
|
|
||||||
public void connected(Channel channel) throws Exception
|
public void connected(Channel channel) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class GlobalTabList implements TabListHandler
|
|||||||
UserConnection con = (UserConnection) player;
|
UserConnection con = (UserConnection) player;
|
||||||
for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() )
|
for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() )
|
||||||
{
|
{
|
||||||
con.packetQueue.add( new PacketC9PlayerListItem( p.getDisplayName(), true, p.getPing() ) );
|
con.sendPacket(new PacketC9PlayerListItem( p.getDisplayName(), true, p.getPing() ) );
|
||||||
}
|
}
|
||||||
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, player.getPing() ) );
|
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, player.getPing() ) );
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class ServerUniqueTabList implements TabListHandler
|
|||||||
{
|
{
|
||||||
for ( String username : usernames )
|
for ( String username : usernames )
|
||||||
{
|
{
|
||||||
( (UserConnection) player ).packetQueue.add( new PacketC9PlayerListItem( username, false, 9999 ) );
|
( (UserConnection) player ).sendPacket(new PacketC9PlayerListItem( username, false, 9999 ) );
|
||||||
}
|
}
|
||||||
usernames.clear();
|
usernames.clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user