Ensure all resources are closed all the time.

This commit is contained in:
md_5 2013-03-11 09:11:36 +11:00
parent 3be83cb5a4
commit 6e18403cd9
3 changed files with 30 additions and 15 deletions

View File

@ -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" );
}
}

View File

@ -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 );
}

View File

@ -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 );