Handle kicks when trying to login to server. Now we have to be about done.

This commit is contained in:
md_5 2013-03-11 10:15:14 +11:00
parent 76319371f7
commit 9fb814003b
3 changed files with 14 additions and 15 deletions

View File

@ -1,14 +0,0 @@
package net.md_5.bungee;
/**
* Exception, which when thrown will disconnect the player from the proxy with
* the specified message.
*/
public class KickException extends RuntimeException
{
public KickException(String message)
{
super( message );
}
}

View File

@ -34,6 +34,11 @@ public class ServerConnection implements Server
@Override @Override
public synchronized void disconnect(String reason) public synchronized void disconnect(String reason)
{
disconnect( ch, reason );
}
static void disconnect(final Channel ch, String reason)
{ {
if ( ch.isActive() ) if ( ch.isActive() )
{ {

View File

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import java.util.Queue; import java.util.Queue;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ChatColor;
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.event.ServerConnectedEvent; import net.md_5.bungee.api.event.ServerConnectedEvent;
@ -125,7 +126,14 @@ public class ServerConnector extends PacketHandler
@Override @Override
public void handle(PacketFFKick kick) throws Exception public void handle(PacketFFKick kick) throws Exception
{ {
throw new KickException( kick.message ); String message = ChatColor.RED + "Kicked whilst connecting to " + target.getName() + ": " + kick.message;
if ( user.getServer() == null )
{
user.disconnect( message );
} else
{
user.sendMessage( message );
}
} }
@Override @Override