From 6e18403cd97ccaf494308522e41b3182beddce7b Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 11 Mar 2013 09:11:36 +1100 Subject: [PATCH] Ensure all resources are closed all the time. --- .../java/net/md_5/bungee/UserConnection.java | 13 +------------ .../bungee/connection/DownstreamBridge.java | 13 +++++++++++-- .../bungee/connection/UpstreamBridge.java | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 58288ef5..b2b74bd3 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -144,20 +144,9 @@ public final class UserConnection implements ProxiedPlayer { if ( ch.isActive() ) { - PlayerDisconnectEvent event = new PlayerDisconnectEvent( this ); - bungee.getPluginManager().callEvent( event ); - bungee.getTabListHandler().onDisconnect( this ); - bungee.getPlayers().remove( this ); - ch.write( new PacketFFKick( reason ) ); ch.close(); - - if ( server != null ) - { - server.getInfo().removePlayer( this ); - server.disconnect( "Quitting" ); - bungee.getReconnectHandler().setServer( this ); - } + server.disconnect( "Quitting" ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 50f5231f..fc161326 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import lombok.RequiredArgsConstructor; import net.md_5.bungee.EntityMap; import net.md_5.bungee.UserConnection; @@ -35,12 +36,20 @@ public class DownstreamBridge extends PacketHandler con.disconnect( Util.exception( t ) ); } + @Override + public void disconnected(Channel channel) throws Exception + { + // We lost connection to the server + server.getInfo().removePlayer( con ); + bungee.getReconnectHandler().setServer( con ); + + con.disconnect( "[Proxy] Lost connection to server D:" ); + } + @Override public void handle(ByteBuf buf) throws Exception { EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId ); - System.out.println( "Got packet from server: " + Util.hex( buf.getUnsignedByte( 0 ) ) ); - System.out.println( buf ); con.ch.write( buf ); } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 6d80ae5c..d71a0ef3 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -1,12 +1,14 @@ package net.md_5.bungee.connection; import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import lombok.RequiredArgsConstructor; import net.md_5.bungee.EntityMap; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.event.ChatEvent; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.packet.Packet0KeepAlive; import net.md_5.bungee.packet.Packet3Chat; @@ -26,11 +28,26 @@ public class UpstreamBridge extends PacketHandler con.disconnect( Util.exception( t ) ); } + @Override + public void disconnected(Channel channel) throws Exception + { + // We lost connection to the client + PlayerDisconnectEvent event = new PlayerDisconnectEvent( con ); + bungee.getPluginManager().callEvent( event ); + bungee.getTabListHandler().onDisconnect( con ); + bungee.getPlayers().remove( con ); + + if ( con.getServer() != null ) + { + con.getServer().disconnect( "Quitting" ); + } + + } + @Override public void handle(ByteBuf buf) throws Exception { EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId ); - System.out.println( "Got packet from client: " + Util.hex( buf.getUnsignedByte( 0 ) ) ); if ( con.getServer() != null ) { con.getServer().getCh().write( buf );